[BUG][kotlin] Kotlin generated code does not compile when parameter name contains $
Created by: sarod
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?
Description
Kotlin generator generates invalid code when parameter name contain $
openapi-generator version
4.0.0-beta2
OpenAPI declaration file content or url
openapi: "3.0.0"
info:
version: "1.0.0"
title: Swagger Petstore
license:
name: MIT
servers:
- url: http://petstore.swagger.io/v1
paths:
/pets/{$petId}:
get:
summary: Info for a specific pet
operationId: showPetById
tags:
- pets
parameters:
- name: $petId
in: path
required: true
description: The id of the pet to retrieve
schema:
type: string
responses:
"200":
description: Expected response to a valid request
content:
application/json:
schema:
$ref: "#/components/schemas/Pets"
default:
description: unexpected error
content:
application/json:
schema:
$ref: "#/components/schemas/Error"
components:
schemas:
Pet:
required:
- id
- name
properties:
id:
type: integer
format: int64
name:
type: string
tag:
type: string
Pets:
type: array
items:
$ref: "#/components/schemas/Pet"
Error:
required:
- code
- message
properties:
code:
type: integer
format: int32
message:
type: string
Command line used for generation
Using the open api above as the content of petstore.yaml openapi-generator generate -i ./petstore.yaml -g kotlin
Steps to reproduce
- Copy the OpenAPI declaration file content to petstore.yaml
- Generate using openapi-generator generate -i ./petstore.yaml -g kotlin
- Follow the README instructions:
- gradle wrapper
- ./gradlew check assemble
Fails with
e: generator-test/src/main/kotlin/org/openapitools/client/apis/PetsApi.kt: (28, 21): Parameter name expected
e: generator-test/src/main/kotlin/org/openapitools/client/apis/PetsApi.kt: (28, 22): Expecting comma or ')'
e: generator-test/src/main/kotlin/org/openapitools/client/apis/PetsApi.kt: (28, 22): Expecting ')'
e: generator-test/src/main/kotlin/org/openapitools/client/apis/PetsApi.kt: (28, 23): Expecting member declaration
e: generator-test/src/main/kotlin/org/openapitools/client/apis/PetsApi.kt: (28, 27): Expecting member declaration
e: generator-test/src/main/kotlin/org/openapitools/client/apis/PetsApi.kt: (28, 33): Expecting member declaration
e: generator-test/src/main/kotlin/org/openapitools/client/apis/PetsApi.kt: (28, 34): Expecting member declaration
e: generator-test/src/main/kotlin/org/openapitools/client/apis/PetsApi.kt: (28, 35): Expecting member declaration
e: generator-test/src/main/kotlin/org/openapitools/client/apis/PetsApi.kt: (28, 39): Expecting member declaration
e: generator-test/src/main/kotlin/org/openapitools/client/apis/PetsApi.kt: (28, 41): Expecting member declaration
e: generator-test/src/main/kotlin/org/openapitools/client/apis/PetsApi.kt: (28, 47): Expecting member declaration
e: generator-test/src/main/kotlin/org/openapitools/client/apis/PetsApi.kt: (28, 48): Expecting member declaration
e: generator-test/src/main/kotlin/org/openapitools/client/apis/PetsApi.kt: (28, 54): Expecting member declaration
e: generator-test/src/main/kotlin/org/openapitools/client/apis/PetsApi.kt: (28, 56): Expecting member declaration
e: generator-test/src/main/kotlin/org/openapitools/client/apis/PetsApi.kt: (28, 58): Expecting member declaration
e: generator-test/src/main/kotlin/org/openapitools/client/apis/PetsApi.kt: (28, 64): Expecting member declaration
e: generator-test/src/main/kotlin/org/openapitools/client/apis/PetsApi.kt: (28, 65): Expecting member declaration
e: generator-test/src/main/kotlin/org/openapitools/client/apis/PetsApi.kt: (28, 70): Expecting member declaration
e: generator-test/src/main/kotlin/org/openapitools/client/apis/PetsApi.kt: (28, 71): Expecting member declaration
e: generator-test/src/main/kotlin/org/openapitools/client/apis/PetsApi.kt: (28, 74): Expecting member declaration
e: generator-test/src/main/kotlin/org/openapitools/client/apis/PetsApi.kt: (28, 76): Expecting member declaration
e: generator-test/src/main/kotlin/org/openapitools/client/apis/PetsApi.kt: (28, 76): Function declaration must have a name
e: generator-test/src/main/kotlin/org/openapitools/client/apis/PetsApi.kt: (34, 22): Unresolved reference: petId
e: generator-test/src/main/kotlin/org/openapitools/client/apis/PetsApi.kt: (34, 44): Unresolved reference: petId
e: generator-test/src/main/kotlin/org/openapitools/client/apis/PetsApi.kt: (34, 65): Unresolved reference: petId
e: generator-test/src/main/kotlin/org/openapitools/client/apis/PetsApi.kt: (44, 37): Type mismatch: inferred type is Array<Pet> but Unit was expected
Related issues/PRs
No related issue
Suggest a fix
$ should be escaped when used in kotlin strings names