swagger-api / swagger-api/swagger-codegen-generators

Swagger not rendered when allOf used in schema

Open
#967 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
299
Forks
439
PR merge metrics
No merged PRs in 30d

Description

https://github.com/swagger-api/swagger-codegen-generators/blob/dff6a3e4c56462a24873fd62e3c38ba61ed7974f/src/main/java/io/swagger/codegen/v3/generators/SchemaHandler.java#L20

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.