swagger-api / swagger-api/swagger-codegen

swagger-codegen-cli.jar is omitting a nested definition referenced from another file

Open
#6,882 2 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

I am using swagger-codegen-cli.jar version 2.2.3 to convert our Swagger from two separate YAML files into a single JSON file. The two files are parent.yaml and child.yaml

The first file, parent.yaml, defines an object type Response with one property ('entitlements'). This property is a reference to a type defined in child.yaml, as './child.yaml#/definitions/Entitlements'.

In child.yaml, that Entitlements object type is defined, with additionalProperties and a reference to the Entitlement type.

That Entitlement type is also defined in child.yaml.

The generate command succeeds, but produces an invalid swagger.json. Specifically, it pulls the Entitlements definition in, but fails to pull in the Entitlement definition.

Swagger-codegen version

2.2.3

Swagger declaration file content or url

Two input files, which I have also attached. First parent.yaml:

swagger: '2.0'

info:
  title: Entitlements data
  contact:
    name: Nobody
    url: https://nobody.nowhere.com
    email: nobody@nowhere.com
  description: Entitlements
  version: v1

host: api.nowhere.com

schemes:
- https
- http

basePath: /rest/v1

produces:
- application/json

paths:
  /entitlements:
    get:
      operationId: Get
      tags:
      - Shared
      responses:
        200:
          description: OK
          schema:
            $ref: '#/definitions/Response'
            properties:
              name:
                type: string

definitions:
  Response:
    type: object
    properties:
      entitlements:
        $ref: './child.yaml#/definitions/Entitlements'

Next, child.yaml:

definitions:

  Entitlement:
    type: object
    description: An entitlement
    properties:
      id:
        type: string
        description: The ID

  Entitlements:
    type: object
    description: A hashmap of entitlements
    additionalProperties:
      $ref: '#/definitions/Entitlement'

The definitions section from the swagger.json output file:

   {
      "definitions" : {
        "Response" : {
          "type" : "object",
          "properties" : {
            "entitlements" : {
              "$ref" : "#/definitions/Entitlements"
            }
          }
        },
        "Entitlements" : {
          "type" : "object",
          "description" : "A hashmap of entitlements",
          "additionalProperties" : {
            "$ref" : "#/definitions/Entitlement"
          }
        }
      }
    }

Note that the definition of the Entitlement type is missing, and thus the reference in this file to "#/definitions/Entitlement" is invalid.

Command line used for generation
 java -jar swagger-codegen-cli.jar generate -i ./parent.yaml -l swagger -o /tmp
Steps to reproduce
  1. Execute the generate command specified above
  2. Look at /tmp/swagger.json, and verify that the definition of the Entitlement type is not present.
Related issues/PRs
Suggest a fix/enhancement

I suspect that this is related to additionalProperties
files.tar.gz
**

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

Reproduce the issue with parent.yaml and child.yaml using the documented swagger-codegen-cli.jar command, then inspect /tmp/swagger.json. Focus on the nested additionalProperties reference from Entitlements to Entitlement. Done means the generated file includes the Entitlement definition and its reference is valid.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
backend-api-design
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.