swagger-api / swagger-api/swagger-codegen

$ref in additionalProperties in external yaml ignored

Open
#4,135 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug Swagger-Parser
Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description

The $ref below additionalProperties is not handled when the definition is kept in a seperate yaml file.
So the class needed for the reference is not created.

If the example YAML below is in a seperate file, the classes Result and LinkObject are created, but RelData is not.

If it is copied into the main swagger file, all classes are created.

The attached maven project shows the problem.

  • src/main/resources/Test1.yaml contains definitions in main file
  • src/main/resources/Test2.yaml references definitions from external file Test2Globals.yaml

Just build the project with mvn generate-sources and then compare the generated code in target/generated-sources-good and target/generated-sources-bad.

Maven project: swagger-addprop-bug.zip

Swagger-codegen version

Maven Plugin Version 2.2.2-SNAPSHOT (locally build)

Swagger declaration file content or url

globals.yaml:

definitions:
  link-object:
    type: object
    additionalProperties:
      $ref: '#/definitions/rel-data'

  rel-data:
    type: object
    required:
      - href
    properties:
      href:
        type: string
      note:
        type: string

  result:
    type: object
    properties: 
      name:
        type: string
      _links:
        $ref: "#/definitions/link-object"

The object result is referenced from the main swagger file. The ref from
result._links to link-object works, but the ref from link-object to
rel-data is ignored.

Command line used for generation

Using Maven, like so:

<configuration>
    <inputSpec>src/main/resources/swagger.yaml</inputSpec>
    <language>jaxrs-resteasy</language>
    <configOptions>
        <sourceFolder>swagger</sourceFolder>
        <dateLibrary>java8</dateLibrary>
    </configOptions>
    <output>target/generated-sources</output>
    <verbose>true</verbose>
    <environmentVariables>
        <models></models>
        <apis></apis>
        <supportingFiles></supportingFiles>
    </environmentVariables>
</configuration>
Steps to reproduce

See attached maven project.

Related issues

Nothing found

Suggest a Fix

None.

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/resources/Test1.yaml, Test2.yaml, and Test2Globals.yaml, then run mvn generate-sources using the attached Maven project. Compare target/generated-sources-good with target/generated-sources-bad and trace why the external $ref under additionalProperties is ignored; done means the generated output includes RelData as well as Result and LinkObject.

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
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.