OpenAPITools / OpenAPITools/openapi-generator

[BUG] Java/Spring generator wrongly emits warnings related to oneOf discriminator

Open
#17,893 4 comments 0 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

Java/Spring generator wrongly emits warnings related to oneOf discriminator:
[WARNING] 'getPets_request' defines discriminator 'pet_type', but the referenced schema 'Cat' is incorrect. pet_type is missing from the schema, define it as required and type string [WARNING] 'getPets_request' defines discriminator 'pet_type', but the referenced schema 'Dog' is incorrect. pet_type is missing from the schema, define it as required and type string

Expected output:
Valid generated pojo models
No misleading warnings related to oneOf 'pet_type' discriminator.

Actual output:
Valid generated pojo models.
Misleading warnings related to oneOf 'pet_type' discriminator.

openapi-generator version

7.3.0

OpenAPI declaration file content or url
openapi: 3.0.3
servers:
  - url: http://localhost/api
    description: Local environment
info:
  description: API
  version: 0.0.0
  title: Api
  x-audience: business-unit-internal
  x-api-id: a8fb5db3-49ef-41c0-a12d-b670cbf64943
  contact:
    name: Unknown
    url: http://unknown.api
    email: unknown@address.unk
paths:
  /pets:
    get:
      operationId: getPets
      requestBody:
        content:
          application/json:
            schema:
              oneOf:
                - $ref: '#/components/schemas/Cat'
                - $ref: '#/components/schemas/Dog'
              discriminator:
                propertyName: pet_type
      responses:
        '200':
          description: Updated

components:
  schemas:
    Pet:
      type: object
      required:
        - petType
      properties:
        petType:
          type: string
      discriminator:
        propertyName: petType
    Cat:
      allOf:
        - $ref: '#/components/schemas/Pet'
        - type: object
          # all other properties specific to a `Cat`
          properties:
            name:
              type: string
    Dog:
      allOf:
        - $ref: '#/components/schemas/Pet'
        - type: object
          # all other properties specific to a `Dog`
          properties:
            bark:
              type: string

Generation Details
Steps to reproduce

A Maven project to reproduce the issue is attached
openapi-one-of-warning-bug.zip

Related issues/PRs
Suggest a fix

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

Run the attached openapi-one-of-warning-bug.zip Maven reproduction with the provided OpenAPI declaration and compare the Java/Spring generator warnings with the expected output. Trace the oneOf discriminator handling that reports Cat and Dog as invalid; done means valid generated POJO models without the misleading pet_type warnings.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.