Repository navigation
Fix #25756: support array/object in the OAS 3.1 multi-type normalizer for Java #25761
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 |
|---|---|---|
|
|
@@ -744,6 +744,74 @@ public void testNormalize31Parameters() { | |
| assertNotNull(pathItem.getDelete().getParameters().get(0).getSchema().getTypes()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testNormalize31MultipleTypes() { | ||
| OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/3_1/issue_25756.yaml"); | ||
|
|
||
| OpenAPINormalizer openAPINormalizer = new OpenAPINormalizer(openAPI, Map.of("NORMALIZE_31SPEC", "true")); | ||
| openAPINormalizer.normalize(); | ||
|
|
||
| Map<String, Schema> companyProperties = openAPI.getComponents().getSchemas().get("Company").getProperties(); | ||
|
|
||
| Schema tradingNames = companyProperties.get("tradingNames"); | ||
| assertNull(tradingNames.getTypes()); | ||
| assertEquals(tradingNames.getAnyOf().size(), 2); | ||
| assertNull(tradingNames.getItems()); | ||
| ArraySchema tradingNamesArray = null; | ||
| Schema tradingNamesString = null; | ||
| for (Object subSchema : tradingNames.getAnyOf()) { | ||
| if (subSchema instanceof ArraySchema) { | ||
| tradingNamesArray = (ArraySchema) subSchema; | ||
| } else if (subSchema instanceof StringSchema) { | ||
| tradingNamesString = (StringSchema) subSchema; | ||
| } | ||
| } | ||
| assertNotNull(tradingNamesArray); | ||
| assertNotNull(tradingNamesString); | ||
| assertEquals(tradingNamesArray.getDescription(), "A list for most countries, a single string for some."); | ||
| assertEquals(tradingNamesArray.getItems().getType(), "string"); | ||
|
|
||
| Schema objOrArray = companyProperties.get("objOrArray"); | ||
| assertNull(objOrArray.getTypes()); | ||
| assertEquals(objOrArray.getAnyOf().size(), 2); | ||
| assertNull(objOrArray.getItems()); | ||
| ObjectSchema objOrArrayObject = null; | ||
| ArraySchema objOrArrayArray = null; | ||
| for (Object subSchema : objOrArray.getAnyOf()) { | ||
| if (subSchema instanceof ObjectSchema) { | ||
| objOrArrayObject = (ObjectSchema) subSchema; | ||
| } else if (subSchema instanceof ArraySchema) { | ||
| objOrArrayArray = (ArraySchema) subSchema; | ||
| } | ||
| } | ||
| assertNotNull(objOrArrayObject); | ||
|
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: This regression test does not cover object Prompt for AI agents |
||
| assertNotNull(objOrArrayArray); | ||
| assertEquals(objOrArrayArray.getDescription(), "Related case from the issue."); | ||
| assertEquals(objOrArrayArray.getItems().getType(), "string"); | ||
|
|
||
| Schema nullableArrOrStr = companyProperties.get("nullableArrOrStr"); | ||
| assertTrue(nullableArrOrStr.getNullable()); | ||
| assertNull(nullableArrOrStr.getTypes()); | ||
| assertEquals(nullableArrOrStr.getAnyOf().size(), 2); | ||
|
|
||
| Schema mapOrString = openAPI.getComponents().getSchemas().get("MapOrString"); | ||
| assertNull(mapOrString.getTypes()); | ||
| assertEquals(mapOrString.getAnyOf().size(), 2); | ||
| ObjectSchema mapOrStringObject = null; | ||
| Schema mapOrStringString = null; | ||
| for (Object subSchema : mapOrString.getAnyOf()) { | ||
| if (subSchema instanceof ObjectSchema) { | ||
| mapOrStringObject = (ObjectSchema) subSchema; | ||
| } else if (subSchema instanceof StringSchema) { | ||
| mapOrStringString = (StringSchema) subSchema; | ||
| } | ||
| } | ||
| assertNotNull(mapOrStringObject); | ||
| assertNotNull(mapOrStringString); | ||
| assertNotNull(mapOrStringObject.getAdditionalProperties()); | ||
| assertEquals(((Schema) mapOrStringObject.getAdditionalProperties()).getType(), "string"); | ||
| } | ||
|
|
||
| @Test | ||
| public void testNormalize31ExclusiveMinMaxNumericOnly() { | ||
| OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/3_1/exclusive-min-max.yaml"); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| openapi: 3.1.0 | ||
| info: | ||
| title: Multi-type property repro (issue 25756) | ||
| version: 1.0.0 | ||
| paths: | ||
| /companies/{id}: | ||
| get: | ||
| operationId: getCompany | ||
| parameters: | ||
| - name: id | ||
| in: path | ||
| required: true | ||
| schema: | ||
| type: string | ||
| responses: | ||
| '200': | ||
| description: OK | ||
| content: | ||
| application/json: | ||
| schema: | ||
| $ref: '#/components/schemas/Company' | ||
| components: | ||
| schemas: | ||
| Company: | ||
| type: object | ||
| properties: | ||
| name: | ||
| type: string | ||
| tradingNames: | ||
| description: A list for most countries, a single string for some. | ||
| type: | ||
| - array | ||
| - string | ||
| items: | ||
| type: string | ||
| objOrArray: | ||
| description: Related case from the issue. | ||
| type: | ||
| - object | ||
| - array | ||
| items: | ||
| type: string | ||
| nullableArrOrStr: | ||
| description: Nullable variant of the array-or-string case. | ||
| type: | ||
| - array | ||
| - string | ||
| - 'null' | ||
| items: | ||
| type: string | ||
| MapOrString: | ||
| type: | ||
| - object | ||
| - string | ||
| additionalProperties: | ||
| type: string |
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.
P1: Object-first unions that declare properties are still not normalized by this change. Because
normalizeSchemahandles non-empty properties beforeprocessNormalize31Spec,type: [object, array]remains a JsonSchema instead of becoming ananyOf, so Java generation can still treat it as an object-only model and lose the array alternative; normalize explicit multi-type schemas before the properties-only path (while preserving the existing implied-object behavior).Prompt for AI agents