Skip to content

unescaped dollar signs in generated kotlin sources #2379

@einsweniger

Description

@einsweniger

(this is a copy of: micronaut-projects/micronaut-gradle-plugin#1162)

Expected Behavior

valid generated kotlin sources from a MS Azure swagger spec

Actual Behaviour

unescaped dollar signs in kotlin code, due to dollar signs in enum values and parameter names, see example:

https://github.com/Azure/azure-rest-api-specs/blob/e5e776854ab5d10da58d1d36fe8521e33d70e510/specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2025-04-01/ComputeRP.json#L204-L211

Java is unaffected.

The Problem is, that kotlin has format Strings, similar to Javascript. A dollar sign, followed by a name (within a string) is assumed to be an existing variable ("$expand" looks for a variable named "expand", same for "$ref").

Image

Steps To Reproduce

for a concise example, use the example yaml, or run functional-tests in the linked project.

swagger: 2.0
info:
  title: Dollar Signs ahead
  version: 1.0.0
  description: might break kotlin
schemes:
- https
produces:
- application/json
consumes:
- application/json
paths:
  /dollarSigns:
    get:
      operationId: getDollarStrings
      description: contains $strings
      parameters:
      - name: $expand
        in: query
        description: also contains $strings
        required: false
        type: string
        enum:
        - ref1/$ref
        - ref2/$ref
      responses:
        "200":
          description: succeeded!
          schema:
            type: string
            description: awesome!
        default:
          description: failed!
          schema:
            type: string
            description: awwwww!
definitions: {}
parameters: {}

Environment Information

N/A

Example Application

https://github.com/einsweniger/micronaut-gradle-plugin/tree/kotlin-dollar_sign_breakage

I am aware, that the issue lies not within the micronaut-gradle-plugin. Unfortunately, the tests here only check for file contents and not if the generated kotlin code can be compiled, so I cannot contribute test breakage in this project, but via the gradle plugin, since that actually runs a kotlin compiler.

If you want to verify this, you can use the linked project and run the

./gradlew :functional-tests:test --tests "io.micronaut.gradle.openapi.OpenApiClientWithKotlinSpec" to verify the problem.

Version

6.18.1 / 6.17.3

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions