OpenAPITools / OpenAPITools/openapi-generator
[BUG] [Spring] Open-Api code generator plugin fails to escape backslash character
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?
- What's the actual output vs expected output?
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
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 with the reported ./gradlew clean openApiGenerate entry point, using the supplied OpenAPI paths and Spring configuration on generator version 4.3.1. Compare the generated model names with the expected escaped path names and verify behavior against version 4.2.0; done means generation completes without the reported undefined-schema errors or mangled model names.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi, spring
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100