Skip to content

[BUG] [Kotlin] overriden variables are not generated with 'override' keyword #22216

@Sylvain-maillard

Description

@Sylvain-maillard

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator?
  • 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
  • Given a openapi spec containing a Schema (Car) that inherits from another (Vehicle) using discriminator and allOf,
  • and the Schema Vehicle define a property "x" of type "object",
  • and the Schéma Car redefining the property by specializing the type to "string"
  • when I generate the code, then the class Car won't compile because the redefined var x does not have the modifier override.

I expect the attributes of Car to have the override keyword as it is valid in kotlin to do that.

openapi-generator version

Tested on latest v7.17.0-SNAPSHOT.

OpenAPI declaration file content or url

see https://gist.github.com/Sylvain-maillard/fe3d0e25d4b21e6acfee8b0544da12e8

Generation Details

Issue was reproduce using docker without specific parameters except the kotlin generator.

docker run --rm -v ${PWD}:/local openapitools/openapi-generator-cli generate -i /local/issue.yaml -g kotlin -o /local/generated
Steps to reproduce
  • generate the kotlin code using the provided yaml
  • the overriden attributes of class Car misses the override keyword.
Related issues/PRs
Suggest a fix

I'have found a quick and dirty fix that rely on rescanning all schemas, looking for duplicate vars on each parents.

I've added the code in org.openapitools.codegen.languages.AbstractKotlinCodegen#postProcessAllModels

It's probably better to fix the issue when the CodegenProperty instances are created, but I didn't have time to dig in that.

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