openapi-generator icon indicating copy to clipboard operation
openapi-generator copied to clipboard

[BUG] External schemas referenced from the content of a parameter are not found

Open DonDi94 opened this issue 7 years ago • 1 comments

Bug Report Checklist

  • [x] Have you provided a full/minimal spec to reproduce the issue?
  • [x] Have you validated the input using an OpenAPI validator (example)?
  • [x] What's the version of OpenAPI Generator used?
  • [x] Have you search for related issues/PRs?
  • [x] What's the actual output vs expected output?
  • [ ] [Optional] Bounty to sponsor the fix (example)
Description

If a parameter has an external reference inside of the content field, the generator will not be able to get the schema from the reference. It works if the reference is towards a schema in the components of the file where the parameter is defined.

openapi-generator version

4.0.0, commit 67423029225e003a1bdeb29909a960ae7e16ed22

OpenAPI declaration file content or url

test.txt

openapi: '3.0.0'
info:
  version: 1.0.0
  title: Test
paths: 
  /:    
    get:
      parameters:
        - name: test
          in: query
          content:
            'application/json':
              schema:
                $ref: './external_components.yaml#/components/schemas/Ref'
      responses:
        default:
          description: Unexpected error

external_components.yaml

openapi: 3.0.0
info:
  version: '1.0.0'
  title: 'External definition for schemas'
paths: {}
components:
  schemas:
    Ref:
      type: string
Command line used for generation

java -jar openapi-generator-cli.jar generate -i test.yaml -g csharp-nancyfx -o out/ >> log.txt

Steps to reproduce
  • Create a file test.yaml with the first specification
  • Create a file external_components.yaml with the second specification in the same folder as test.yaml
  • Put openapi-generator-cli.jar in the same folder as the two yaml files
  • Run the command
  • Open log.txt

The log file will contain the following warning:

[main] WARN  o.o.codegen.DefaultCodegen - Error obtaining the datatype from ref:./external_components.yaml#/components/schemas/Ref. Default to 'object'

The expected result would be to not have that working and have the parameter use the schema named Ref rather than object.

Related issues/PRs

I haven't found any

Suggest a fix

I tried to look all around the source code but I couldn't find the reason for it, as the content is processed correctly for both requestBody and responses.

DonDi94 avatar May 29 '19 15:05 DonDi94

Facing the same issue on 4.3.0. Any news on this?

RaduFurnea avatar Apr 14 '20 09:04 RaduFurnea