Skip to content

$ref in additionalProperties in external yaml ignored #4135

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
rakus opened this issue Nov 4, 2016 · 7 comments
Open

$ref in additionalProperties in external yaml ignored #4135

rakus opened this issue Nov 4, 2016 · 7 comments

Comments

@rakus
Copy link

rakus commented Nov 4, 2016

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.

@jimschubert
Copy link
Contributor

@rakus are there differences in this issue from #4103? Is the only difference yaml versus the JSON in #4103?

@rakus
Copy link
Author

rakus commented Nov 5, 2016

@jimschubert Yes I think so. This talks about $ref within the external file.

The $ref from the main swagger to the external file works ok.
The $ref from a normal property in the external file to a object in the same file works ok.

But: The $ref from additionalProperties in the external file to a object in the same file fails.

The swagger example in initial description is the external file (just updated as definitions: was missing).

@fehguy
Copy link
Contributor

fehguy commented Nov 5, 2016

I think this is not supported in the parser. Do you mind opening an issue there?

@rakus
Copy link
Author

rakus commented Nov 5, 2016

Opened against swagger-parser as #342.

Should this be closed or should we wait for the fix of swagger-parser and the verify it?

@wing328
Copy link
Contributor

wing328 commented Nov 7, 2016

@rakus let's leave this open for the time being.

@slarti-b
Copy link
Contributor

We just ran up against this. Any news or updates? One other question: how is this intended to be implemented? Specifically, would it be possible to specify package names per included file in some way?

To explain, we're working on a number of APIs and want to have a common.yml with certain shared object/parameter definitions. let's say I have two APIs, Foo and bar, each in their own files which reference an ErrorMessage object in common.yml Currently if I run the codegen for Foo it generates it with a class called CommonYamldefinitionsErrorMessage in my com.example.api.foo package, but that class isn't created. What I'd like is for it to generate with an ErrorMessage class imported from com.example.api.common. That way both the APIs can refer to the same object. This makes most sense of using external files IMO - if I'm not sharing anything i can put everything in one more easily.

I understand this might be out-of-scope for this ticket, but wanted to raise it.

@slarti-b
Copy link
Contributor

slarti-b commented Dec 12, 2017

I have a work-around for this. it's a bit (lot) of a hack, but it works. What I do is:

  • run the codegen on my common.yaml with option to specify my common package. This fails, with a java.lang.NullPointerException because there are no paths defined in common.yaml running with -Dmodels -DsupportingFiles (so not apis) means this succeeds even though no paths are defined
  • run the codegen on my api file, and specify import-mappings and type-mappings on the command line

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants