Repository navigation
[core] Treat an OAS 3.1 boolean schema false as closed additionalProperties (#25430) #25470
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3645,7 +3645,7 @@ protected void setAddProps(Schema schema, IJsonSchemaValidationProperties proper | |
| addPropProp = fromProperty(getAdditionalPropertiesName(), new Schema(), false); | ||
| additionalPropertiesIsAnyType = true; | ||
| } | ||
| } else { | ||
| } else if (!isBooleanSchemaFalse(schema.getAdditionalProperties())) { | ||
| // if additional properties is set (e.g. free form object, any type, string, etc) | ||
| addPropProp = fromProperty(getAdditionalPropertiesName(), (Schema) schema.getAdditionalProperties(), false); | ||
| additionalPropertiesIsAnyType = true; | ||
|
|
@@ -3664,6 +3664,12 @@ protected void setAddProps(Schema schema, IJsonSchemaValidationProperties proper | |
| } | ||
| } | ||
|
|
||
| // OAS 3.1 can parse `additionalProperties: false` as a boolean schema instead of Boolean.FALSE | ||
| private static boolean isBooleanSchemaFalse(Object additionalProperties) { | ||
| return additionalProperties instanceof Schema | ||
| && Boolean.FALSE.equals(((Schema) additionalProperties).getBooleanSchemaValue()); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: The checked-in OpenAPI input uses Prompt for AI agents |
||
| } | ||
|
|
||
| /** | ||
| * Recursively look in Schema sc for the discriminator and return it | ||
| * | ||
|
|
@@ -8592,7 +8598,7 @@ protected void addRequiredVarsMap(Schema schema, IJsonSchemaValidationProperties | |
| if (!found) { | ||
| LOGGER.warn("Property {} is not processed correctly (missing from getVars). Maybe it's a const (not yet supported) in openapi v3.1 spec.", requiredPropertyName); | ||
| } | ||
| } else if (schema.getAdditionalProperties() instanceof Boolean && Boolean.FALSE.equals(schema.getAdditionalProperties())) { | ||
| } else if (Boolean.FALSE.equals(schema.getAdditionalProperties()) || isBooleanSchemaFalse(schema.getAdditionalProperties())) { | ||
| // TODO add processing for requiredPropertyName | ||
| // required property is not defined in properties, and additionalProperties is false, value is null | ||
| requiredVarsMap.put(usedRequiredPropertyName, null); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| openapi: 3.1.0 | ||
| info: | ||
| title: Closed schema with an inline map property (issue 25430) | ||
| version: 1.0.0 | ||
| paths: | ||
| /patch: | ||
| post: | ||
| operationId: patch | ||
| requestBody: | ||
| content: | ||
| application/json: | ||
| schema: | ||
| $ref: "#/components/schemas/PatchRequest" | ||
| responses: | ||
| "204": | ||
| description: No content | ||
| components: | ||
| schemas: | ||
| PatchRequest: | ||
| type: object | ||
| properties: | ||
| context: | ||
| type: object | ||
| additionalProperties: true | ||
| additionalProperties: false | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P3: This fixture only covers the Prompt for AI agents |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P3: This helper repeats the false-boolean
additionalPropertiescheck thatModelUtils.isMapSchemaandModelUtils.isModelWithPropertiesOnlyalready inline. Move it toModelUtilsas a public static method and call it from both places, so the OAS 3.1 closed-schema rule lives in one place.Prompt for AI agents