Skip to content

[BUG] Discriminator mapping not correct when using oneOf with discriminator #6782

@argenstijn

Description

@argenstijn

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
    yes
  • Have you validated the input using an OpenAPI validator (example)?
    yes
  • What's the version of OpenAPI Generator used?
    4.3.1
  • Have you search for related issues/PRs?
    yes
Description

The generated code leads to the following result:

@JsonInclude(JsonInclude.Include.NON_NULL)
@javax.annotation.processing.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", date = "2020-06-25T13:58:21.826225400+02:00[Europe/Berlin]")
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.EXISTING_PROPERTY, property = "parentId", visible = true)
@JsonSubTypes({
@JsonSubTypes.Type(value = TestHolder.class, name = "whatsup"),
@JsonSubTypes.Type(value = WhatHolder.class, name = "tst"),
})

public interface ArrayItem {
public String getParentId();
}

I would expect the following result

@JsonInclude(JsonInclude.Include.NON_NULL)
@javax.annotation.processing.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", date = "2020-06-25T13:58:21.826225400+02:00[Europe/Berlin]")
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.EXISTING_PROPERTY, property = "parentId", visible = true)
@JsonSubTypes({
@JsonSubTypes.Type(value = TestHolder.class, name = "whatsup"),
@JsonSubTypes.Type(value = WhatHolder.class, name = "tst"),
})

public interface ArrayItem {
public ParentIdEnum getParentId();
}

It should use the correct type from the child!.

See content of YAML

OpenAPI declaration file content or url

openapi: 3.0.0
info:
version: "0.0.0.1"
title: ""
x-apiType: ""
description: ""
paths:
/test:
post:
tags:
- "test"
description: "tes"
operationId: "test"
requestBody:
description: "Payload for premium calculation."
required: true
content:
application/json:
schema:
$ref: "#/components/schemas/NewRequest"
responses:
"200":
description: "Successful operation"
components:
schemas:
Parent:
required:
- parentId
type: object
properties:
parentId:
type: string
enum:
- whatsup
- tst
discriminator:
propertyName: parentId
mapping:
whatsup: "#/components/schemas/What"
tst: "#/components/schemas/Test"
What:
type: object
allOf:
- $ref: "#/components/schemas/Parent"
properties:
whatever:
type: string
Test:
type: object
allOf:
- $ref: "#/components/schemas/Parent"
properties:
test:
type: string
NewRequest:
type: object
properties:
parents:
type: array
minItems: 1
maxItems: 100
items:
$ref: "#/components/schemas/arrayItem"
arrayItem:
type: object
oneOf:
- $ref: "#/components/schemas/TestHolder"
- $ref: "#/components/schemas/WhatHolder"
discriminator:
propertyName: parentId
mapping:
whatsup: "#/components/schemas/TestHolder"
tst: "#/components/schemas/WhatHolder"
TestHolder:
type: object
allOf:
- $ref: "#/components/schemas/What"
properties:
testHolder:
type: string
WhatHolder:
type: object
allOf:
- $ref: "#/components/schemas/Test"
properties:
whatHolder:
type: string

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