OpenAPITools / OpenAPITools/openapi-generator
Problem reading vendor extensions applied of properties
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)?
- Have you tested with the latest master to confirm the issue still exists?
- Have you searched for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
There is a bug in the reading of vendor extensions applied to properties when the property is a referenced object.
In this case the extensions are ignored. I have checked it against a variety of languages and the effect is the same across all of them, so the problem is probably in the swagger parser, but I thought it should be reported here as it manifest as a bug here, even if the source is in another tool.
openapi-generator version
I have check it in
- 4.3.0
- 5.3.0
- 6.2.1
Didn't check master as there is no sign its been considered and it is probably a problem with the swagger parser.
OpenAPI declaration file content or url
To illustrate the problem consider the following schema:
test_message:
type: object
properties:
primitive:
type: integer
x-format: u32
x-maitred-index: 0
in_line:
type: object
x-maitred-index: 1
properties:
id:
description: Vehical registation ID.
type: string
x-maitred-index: 0
description: in_line description
ref_obj:
$ref: '#/ref_obj'
x-maitred-index: 2
description: ref_obj external description
ref_obj:
type: object
required:
- id
description: ref_obj internal description
properties:
id:
description: Vehical registation ID.
type: string
x-maitred-index: 0
Generation Details
I have tried it with
java -cp .:-/src -DdebugModels -jar openapi-generator-cli-6.2.1.jar generate
-i schema/api_def/objects_api.yaml
-g csharp
--additional-properties=library=native,serializationLibrary=jackson,java8=true
-t templates/csharp
-o log/generation.log
and with additional properties set to
--additional-properties=library=native,serializationLibrary=jackson
--additional-properties=library=native
--additional-properties=serializationLibrary=jackson
as well as no additional properties.
Steps to reproduce
If you look at the relevant parameters of the JSON generated from the above schema which is passed to the mustache template, you get the following:
C#
"importPath" : "Model.TestMessage",
"model" : {
"name" : "test_message",
"vars" : [ {
"baseName" : "primitive",
"isPrimitiveType" : true,
"isModel" : false,
"vendorExtensions" : {
"x-format" : "u32",
"x-maitred-index" : 0,
"x-csharp-value-type" : true,
"x-is-value-type" : true,
"x-emit-default-value" : false
},
}, {
"baseName" : "in_line",
"isPrimitiveType" : false,
"isModel" : true,
"vendorExtensions" : {
"x-emit-default-value" : false,
"x-maitred-index" : 1,
"x-is-value-type" : false
},
}, {
"baseName" : "ref_obj",
"isPrimitiveType" : false,
"isModel" : true,
"vendorExtensions" : {
"x-emit-default-value" : false,
"x-is-value-type" : false
},
} ],
}
Rust
"name" : "test_message",
"vars" : [ {
"baseName" : "primitive",
"isPrimitiveType" : true,
"isModel" : false,
"vendorExtensions" : {
"x-format" : "u32",
"x-maitred-index" : 0
},
}, {
"baseName" : "in_line",
"isPrimitiveType" : false,
"isModel" : true,
"vendorExtensions" : {
"x-maitred-index" : 1
},
}, {
"baseName" : "ref_obj",
"isPrimitiveType" : false,
"isModel" : true,
"vendorExtensions" : { },
} ],
Python Flask
"model" : {
"name" : "test_message",
"vars" : [ {
"baseName" : "primitive",
"isPrimitiveType" : true,
"isModel" : false,
"vendorExtensions" : {
"x-format" : "u32",
"x-maitred-index" : 0
},
}, {
"baseName" : "in_line",
"isPrimitiveType" : false,
"isModel" : true,
"vendorExtensions" : {
"x-maitred-index" : 1
},
}, {
"baseName" : "ref_obj",
"isPrimitiveType" : false,
"isModel" : true,
"vendorExtensions" : { },
} ],
Related issues/PRs
Couldn't find any.
Suggest a fix
I have checked several other languages and it is all basically the same. I think the swagger parser, when its sees a reference it does not bother the read and/or pass back the extensions, but in the case of in-line processes it does. In the case of C# x-emit-default-value and x-is-value-type are added by the generator, so only the schema present entries are missing.
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 by running the schema/api_def/objects_api.yaml example with the shown openapi-generator CLI command and inspect the debugModels output for the ref_obj property. Compare the C#, Rust, and Python Flask results to determine whether extensions are lost in the parser or generator. Done means vendor extensions on referenced properties are preserved consistently in the generated model data.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, flask, java, rust, yaml
- Domain
- backend-api-design, devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 28/100