OpenAPITools / OpenAPITools/openapi-generator

[BUG] [KOTLIN] gradle task "generateOpenApiDocs" wrongly converts data class field names starting with substring "isIn" into OpenApiSpec.json

Open
#14,386 0 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

In our project, we are using Spring+Kotlin for our backend.
We auto-generate an OpenApiSpec.json based on our backend-API-code. We get it from "[baseUrlToOurBackend]/v3/api-docs".
I noticed a strange bug when I checked the auto-generated OpenApiSpec.json:

If I use a field name, that starts with "isIn" (for example "isInviteSuccessful" or "isInhouseProduction") inside of a Kotlin data class, which is used in the endpoints-code of my backend, then it appears with a different field name in the auto-generated OpenApiSpec.json:

Some actual examples I witnessed:

"isInviteSuccessful" in my Kotlin data class translates to "inviteSuccessful" in the auto-generated OpenApiSpec.json

"isOnDemand" in my Kotlin data class translates to "onDemand" in the auto-generated OpenApiSpec.json.

Therefore we started avoiding field names, that start with "is[A-Z]*".
However, we thought that this seems to be a bug and could be fixed in future releases.

openapi-generator version

We are using:

org.springframework.boot version 2.7.5
org.openapi.generator version 6.2.1
org.springdoc.openapi-gradle-plugin version 1.4.0
org.springdoc:springdoc-openapi-ui version 1.6.12

Steps to reproduce

This error is pretty simple to reproduce if you just use the openapi dependencies mentioned above:

  1. Create a Kotlin data class, e.g. "SomeDataClass", and give it two String fields "fieldA" and "isInviteSuccessful".
  2. Create e.g. a GET endpoint that receives an input of type "SomeDataClass".
  3. Now if you run the gradle task "generateOpenApiDocs" and look into the generated OpenApiSpec.json (or just go to "[baseUrlToOurBackend]/v3/api-docs"), you'll see that the first field "fieldA" has its correct name in the "SomeDataClass" model, but the field "isInviteSuccessful" suddenly has the field name "inviteSuccessful".
    The "is[...]" was automatically dropped from the field name!

Since I'm not 100% sure where this topic belongs to, I will adress this issue also in the repo https://github.com/springdoc/springdoc-openapi/

The link is:
https://github.com/springdoc/springdoc-openapi/issues/2032

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

Start by reproducing the issue with the Kotlin data class and the Gradle task "generateOpenApiDocs", then compare the generated OpenApiSpec.json with the original field names. Review the related springdoc-openapi issue 2032 and determine whether the fix belongs there; done means fields such as "isInviteSuccessful" and "isOnDemand" retain their names in the generated schema.

Written by the indexing model from the issue text.

Assessment

Tech stack
kotlin, openapi, spring-boot
Domain
api, backend-api-design
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.