Created by: GuillaumeSmaha
Since swagger-core 2.2.0 for OpenAPI 3.1, a set of type can be used instead of an unique type: https://github.com/swagger-api/swagger-core/blob/v2.2.8/modules/swagger-models/src/main/java/io/swagger/v3/oas/models/media/Schema.java#L107-L111
In the case of an array, the schema is not an ArraySchema
but an JsonSchema
with a set of types defined to [array]
.
Example of usage of JsonSchema if OpenAPI is 3.1:
https://github.com/swagger-api/swagger-parser/blob/v2.1.8/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/util/ResolverFully.java#L383-L390
See https://github.com/OpenAPITools/openapi-generator/issues/14577#issuecomment-1418778197 for example of the JsonSchema in getPrimitiveType(Schema)
.
To solve that, ModelUtils.isArraySchema(schema)
is now returning true if the schema is an instance of ArraySchema
or JsonSchema
with only one type and this type need to be equal to array
.
The function getSchemaItems(schema)
is moved to ModelUtils.getArrayItems(schema)
to be used in ModelUtils
and it is now used everywhere to get items in a schema whatever the type of the schema (ArraySchema or JsonSchema)
Add test testOpenAPI310ResponsesJsonSchemaIsArray
to validate JsonSchema is correctly translate to an array
PR checklist
-
Read the contribution guidelines. -
Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community. -
Run the following to build the project and update samples: ./mvnw clean package ./bin/generate-samples.sh ./bin/utils/export_docs_generators.sh
./bin/generate-samples.sh bin/configs/java*
. For Windows users, please run the script in Git BASH. -
In case you are adding a new generator, run the following additional script : ./bin/utils/ensure-up-to-date.sh
-
File the PR against the correct branch: master
(6.3.0) (minor release - breaking changes with fallbacks),7.0.x
(breaking changes without fallbacks) -
If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request. This is a core change @wing328