OpenAPITools / OpenAPITools/openapi-generator
[BUG][KOTLIN] Using a $ in a string in the open api spec breaks kotlin generation.
Nobody has claimed this yet.
- 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?
Description
I am attempting to use a $ in my open api spec for a query param $next for example , but generating it makes the kotlin code uncompilable because the $ doesn't get escaped in the generated code. I can reproduce the same behavior by adding a $ into a documentation string as well.
openapi-generator version
6.6.0, gradle plugin, doesn't seem to be a regression.
OpenAPI declaration file content or url
info:
contact:
email: email@provider.com
name: Maintainer
description: 'This schema cannot be compiled after it is generated using the $kotlin generator because the $ is not escaped and kotlin allows you to use it as a placeholder. Example:<br><br>
val variable: String = "String"<br>
printlin("Example placeholder $variable")<br><br>
Outputs:<br>
Example placeholder String
'
title: Broken $Kotlin Schema
version: v1.0.0
openapi: 3.0.3
servers:
- description: The server
url: http://url
paths:
"/endpoint":
get:
operationId: brokenGet
parameters:
- description: Breaks the $kotlin generation because the $ is not escaped so we can't compile
in: query
name: "$brokenForKotlin"
required: false
schema:
type: string
responses:
'201':
content:
application/json:
schema:
type: object
properties:
"$brokenField":
type: string
description: returns the status of the async request
summary: Breaks the $kotlin generation because the $ is not escaped so we can't compile
tags:
- broken
Generation Details
This is broken for spring boot 3 and (kotlin-spring)
Steps to reproduce
Generate this schema, then compile the code
Related issues/PRs
- Not any that I could find
Suggest a fix
- Escape $'s when writing strings in the generated output
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by generating the provided OpenAPI schema for the kotlin-spring target with the 6.6.0 Gradle plugin, then compile the generated code. Trace how the $ appears in generated documentation, parameter names, and fields, and ensure the generated Kotlin output compiles while preserving the source text.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- kotlin, openapi
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100