OpenAPITools / OpenAPITools/openapi-generator

[BUG] [Java] Vendor extensions on discriminator schema objects seem ignored

Open
#17,110 1 comment 5 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
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
  1. Patch the typeInfoAnnotation.mustache file as outlined above
  2. Use the provided yaml file as an example
  3. Generate the model objects and verify that defaultImpl has not been added on the @JsonTypeInfo annotation

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.