Skip to content

[BUG][DefaultCodegen] OneOf with discriminator for referenced object with allOf  #19261

Description

@Axent96

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

Warninng: [main] WARN o.o.codegen.DefaultCodegen - 'GeneralProduct' defines discriminator 'type', but the referenced schema 'HomeProduct' is incorrect. type is missing from the schema, define it as required and type string

openapi-generator version

7.7.0

OpenAPI declaration file content or url
openapi: 3.0.3
info:
  title: test
  description: Test
  version: "2.0"
servers:
  - url: 'https://example.com'
security:
  - APIKeyHeader: []
paths:
  /products/{identifier}:
    get:
      tags:
        - Product Item
      summary: Get single product
      parameters:
        - name: identifier
          in: path
          required: true
          schema:
            type: string
          example: "100001951"
          description: The product identifier
      responses:
        200:
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/GeneralProduct'
components:
  schemas:
    GeneralProduct:
      type: object
      oneOf:
        - $ref: '#/components/schemas/HomeProduct'
        - $ref: '#/components/schemas/InternetProduct'
      discriminator:
        propertyName: type
        mapping:
          home: '#/components/schemas/HomeProduct'
          internet: '#/components/schemas/InternetProduct'
    HomeProduct:
      allOf:
        - $ref: "#/components/schemas/Product"
        - type: object
          required:
            - newField
          properties:
            newField:
              type: string
    InternetProduct:
      allOf:
        - $ref: "#/components/schemas/Product"
        - type: object
          required:
            - extraField
          properties:
            extraField:
              type: string
    Product:
      type: object
      required:
        - productId
        - name
        - type
      properties:
        productId:
          type: string
        name:
          type: string
        type:
          $ref: '#/components/schemas/AboType'
    AboType:
      type: string
      enum:
        - "internet"
        - "home"
Generation Details

java -jar codegen/openapi-generator-cli-7.7.0.jar generate -i ./api.json -g php --invoker-package=Test\Main --api-package=Client --model-package=Models --additional-properties=variableNamingConvention=camelCase --additional-properties=disallowAdditionalPropertiesIfNotPresent=false --additional-properties=legacyDiscriminatorBehavior=false -o /tmp/

Steps to reproduce

Generate a library

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions