swagger-api / swagger-api/swagger-codegen-generators
Swagger not rendered when allOf used in schema
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 299
- Forks
- 439
- PR merge metrics
- No merged PRs in 30d
Description
I got null pointer execption on combined schema with allOf.
According to the doc
https://swagger.io/docs/specification/data-models/oneof-anyof-allof-not/
allOf, anyOf...etc should be lower case.
Although swagger-apidoc generates an issue when allOf us used with lowercase (first char).
When I change allOf to AllOf, the swagger doc renders.
The exception is the following using lowercase allOf:
Exception in thread "Thread-1" java.lang.NullPointerException
at io.swagger.codegen.v3.generators.SchemaHandler.processArrayItemSchema(SchemaHandler.java:127)
at io.swagger.codegen.v3.generators.SchemaHandler.processComposedSchemas(SchemaHandler.java:39)
at io.swagger.codegen.v3.ISchemaHandler.readProcessedModels(ISchemaHandler.java:30)
at io.swagger.codegen.v3.DefaultGenerator.generateModels(DefaultGenerator.java:391)
at io.swagger.codegen.v3.DefaultGenerator.generate(DefaultGenerator.java:779)
at io.swagger.codegen.v3.cli.cmd.Generate.run(Generate.java:360)
at java.lang.Thread.run(Thread.java:748)
Tested on version an older version 1.0.20, but the issue based on the source code seems to be present in the master branch too.
Example json schema:
"ConfigUpdateRequestDto": {
"type": "array",
"items": {
"AllOf": [
{
"$ref": "#/components/schemas/Config"
},
{
"type": "object",
"properties": {
"apply": {
"type": "boolean"
}
}
}
]
}
},
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with src/main/java/io/swagger/codegen/v3/generators/SchemaHandler.java, especially processArrayItemSchema at line 127 and processComposedSchemas, then reproduce the NullPointerException using the provided ConfigUpdateRequestDto schema. Done means a schema using lowercase allOf is processed without the exception and the Swagger documentation renders correctly.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100