OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
21.77k stars 6.57k forks source link

[BUG] [Spring] Open-Api code generator plugin fails to escape backslash character #8707

Open mlhrAnjaria opened 3 years ago

mlhrAnjaria commented 3 years ago

Bug Report Checklist

Description

Trying to generate a Java client from open api specification.

openapi-generator version

4.3.1

OpenAPI declaration file content or url
paths:
  /sources:
    $ref: 'paths.yaml#/~1sources'
  /sources/{directorySourceId}:
    $ref: 'paths.yaml#/~1sources~1{directorySourceId}'
  /sources/{directorySourceId}/actions:
    $ref: 'paths.yaml#/~1sources~1{directorySourceId}~1actions'
openApiGenerate {
        generatorName = "spring"
        outputDir = "$buildDir/openapi".toString()
        apiFilesConstrainedTo = [""]
        modelFilesConstrainedTo = [""]
        supportingFilesConstrainedTo = ["ApiUtil.java"]
        configOptions = [delegatePattern: true, dateLibrary: "java8", useTags: true]
        typeMappings = ["OffsetDateTime" : "Instant"]
        importMappings = ["java.time.OffsetDateTime" : "java.time.Instant"]
        validateSpec = true
    }

Steps to reproduce

./gradlew clean openApiGenerate

It causes error with

#/components/schemas/~1sources~1{directorySourceId} is not defined
#/components/schemas/~1sources~1{directorySourceId} is not defined
#/components/schemas/~1sources~1{directorySourceId} is not defined
~1sources~1{directorySourceId} (model name starts with number) cannot be used as model name. Renamed to Model1sources1directorySourceId

causing model names to be Model1sources1directorySourceId and Model1sources1directorySourceId1actions.

Related issues/PRs

Previous PR on older versions- 1691

Suggest a fix

This works fine with plugin version 4.2.0

chirag2120787 commented 2 years ago

Any workaround for this for latest version?

HariRangarajan-Solace commented 1 year ago

I am trying to get around the issue with the plugin version 4.2.0 but the issue is still present over there too. Any idea on when a fix is expected ?