diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/AbstractCSharpCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/AbstractCSharpCodegen.java index a2f1bfffb1f..50e278e714e 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/AbstractCSharpCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/AbstractCSharpCodegen.java @@ -422,6 +422,20 @@ public Map postProcessOperations(Map objs) { } } + if (operation.examples != null){ + for (Map example : operation.examples) + { + for (Map.Entry entry : example.entrySet()) + { + // Replace " with \", \r, \n with \\r, \\n + String val = entry.getValue().replace("\"", "\\\"") + .replace("\r","\\r") + .replace("\n","\\n"); + entry.setValue(val); + } + } + } + processOperation(operation); } } diff --git a/modules/swagger-codegen/src/main/resources/aspnetcore/controller.mustache b/modules/swagger-codegen/src/main/resources/aspnetcore/controller.mustache index 05db73f1a0c..ea447e946f9 100644 --- a/modules/swagger-codegen/src/main/resources/aspnetcore/controller.mustache +++ b/modules/swagger-codegen/src/main/resources/aspnetcore/controller.mustache @@ -46,6 +46,9 @@ namespace {{packageName}}.Controllers {{/dataType}}{{/responses}} {{#returnType}} string exampleJson = null; + {{#examples}} + exampleJson = "{{{example}}}"; + {{/examples}} {{#isListCollection}}{{>listReturn}}{{/isListCollection}}{{^isListCollection}}{{#isMapContainer}}{{>mapReturn}}{{/isMapContainer}}{{^isMapContainer}}{{>objectReturn}}{{/isMapContainer}}{{/isListCollection}} {{!TODO: defaultResponse, examples, auth, consumes, produces, nickname, externalDocs, imports, security}} //TODO: Change the data returned