-
Notifications
You must be signed in to change notification settings - Fork 52
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
Swagger documentation for BodyParam and Responses with JSON models generated from case classes by reflections #653
Conversation
.editorconfig
Outdated
@@ -0,0 +1,7 @@ | |||
[*] |
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.
Can you remove this file? I guess it's only for a particular editor thus should not be committed.
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.
This is cross editors configuration for code autoformatting supported by rather a lot of IDEs and editors: https://editorconfig.org/#download
The idea was to allow to share the same configuration between different project developers. But if you insist, I'll remove it.
* | ||
* @param name field name | ||
* @param tpe field type | ||
* @param isRequired_? if true means that field is required |
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.
What's the purpose to add _?
to the name? Should we simply name it required
?
|
||
/** | ||
* Utility functions to reflect scala case classes to structure that can be rendered to Swagger documentation | ||
* User: smeagol74 |
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.
Anyone can freely change any file, so let's remove User
, Date
, and Time
.
def isArrayType_?(tpe: Type): Boolean = _arraySymbols.contains(tpe.typeSymbol.name) | ||
|
||
|
||
def _reflectField(fld: TermSymbol): Swagger.JsonField = { |
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.
Please remove _
prefix because is ugly. Add private
if it's private.
@ngocdaothanh , I applied all the fixes. Also I rebased my patch over the current master and squashed into the single commit. I did not removed the .editorconfig yet, hope you will decide to leave it in project as useful. |
👍 Thanks, I've commented at the new PR. The PR is very cool, I'm just requesting for some changes in coding style, so that the new files look consistent with existing files. |
This patch allows to document JSON models from case classes with Swagger like this example:
And this code will produce following swagger.json
You may want to load that json to Swagger Online Editor to check how the documentation looks like.
This patch supports simple case classes as models (not sure about inheritance and other advanced features),
Seq
,List
,Set
as array types,Option
for non-mandatory fields.