swagger-api / swagger-api/swagger-codegen

[Java-Playframework][Core] Referenced models not in model list

Open
#6,184 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description

We have bumped into a situation where a model ends up as an import to another model, but it does not show up in the list of CodegenModels. This happens because one of our models is an allOf which references a model called ModelError, but ModelError is not directly used anywhere in our api definition.

In the example below, ModelError ends as an import for InvalidArgument, but ModelError is not in the list of models.

I am tagging this as Java-Playframework because that's where I've seen the error surface, but it looks to me like a problem in DefaultCodegen

Swagger-codegen version

2.3.0-SNAPSHOT

Swagger declaration file content or url

File 1:

[...]
"/path": {
      "get": {
        "responses": {
          "200": {
            "description": "OK",
            "schema": {
              "$ref": "#/definitions/ConsumptionsData"
            },
          "400": {
            "description": "Problem with the client request, in this case both OUT_OF_RANGE and INVALID_ARGUMENT are possible",
            "schema": {
              "$ref": "../common/errors.json#/definitions/InvalidArgument"
            },
            "examples": {
              "application/json": {
                "code": "OUT_OF_RANGE",
                "message": "Client specified an invalid range"
              }
            }
          }
        }
      }
    },
[...]

File 2:

{
  "definitions": {
    "ModelError": {
      "type": "object",
      "required": [
        "message"
      ],
      "properties": {
        "message": {
          "type": "string",
          "description": "A human readable description of what the event represent"
        }
      }
    },
    "InvalidArgument": {
      "allOf": [
        {
          "type": "object",
          "required": [
            "code"
          ],
          "properties": {
            "code": {
              "type": "string",
              "enum": [
                "INVALID_ARGUMENT"
              ],
              "default": "INVALID_ARGUMENT",
              "description": "Client specified an invalid argument, request body or query param."
            }
          }
        },
        {
          "$ref": "#/definitions/ModelError"
        }
      ]
    }
}

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 in DefaultCodegen and trace how CodegenModels is populated for allOf references, using the two Swagger definition files and the Java-Playframework path described in the issue. Done when the referenced ModelError appears in the model list as well as being imported for InvalidArgument.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.