OpenAPITools / OpenAPITools/openapi-generator
[BUG] substantive difference between yaml and json generator generation
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?
Description
Our openapi spec generation bundling has substantive difference between json and yaml output. We would like to use yaml bundle, but it drops an example (and many other examples).
openapi-generator version
I've tried with:
openapi-generator-cli:v4.3.1
openapi-generator-cli:v5.0.0
openapi-generator-cli:v5.1.0
openapi-generator-cli:latest
OpenAPI declaration file content or url
Path spec
paths:
/enroll:
post:
operationId: enrollCustomer
summary: Enroll Customer
tags: [ Enroll ]
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/CreateEnrollment'
CreateEnrollment
CreateEnrollment:
description: Describes an example.
type: object
additionalProperties: false
properties:
customer:
$ref: './customers.yml#/components/schemas/Customer'
account:
$ref: './customers.yml#/components/schemas/Account'
statementDeliveryOptions:
$ref: './statements.yml#/components/schemas/CreateCustomerPreferences'
required:
- customer
- account
- statementDeliveryOptions
Customer
Customer:
oneOf: # whichever option is listed first is the one for which example JSON will be displayed in the swagger editor
- $ref: '#/components/schemas/CorporationAsCustomer'
- $ref: '#/components/schemas/SoleProprietorAsCustomer'
- $ref: '#/components/schemas/IndividualAsCustomer'
discriminator:
propertyName: type
mapping:
individual: '#/components/schemas/IndividualAsCustomer'
sole-proprietor: '#/components/schemas/SoleProprietorAsCustomer'
corporation: '#/components/schemas/CorporationAsCustomer'
non-profit: '#/components/schemas/CorporationAsCustomer'
partnership: '#/components/schemas/CorporationAsCustomer'
llc: '#/components/schemas/CorporationAsCustomer'
Generation Details
for json bundle
rm -rf ./bundle
mkdir -p ./bundle
docker run --rm \
-u $(USERID):$(GROUPID) \
-v ${PWD}:/local openapitools/openapi-generator-cli:v5.0.0 generate \
--input-spec /local/openapi/openapi.yaml \
--output /local/bundle \
--generator-name openapi
for yaml bundle
rm -rf ./bundle
mkdir -p ./bundle
docker run --rm \
-u $(USERID):$(GROUPID) \
-v ${PWD}:/local openapitools/openapi-generator-cli:v5.0.0 generate \
--input-spec /local/openapi/openapi.yaml \
--output /local/bundle \
--generator-name openapi-yaml
Steps to reproduce
Run each of the above commands for generating both a json and yaml bundle.
Comparing the /enroll endpoint is different, most concerning is the dropped example in the yaml output.
json output:
"CreateEnrollment" : {
"additionalProperties" : false,
"description" : "Describes an example.",
"properties" : {
"customer" : {
"$ref" : "#/components/schemas/Customer"
},
"account" : {
"$ref" : "#/components/schemas/Account"
},
"statementDeliveryOptions" : {
"$ref" : "#/components/schemas/CreateCustomerPreferences"
}
},
"required" : [ "account", "customer", "statementDeliveryOptions" ],
"type" : "object"
},
yaml output:
CreateEnrollment:
additionalProperties: false
description: Describes an example.
example:
statementDeliveryOptions:
mail: false
account:
accountID: e1b1544a
routingNumber: "051504597"
institution:
routingNumber: "123456780"
phoneNumber: "5551112222"
address:
zip: "43724"
address2: ""
city: CALDWELL
address1: 430 NORTH ST
state: OH
name: First Bank
archivedAt: 2020-12-03T03:09:49.381Z
holderName: My Company,llc or Wade Arnold
customerID: e1b1544a
accountNumber: "0001027028"
type: checking
maskedAccountNumber: "0001027028"
status: validated
properties:
customer:
$ref: '#/components/schemas/Customer'
account:
$ref: '#/components/schemas/Account'
statementDeliveryOptions:
$ref: '#/components/schemas/CreateCustomerPreferences'
required:
- account
- customer
- statementDeliveryOptions
type: object
Notice the example for customer is dropped in the yaml. I expect the customer example to be present.
I recognize this is a partial and will not be 100% to reproduce. I could demo the issue, or get on a call to demonstrate. I can't provide the repo as our code models are tied in. I could provide more (all) complete spec files if that would be helpful.
Related issues/PRs
I found some adjacent PR's but nothing that is the same.
Suggest a fix
I suspect this has to do with using $ref for complex structures which themselves have oneOf with discriminator.
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 with the supplied OpenAPI fragments and run the two openapi-generator-cli commands using the openapi and openapi-yaml generators. Compare the generated JSON and YAML bundles, focusing on the customer example under CreateEnrollment; done means the YAML output preserves the example consistently with the JSON output.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, json, yaml
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100