swagger-api / swagger-api/swagger-codegen
[aspnetcore] exampleJson invalid template generation of over-quoted \\" for array of strings
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
When generating aspnetcore server code, the controller template for exampleJson renders incorrect escaped output. Double Backslash followed by quote which breaks the build. It seems to be when inside an array and where the values are string not integer.
exampleJson = .... Shortened
\"metadata\" : [ [ {\n \"values\" : [ \"[\\"Value 1\\",\\"Value 2\\",\\"Value 3\\"]\", \"[\\"Value 1\\",\\"Value 2\\",\\"Value 3\\"]\" ],\n \"key\" : \"Key 1\"\n },
note the \"
Swagger-codegen version
3.0.10
Swagger declaration file content or url
MetaData:
type: object
properties:
key:
type: string
example: Key 1
values:
type: array
items:
type: string
example:
- Value 1
- Value 2
- Value 3
Command line used for generation
swagger-codegen generate
-i ./conferences.yaml
-l aspnetcore
--aspnet-core-version 2.2
--interface-controller
-c config.json
-o ../
Steps to reproduce
- run command
- examine output
- look at incorrect quotes
- note - it only seems to be with strings in arrays of this pattern
Related issues/PRs
#9586
#5460
Suggest a fix/enhancement
Looked at AbstractCSharpCodegen.java as possible candidate but wanted to check if there is an obvious reason first.
if (operation.examples != null){
for (Map<String, String> example : operation.examples)
{
for (Map.Entry<String, String> entry : example.entrySet())
{
// Replace " with \", \r, \n with \\r, \\n
String val = entry.getValue().replace("\"", "\\\"")
.replace("\r","\\r")
.replace("\n","\\n");
entry.setValue(val);
}
}
}
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
Reproduce the generated aspnetcore controller with the supplied YAML and command, then inspect the example-processing code in AbstractCSharpCodegen.java. Compare string-array examples with integer arrays and verify that the generated controller builds without over-quoted values.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, java
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100