Skip to content

Commit b199901

Browse files
rc-gleanCopilot
andauthored
[fix] Apply REMOVE_X_INTERNAL normalizer to nested inline properties (#22097)
* fix: Apply REMOVE_X_INTERNAL normalizer to nested inline properties When REMOVE_X_INTERNAL=true is set, the normalizer removes the x-internal extension from top-level schemas in components/schemas but fails to remove it from inline object properties within those schemas. This causes issues when: 1. A schema is imported cross-file (e.g., admin.yaml imports from chat.yaml) 2. That schema has an inline object property with x-internal: true 3. The inline property has type: object with nested properties Result: TypeScript generator creates a type reference but no interface definition, causing compilation errors. This fix applies the same x-internal removal logic to normalizeProperties() that already exists in normalizeComponentsSchemas(), ensuring inline properties are handled consistently. Fixes behavior for inline schemas with x-internal in cross-file imports. * Update modules/openapi-generator/src/main/java/org/openapitools/codegen/OpenAPINormalizer.java Co-authored-by: Copilot <[email protected]> * test: Add test case for REMOVE_X_INTERNAL with inline properties Adds test to verify that REMOVE_X_INTERNAL normalizer correctly removes x-internal extension from inline object properties, not just top-level schemas. * Apply suggestion from @Copilot Co-authored-by: Copilot <[email protected]> * Revert "Apply suggestion from @Copilot" This reverts commit c899e9e. --------- Co-authored-by: Copilot <[email protected]>
1 parent 941a5cc commit b199901

File tree

3 files changed

+74
-0
lines changed

3 files changed

+74
-0
lines changed

modules/openapi-generator/src/main/java/org/openapitools/codegen/OpenAPINormalizer.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -855,6 +855,20 @@ protected void normalizeProperties(Map<String, Schema> properties, Set<Schema> v
855855
}
856856
for (Map.Entry<String, Schema> propertiesEntry : properties.entrySet()) {
857857
Schema property = propertiesEntry.getValue();
858+
859+
// remove x-internal if needed (same logic as normalizeComponentsSchemas)
860+
if (property.getExtensions() != null && getRule(REMOVE_X_INTERNAL)) {
861+
Object xInternalValue = property.getExtensions().get(X_INTERNAL);
862+
boolean isInternal = false;
863+
if (xInternalValue instanceof Boolean) {
864+
isInternal = (Boolean) xInternalValue;
865+
} else if (xInternalValue instanceof String) {
866+
isInternal = Boolean.parseBoolean((String) xInternalValue);
867+
}
868+
if (isInternal) {
869+
property.getExtensions().remove(X_INTERNAL);
870+
}
871+
}
858872
Schema newProperty = normalizeSchema(property, new HashSet<>());
859873
propertiesEntry.setValue(newProperty);
860874
}

modules/openapi-generator/src/test/java/org/openapitools/codegen/OpenAPINormalizerTest.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1153,6 +1153,42 @@ public void testNormalizerClass() {
11531153
assertEquals(requiredProperties.getRequired(), null);
11541154
}
11551155

1156+
1157+
@Test
1158+
public void testRemoveXInternalFromInlineProperties() {
1159+
OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/3_0/inline_x_internal_test.yaml");
1160+
Schema parentSchema = openAPI.getComponents().getSchemas().get("ParentSchema");
1161+
Schema inlineProperty = (Schema) parentSchema.getProperties().get("inlineXInternalProperty");
1162+
1163+
// Before normalization: x-internal should be present on inline property
1164+
assertNotNull(inlineProperty.getExtensions());
1165+
assertEquals(inlineProperty.getExtensions().get("x-internal"), true);
1166+
1167+
// Run normalizer with REMOVE_X_INTERNAL=true
1168+
Map<String, String> options = new HashMap<>();
1169+
options.put("REMOVE_X_INTERNAL", "true");
1170+
OpenAPINormalizer openAPINormalizer = new OpenAPINormalizer(openAPI, options);
1171+
openAPINormalizer.normalize();
1172+
1173+
// After normalization: x-internal should be removed from inline property
1174+
Schema parentSchemaAfter = openAPI.getComponents().getSchemas().get("ParentSchema");
1175+
Schema inlinePropertyAfter = (Schema) parentSchemaAfter.getProperties().get("inlineXInternalProperty");
1176+
1177+
// x-internal extension should be removed (null or not present in map)
1178+
if (inlinePropertyAfter.getExtensions() != null) {
1179+
assertNull(inlinePropertyAfter.getExtensions().get("x-internal"));
1180+
}
1181+
1182+
// The property itself should still exist (we're removing the flag, not the property)
1183+
assertNotNull(inlinePropertyAfter);
1184+
assertEquals(inlinePropertyAfter.getType(), "object");
1185+
1186+
// Nested properties should still exist
1187+
assertNotNull(inlinePropertyAfter.getProperties());
1188+
assertNotNull(inlinePropertyAfter.getProperties().get("nestedField"));
1189+
assertNotNull(inlinePropertyAfter.getProperties().get("nestedNumber"));
1190+
}
1191+
11561192
public static class RemoveRequiredNormalizer extends OpenAPINormalizer {
11571193

11581194
public RemoveRequiredNormalizer(OpenAPI openAPI, Map<String, String> inputRules) {
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
openapi: 3.0.0
2+
info:
3+
version: 1.0.0
4+
title: Test inline x-internal
5+
components:
6+
schemas:
7+
ParentSchema:
8+
description: Schema with inline x-internal property
9+
type: object
10+
properties:
11+
normalProperty:
12+
type: string
13+
description: A normal property without x-internal
14+
inlineXInternalProperty:
15+
x-internal: true
16+
description: Inline object property marked as x-internal
17+
type: object
18+
properties:
19+
nestedField:
20+
type: string
21+
description: A field inside the inline x-internal object
22+
nestedNumber:
23+
type: integer
24+
description: Another field inside the inline object

0 commit comments

Comments
 (0)