Skip to content
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

[codegen] external $ref in parameters not supported #455

Closed
tnmtechnologies opened this issue Jul 4, 2018 · 13 comments
Closed

[codegen] external $ref in parameters not supported #455

tnmtechnologies opened this issue Jul 4, 2018 · 13 comments
Milestone

Comments

@tnmtechnologies
Copy link
Contributor

Description

When a parameter schema $ref references an external yaml file, code generation fails.

openapi-generator version

openapi-generator-cli-3.0.3.jar

OpenAPI declaration file content or url

here is a yaml definition fragment relating to the code generation failure:

  /nf-instances/{nfInstanceID}:
    get:
      summary: Read the profile of a given NF Instance
      operationId: GetNFInstance
      tags:
        - NF Instance ID (Document)
      parameters:
        - name: nfInstanceID
          in: path
          description: Unique ID of the NF Instance
          required: true
          schema:
            $ref: './TS29571_CommonData.yaml#/components/schemas/NfInstanceId'
      responses:
        '200':
          description: Expected response to a valid request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/NFProfile'
Command line used for generation

java -jar ./openapi-generator-cli-3.0.3.jar generate -i TS29510_Nnrf_NFManagement.yaml -g jaxrs-resteasy -o samples.openapi

Steps to reproduce

Output is as follows when code generation fails:

 java  -jar ./openapi-generator-cli-3.0.3.jar generate -i TS29510_Nnrf_NFManagement.yaml -g jaxrs-resteasy -o samples.openapi 
[main] WARN  o.o.c.ignore.CodegenIgnoreProcessor - Output directory does not exist, or is inaccessible. No file (.openapi-generator-ignore) will be evaluated.
[main] WARN  o.o.codegen.utils.URLPathUtils - 'host' not defined in the spec (2.0). Default to http://localhost
[main] WARN  o.o.codegen.utils.URLPathUtils - 'host' not defined in the spec (2.0). Default to http://localhost
[main] WARN  o.o.codegen.utils.URLPathUtils - 'host' not defined in the spec (2.0). Default to http://localhost
[main] WARN  o.o.codegen.utils.ModelUtils - Failed to get the schema name: ./TS29571_CommonData.yaml#/components/schemas/NfInstanceId
[main] WARN  o.o.codegen.utils.ModelUtils - Failed to get the schema name: ./TS29571_CommonData.yaml#/components/schemas/NfInstanceId
[main] INFO  o.o.codegen.AbstractGenerator - writing file .....\samples.openapi\src\gen\java\org\openapitools\model\AmfInfo.java
[main] INFO  o.o.codegen.AbstractGenerator - writing file .....\samples.openapi\src\gen\java\org\openapitools\model\AusfInfo.java
[main] INFO  o.o.codegen.AbstractGenerator - writing file .....\samples.openapi\src\gen\java\org\openapitools\model\BsfInfo.java
[main] INFO  o.o.codegen.AbstractGenerator - writing file .....\samples.openapi\src\gen\java\org\openapitools\model\DataSetId.java
[main] INFO  o.o.codegen.AbstractGenerator - writing file .....\samples.openapi\src\gen\java\org\openapitools\model\DefaultNotificationSubscription.java

Related issues/PRs

#149

Suggest a fix/enhancement
@jmini
Copy link
Member

jmini commented Jul 4, 2018

This should be supported as indicated in #80, can you please publish the content of your TS29571_CommonData.yaml file (the necessary extract) so that we have a chance to reproduce this?

@tnmtechnologies
Copy link
Contributor Author

Please find in attachment the yaml files
#455-yaml-files.ZIP

@tnmtechnologies tnmtechnologies changed the title [codegen] external $ref in paraters not supported [codegen] external $ref in parameters not supported Jul 4, 2018
@jmini
Copy link
Member

jmini commented Jul 5, 2018

Thank you.

I had to comment this section in TS29510_Nnrf_NFManagement.yaml

        n1MessageClass:
          $ref: './TS29518_Namf_Communication.yaml#/components/schemas/N1MessageClass'
        n2InformationClass:
          $ref: './TS29518_Namf_Communication.yaml#/components/schemas/N2InformationClass'

because the file TS29518_Namf_Communication.yaml was not provided...


I think this is a Swagger-Parser issue. Because with the option we are using

        OpenAPIParser openApiParser = new OpenAPIParser();
        ParseOptions options = new ParseOptions();
        options.setResolve(true);
        options.setFlatten(true);

The parser should merge all files in one spec with only local $ref.

I will try to reproduce the issue on a smaller example.

@jmini
Copy link
Member

jmini commented Jul 5, 2018

The problem is to be solved in Swagger-Parser. See issue: swagger-api/swagger-parser#749

@tnmtechnologies
Copy link
Contributor Author

Thank you for your analysis.

@markus-wa
Copy link
Contributor

My workaround for now:

paths:
  /example:
    get:
      operationId: myOp
      parameters:
        - in: query
          name: myParam
          schema:
            $ref: '#/components/schemas/MyParamSchema'

components:
  schemas:
    MyParamSchema:
      allOf:
       - ref: './other.yaml#/MyParamSchema'

@jmini
Copy link
Member

jmini commented Jul 31, 2018

The issue in Swagger-Parser was fixed, and with PR #696 OpenAPI-Generator was updated to use a version containing the fix.

This issue reported here, should no longer appear with the newest 3.2.0-SNAPSHOT version.
@markus-wa, @tnmtechnologies, can you check it?

@jmini jmini added this to the 3.2.0 milestone Jul 31, 2018
@markus-wa
Copy link
Contributor

markus-wa commented Aug 6, 2018

I think it's fixed for me @jmini.

But unfortunately 2.0.2-OpenAPITools.org-1 breaks the workaround for swagger-api/swagger-parser#764.

In general, references to other files in already referenced files don't work if they are in a different folder than the spec. References are now always relative to the spec instead of the file in which they are located.

@wing328 wing328 modified the milestones: 3.2.0, 3.2.1 Aug 6, 2018
@wing328 wing328 modified the milestones: 3.2.1, 3.2.2 Aug 14, 2018
@wing328 wing328 modified the milestones: 3.2.2, 3.2.3 Aug 22, 2018
@wing328 wing328 modified the milestones: 3.2.3, 3.3.0 Aug 30, 2018
@tnmtechnologies
Copy link
Contributor Author

It is fixed for me too (tested with 3.2.0).

@LBoraz
Copy link

LBoraz commented Oct 31, 2019

version 4.2.0 of the generator still produces the warning (with no external $ref)

@markus-wa
Copy link
Contributor

Might be best to open a new issue @LBoraz - afaik closed ones usually aren't being monitored

@xvilo
Copy link
Contributor

xvilo commented Jun 24, 2020

@LBoraz did you create a new issue?

@LBoraz
Copy link

LBoraz commented Aug 20, 2020

No, i didn't

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

6 participants