-
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
Conversation
{ | ||
// Replace " with \", \r, \n with \\r, \\n | ||
String val = entry.getValue().replace("\"", "\\\"") | ||
.replace("\r","\\r") |
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…
- This will replace unexpected results. For instance, what if my example was:
{ "example_commands": [ "\run", "\nip", "\yap", "\rollover" ], "fast_commands": [ "\\run", "\\rollover" ], "omg_slow_down_puppy": [ "\\\run", "\\\rollover" ], "search_command" : "\\" }
- This will lead to failed compilation if we don't escape other things like double-quotes and format placeholders like
{0}
,{0,15}
,{0:t}
, etc. - afiak this will result in multiline strings, regardless of how many times you escape these characters. I could be wrong on that, though.
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:
this\r"matches
this\rdoesn't
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!
Thanks for the PR but your commit (as shown in the Commits tab) is not linked to your Github account, which means this PR won't count as your contribution in https://github.com/swagger-api/swagger-codegen/graphs/contributors. Let me know if you need help fixing it. |
f5e2b65
to
3a99c43
Compare
@knom seems like the rebase failed as the PR now contains commits not authored by you. I'll create another PR by cherry-picking the commits owned by you. |
fe09b46
to
b9048d3
Compare
@@ -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 comment
The 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 comment
The 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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
There was a discussion to add an isJson
tag before but no one seems to have time to implement that yet.
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.
why a tag rather than Mustache filter? just curious.
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.
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.
@wing328 I've just redone the REBASE.. now it should work! |
RE: Issue #7092, #5423
@mandrean @jimschubert
Added support for Operation EXAMPLE value in ASP.NET Core Generator.
Now exampleJson is currectly generated.