OpenAPITools / OpenAPITools/openapi-generator
[BUG] External schemas referenced from the content of a parameter are not found
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator (example)?
- What's the version of OpenAPI Generator used?
- Have you search for related issues/PRs?
- 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.yamlwith the first specification - Create a file
external_components.yamlwith the second specification in the same folder astest.yaml - Put
openapi-generator-cli.jarin 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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at DefaultCodegen, where the warning reports failure to resolve the reference, and compare parameter content handling with the working requestBody and responses paths. Reproduce with test.yaml and external_components.yaml using the csharp-nancyfx generation command; done means the external Ref schema is resolved and the parameter uses it instead of object.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api, backend-api-design
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100