Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #4171
Closed
Open
Issue created Oct 16, 2019 by Administrator@rootContributor5 of 6 checklist items completed5/6 checklist items

[BUG] Kotlin-Client should support inheritance/$allOf bug with child required properties

Created by: mtraynham

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • What's the version of OpenAPI Generator used?
  • Have you search for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Bounty to sponsor the fix (example)
Description

Inheritance doesn't seem to be supported with kotlin-client. I would have expected a top level interface for parent classes and a child data class implementation which uses override to mark overridden values.

Also, for classes that are inherited via $allOf, it seems required properties on the child class get duplicated as optional properties. Like:

    @Json(name = "c")
    val c: kotlin.String,
    @Json(name = "c")
    val c: kotlin.String? = null

Following the OpenAPI declaration file below, the following is generated: src/main/kotlin/org/openapitools/client/models/Parent.kt

data class Parent (
    @Json(name = "a")
    val a: kotlin.String,
    @Json(name = "b")
    val b: kotlin.String? = null
)

src/main/kotlin/org/openapitools/client/models/Child.kt

data class Child (
    @Json(name = "a")
    val a: kotlin.String,
    @Json(name = "c")
    val c: kotlin.String,
    @Json(name = "b")
    val b: kotlin.String? = null,
    @Json(name = "d")
    val d: kotlin.String? = null,
    @Json(name = "c")
    val c: kotlin.String? = null
)

You'll notice that not only is Parent not an interface, but within Child, property c is duplicated, once as required and secondly as optional.

I would have expected: src/main/kotlin/org/openapitools/client/models/Parent.kt

interface Parent {
    @Json(name = "a")
    val a: kotlin.String
    @Json(name = "b")
    val b: kotlin.String?
}

src/main/kotlin/org/openapitools/client/models/Child.kt

data class Child (
    @Json(name = "a")
    override val a: kotlin.String,
    @Json(name = "b")
    override val b: kotlin.String? = null,
    @Json(name = "c")
    val c: kotlin.String,
    @Json(name = "d")
    val d: kotlin.String? = null
) : Parent
openapi-generator version

4.1.3

OpenAPI declaration file content or url
{
    "openapi": "3.0.1",
    "info": {
        "title": "Test",
        "description": "Test API",
        "contact": {
            "email": "foo@bar.com"
        },
        "version": "1.0.0"
    },
    "servers": [
        {
            "url": "https://192.168.1.1"
        }
    ],
    "paths": {},
    "components": {
        "schemas": {
            "Parent": {
                "required": [
                    "a"
                ],
                "type": "object",
                "properties": {
                    "a": {
                        "type": "string"
                    },
                    "b": {
                        "type": "string"
                    }
                }
            },
            "Child": {
                "required": [
                    "a",
                    "c"
                ],
                "type": "object",
                "allOf": [
                    {
                        "$ref": "#/components/schemas/Parent"
                    },
                    {
                        "type": "object",
                        "properties": {
                            "c": {
                                "type": "string"
                            },
                            "d": {
                                "type": "string"
                            }
                        }
                    }
                ]
            }
        },
        "securitySchemes": {}
    }
}
Command line used for generation
openapi-generator-cli generate -g kotlin -i API.json
Steps to reproduce
Related issues/PRs
Suggest a fix
Assignee
Assign to
Time tracking