-
Notifications
You must be signed in to change notification settings - Fork 9.1k
Improve enum values for Enum Type in Swagger ReadOnly documentation #4191
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
Conversation
…ptimisation) and also adding default/example value
…nother way to have enums values in swagger.json)
do you have some news about this pull request ? |
@shockey ? :) |
@dedece35 we've slated time next week to address open PRs, check their functionality, give feedback, and merge if appropriate. Thanks for submitting the PR, and thanks for waiting. We appreciate the community contributions, just a bit overwhelmed with work :) |
@webron OK ... thanks for your answer :) |
@webron I let myself to revive you about my pull-request :) thanks again :) |
@dedece35 - I'm willing to go ahead and merge it (pending code review) for the functionality - but keep in mind that we may change it completely in the future. The need is understandable, which is why I think we should move forward with it, but design wise it may not be the best solution (no offense). |
@@ -0,0 +1,1079 @@ | |||
{ |
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.
Is there any particular reason this file was added?
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.
hello @shockey, this file is a simple copy of original http://petstore.swagger.io/v2/swagger.json with a new use case for enum values. In original swagger-petstore.json you can find enum values inside "get/parameters/items" ressource (example with path "/pet/findByStatus"). In the new swagger JSON file, "enum" values can appear in "get/parameters" and not only in "items" ressource (example with path "/pet/findByStock"). Indeed, this file is for testing to check enum values are also processed if are'nt inside "items" ressource : developer can use http://localhost:3200/swagger-petstore-enum.json to see the swagger-ui rendering
|
||
if (isDisplayParamItemsEnum) { // if we have an array, default value is in "items" | ||
paramDefaultValue = paramItems.get("default") | ||
if (paramExample == undefined) { |
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.
Should use ===
instead of ==
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.
ok, no problem.
isDisplayParamItemsEnum = true | ||
|
||
if ( paramEnum !== undefined ) { | ||
if (paramEnum.size > 0) { |
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.
These two conditionals should be collapsed into one if
statement
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.
ok, no problem.
if ( paramItems !== undefined ) { | ||
paramItemsEnum = param.get("items").get("enum") | ||
|
||
if (paramItems !== undefined) { |
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.
These statements should be inverted: the if
statement should have a positive condition (paramItems === undefined
) and the else statement should be used for the negative case.
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.
in this condition, I have no positive case : I only want to do things in negative case. I can't translate this condition in positive way.
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.
@shockey changes done.
the purpose of this file lives on in the e2e test specs folder
thanks @dedece35! 😄 |
thanks to you :) |
SwaggerUI documentation in ReadOnly mode gives :
From improvement Adding enum values for Enum Type in Swagger ReadOnly documentation #3977
One enum items representation wasn't considered in swagger.json
Currently considered in swagger.json :
... "parameters": [ { "name": "status", "in": "query", "description": "Status values that need to be considered for filter", "required": true, "type": "array", "items": { "type": "string", "enum": [ "available", "pending", "sold" ], "default": "available", "example": "pending" }, "collectionFormat": "multi" } ], ...
Not considered in swagger.json (example swagger.json generated from swagger annotations in Java code) - there is no "items" structure for "enum" values :
... "parameters": [ { "name": "stockstatus", "in": "query", "description": "stock status values that need to be considered for filter", "required": false, "type": "string", "default": "full", "x-example": "empty", "enum": [ "empty", "halfempty", "full" ] } ], ...
Description
Motivation and Context
As I described in my old PR #3977 , I think it's good idea to have access to default value, example value et availables values in readonly mode (not in TryItOut mode).
This PR is able to solve a new situation in swagger.json (enum values can be out of "items" structure)
There is NO issue for this featureFixes #2873.
How Has This Been Tested?
I tested in the same way as my old PR #3977
"npm test" results :
236 passing (744ms) 11 pending
Screenshots (if appropriate):
the red square zone is the result with new path added ("/store/findByStock") and new Enum values managment

Checklist
My PR contains...
src/
is unmodified: changes to documentation, CI, metadata, etc.)package.json
)My changes...
Documentation
Automated tests