Skip to content

Commit b9048d3

Browse files
committed
Added support for Operation EXAMPLE value in ASP.NET Core Generator.
1 parent 643ef64 commit b9048d3

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/AbstractCSharpCodegen.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,20 @@ public Map<String, Object> postProcessOperations(Map<String, Object> objs) {
422422
}
423423
}
424424

425+
if (operation.examples != null){
426+
for (Map<String, String> example : operation.examples)
427+
{
428+
for (Map.Entry<String, String> entry : example.entrySet())
429+
{
430+
// Replace " with \", \r, \n with \\r, \\n
431+
String val = entry.getValue().replace("\"", "\\\"")
432+
.replace("\r","\\r")
433+
.replace("\n","\\n");
434+
entry.setValue(val);
435+
}
436+
}
437+
}
438+
425439
processOperation(operation);
426440
}
427441
}

modules/swagger-codegen/src/main/resources/aspnetcore/controller.mustache

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ namespace {{packageName}}.Controllers
4646
{{/dataType}}{{/responses}}
4747
{{#returnType}}
4848
string exampleJson = null;
49+
{{#examples}}
50+
exampleJson = "{{{example}}}";
51+
{{/examples}}
4952
{{#isListCollection}}{{>listReturn}}{{/isListCollection}}{{^isListCollection}}{{#isMapContainer}}{{>mapReturn}}{{/isMapContainer}}{{^isMapContainer}}{{>objectReturn}}{{/isMapContainer}}{{/isListCollection}}
5053
{{!TODO: defaultResponse, examples, auth, consumes, produces, nickname, externalDocs, imports, security}}
5154
//TODO: Change the data returned

0 commit comments

Comments
 (0)