OpenAPITools / OpenAPITools/openapi-generator
[BUG] [Java] Vendor extensions on discriminator schema objects seem ignored
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
When generating code with the jaxrs-spec Java generator, we use a slightly modified typeInfoAnnotation.mustache file in which we check the existence of a custom vendor extension (in this case x-default-type).
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "{{{discriminator.propertyBaseName}}}"{{#vendorExtensions.x-default-type}}, defaultImpl = {{{vendorExtensions.x-default-type}}}.class{{/vendorExtensions.x-default-type}}, visible = true)
However, since version 7 it seems that vendorExtensions is always empty when wrapped inside a #discriminator block (as is the case with typeInfoAnnotation.mustache, see here).
When referencing vendorExtensions.x-default-type outside of the #discriminator block, the extension is found as expected.
openapi-generator version
v7.1.0; this seems to be a regression to v6.6.0 where this scenario worked as expected.
OpenAPI declaration file content or URL
Here is an example to reproduce the issue:
openapi: 3.0.3
info:
title: Test Andy
version: 1.0.0
paths:
/test-andy:
post:
operationId: testAndy
requestBody:
content:
application/json:
schema:
$ref: "#/components/schemas/TestAndyRequest"
responses:
"200":
description: Created
content:
application/json:
schema:
$ref: "#/components/schemas/TestAndyResponse"
components:
schemas:
TestAndyRequest:
x-default-type: "TestAndyRequest1"
type: object
properties:
type:
type: string
discriminator:
propertyName: type
mapping:
one: "#/components/schemas/TestAndyRequest1"
two: "#/components/schemas/TestAndyRequest2"
TestAndyRequest1:
description: A batch ingestion job. The only source types allowed for this job are `table` and `uploaded`.
type: object
allOf:
- $ref: "#/components/schemas/TestAndyRequest"
TestAndyRequest2:
description: A batch ingestion job. The only source types allowed for this job are `table` and `uploaded`.
type: object
allOf:
- $ref: "#/components/schemas/TestAndyRequest"
TestAndyResponse:
type: object
properties:
test:
type: string
Generation Details
I used the following command off of a master build:
java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate \
-i modules/openapi-generator/src/test/resources/3_0/test-andy.yaml \
-g jaxrs-spec \
-o test
Steps to reproduce
- Patch the
typeInfoAnnotation.mustachefile as outlined above - Use the provided
yamlfile as an example - Generate the model objects and verify that
defaultImplhas not been added on the@JsonTypeInfoannotation
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 modules/openapi-generator/src/main/resources/JavaJaxRS/spec/pojo.mustache and the referenced typeInfoAnnotation.mustache, then reproduce using modules/openapi-generator/src/test/resources/3_0/test-andy.yaml and the provided jaxrs-spec generation command. Done means the generated model includes defaultImpl from the x-default-type vendor extension inside the discriminator annotation, as it did in v6.6.0.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100