-
Notifications
You must be signed in to change notification settings - Fork 6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[ASP.NET Core] Added support for Operation EXAMPLE value #7091
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -92,6 +92,8 @@ public virtual IActionResult FindPetsByStatus([FromQuery][Required()]List<string | |
// return StatusCode(400); | ||
|
||
string exampleJson = null; | ||
exampleJson = "<Pet>\n <id>123456789</id>\n <name>doggie</name>\n <photoUrls>\n <photoUrls>aeiou</photoUrls>\n </photoUrls>\n <tags>\n </tags>\n <status>aeiou</status>\n</Pet>"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any way to ONLY pick JSON examples here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably a hack, but iterate responses in the generator code and remove them if they don't start with a "{". If you go that route, is suggest logging a warning any time an example is dropped by the generator in this way. Mustache doesn't really have logic. It does allow custom filters, so maybe we could write a filter that will only write a value of it is valid json. An issue with that approach is that you can't pick "the first json example* like you could in The generator processing. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a discussion to add an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why a tag rather than Mustache filter? just curious. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh. I get what you're saying. It would be weird to use a tag to get a single json object from ab list of mixed possible types, I think. |
||
exampleJson = "[ {\n \"tags\" : [ {\n \"id\" : 1,\n \"name\" : \"name\"\n }, {\n \"id\" : 1,\n \"name\" : \"name\"\n } ],\n \"id\" : 0,\n \"category\" : {\n \"id\" : 6,\n \"name\" : \"name\"\n },\n \"status\" : \"available\",\n \"name\" : \"doggie\",\n \"photoUrls\" : [ \"photoUrls\", \"photoUrls\" ]\n}, {\n \"tags\" : [ {\n \"id\" : 1,\n \"name\" : \"name\"\n }, {\n \"id\" : 1,\n \"name\" : \"name\"\n } ],\n \"id\" : 0,\n \"category\" : {\n \"id\" : 6,\n \"name\" : \"name\"\n },\n \"status\" : \"available\",\n \"name\" : \"doggie\",\n \"photoUrls\" : [ \"photoUrls\", \"photoUrls\" ]\n} ]"; | ||
|
||
var example = exampleJson != null | ||
? JsonConvert.DeserializeObject<List<Pet>>(exampleJson) | ||
|
@@ -122,6 +124,8 @@ public virtual IActionResult FindPetsByTags([FromQuery][Required()]List<string> | |
// return StatusCode(400); | ||
|
||
string exampleJson = null; | ||
exampleJson = "<Pet>\n <id>123456789</id>\n <name>doggie</name>\n <photoUrls>\n <photoUrls>aeiou</photoUrls>\n </photoUrls>\n <tags>\n </tags>\n <status>aeiou</status>\n</Pet>"; | ||
exampleJson = "[ {\n \"tags\" : [ {\n \"id\" : 1,\n \"name\" : \"name\"\n }, {\n \"id\" : 1,\n \"name\" : \"name\"\n } ],\n \"id\" : 0,\n \"category\" : {\n \"id\" : 6,\n \"name\" : \"name\"\n },\n \"status\" : \"available\",\n \"name\" : \"doggie\",\n \"photoUrls\" : [ \"photoUrls\", \"photoUrls\" ]\n}, {\n \"tags\" : [ {\n \"id\" : 1,\n \"name\" : \"name\"\n }, {\n \"id\" : 1,\n \"name\" : \"name\"\n } ],\n \"id\" : 0,\n \"category\" : {\n \"id\" : 6,\n \"name\" : \"name\"\n },\n \"status\" : \"available\",\n \"name\" : \"doggie\",\n \"photoUrls\" : [ \"photoUrls\", \"photoUrls\" ]\n} ]"; | ||
|
||
var example = exampleJson != null | ||
? JsonConvert.DeserializeObject<List<Pet>>(exampleJson) | ||
|
@@ -157,6 +161,8 @@ public virtual IActionResult GetPetById([FromRoute][Required]long? petId) | |
// return StatusCode(404); | ||
|
||
string exampleJson = null; | ||
exampleJson = "<Pet>\n <id>123456789</id>\n <name>doggie</name>\n <photoUrls>\n <photoUrls>aeiou</photoUrls>\n </photoUrls>\n <tags>\n </tags>\n <status>aeiou</status>\n</Pet>"; | ||
exampleJson = "{\n \"tags\" : [ {\n \"id\" : 1,\n \"name\" : \"name\"\n }, {\n \"id\" : 1,\n \"name\" : \"name\"\n } ],\n \"id\" : 0,\n \"category\" : {\n \"id\" : 6,\n \"name\" : \"name\"\n },\n \"status\" : \"available\",\n \"name\" : \"doggie\",\n \"photoUrls\" : [ \"photoUrls\", \"photoUrls\" ]\n}"; | ||
|
||
var example = exampleJson != null | ||
? JsonConvert.DeserializeObject<Pet>(exampleJson) | ||
|
@@ -232,6 +238,7 @@ public virtual IActionResult UploadFile([FromRoute][Required]long? petId, [FromF | |
// return StatusCode(200, default(ApiResponse)); | ||
|
||
string exampleJson = null; | ||
exampleJson = "{\n \"message\" : \"message\",\n \"code\" : 0,\n \"type\" : \"type\"\n}"; | ||
|
||
var example = exampleJson != null | ||
? JsonConvert.DeserializeObject<ApiResponse>(exampleJson) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are a few issues with this approach that I see…
{0}
,{0,15}
,{0:t}
, etc.The amount of effort to resolve this is, I don't think, worth the benefit.
Some of this could be resolved by replacing only on boundaries, for example a regex like
\b\\r\b
which would catch probably most cases outside of text occurrences:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great suggestions @jimschubert!
On the double quotes.. I do replace these as well..
I'm not that fluent in Java..
How would I rewrite the code to do regex replace instead?
Thanks!