Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -855,6 +855,20 @@ protected void normalizeProperties(Map<String, Schema> properties, Set<Schema> v
}
for (Map.Entry<String, Schema> propertiesEntry : properties.entrySet()) {
Schema property = propertiesEntry.getValue();

// remove x-internal if needed (same logic as normalizeComponentsSchemas)
if (property.getExtensions() != null && getRule(REMOVE_X_INTERNAL)) {
Object xInternalValue = property.getExtensions().get(X_INTERNAL);
boolean isInternal = false;
if (xInternalValue instanceof Boolean) {
isInternal = (Boolean) xInternalValue;
} else if (xInternalValue instanceof String) {
isInternal = Boolean.parseBoolean((String) xInternalValue);
}
if (isInternal) {
property.getExtensions().remove(X_INTERNAL);
}
}
Schema newProperty = normalizeSchema(property, new HashSet<>());
propertiesEntry.setValue(newProperty);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1153,6 +1153,42 @@ public void testNormalizerClass() {
assertEquals(requiredProperties.getRequired(), null);
}


@Test
public void testRemoveXInternalFromInlineProperties() {
OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/3_0/inline_x_internal_test.yaml");
Schema parentSchema = openAPI.getComponents().getSchemas().get("ParentSchema");
Schema inlineProperty = (Schema) parentSchema.getProperties().get("inlineXInternalProperty");

// Before normalization: x-internal should be present on inline property
assertNotNull(inlineProperty.getExtensions());
assertEquals(inlineProperty.getExtensions().get("x-internal"), true);

// Run normalizer with REMOVE_X_INTERNAL=true
Map<String, String> options = new HashMap<>();
options.put("REMOVE_X_INTERNAL", "true");
OpenAPINormalizer openAPINormalizer = new OpenAPINormalizer(openAPI, options);
openAPINormalizer.normalize();

// After normalization: x-internal should be removed from inline property
Schema parentSchemaAfter = openAPI.getComponents().getSchemas().get("ParentSchema");
Schema inlinePropertyAfter = (Schema) parentSchemaAfter.getProperties().get("inlineXInternalProperty");

// x-internal extension should be removed (null or not present in map)
if (inlinePropertyAfter.getExtensions() != null) {
assertNull(inlinePropertyAfter.getExtensions().get("x-internal"));
}

// The property itself should still exist (we're removing the flag, not the property)
assertNotNull(inlinePropertyAfter);
assertEquals(inlinePropertyAfter.getType(), "object");

// Nested properties should still exist
assertNotNull(inlinePropertyAfter.getProperties());
assertNotNull(inlinePropertyAfter.getProperties().get("nestedField"));
assertNotNull(inlinePropertyAfter.getProperties().get("nestedNumber"));
}

public static class RemoveRequiredNormalizer extends OpenAPINormalizer {

public RemoveRequiredNormalizer(OpenAPI openAPI, Map<String, String> inputRules) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
openapi: 3.0.0
info:
version: 1.0.0
title: Test inline x-internal
components:
schemas:
ParentSchema:
description: Schema with inline x-internal property
type: object
properties:
normalProperty:
type: string
description: A normal property without x-internal
inlineXInternalProperty:
x-internal: true
description: Inline object property marked as x-internal
type: object
properties:
nestedField:
type: string
description: A field inside the inline x-internal object
nestedNumber:
type: integer
description: Another field inside the inline object
Loading