Skip to content
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

Request sample outputs differently according to paths in swagger.json #151

Closed
lucychild opened this issue Dec 2, 2016 · 5 comments
Closed

Comments

@lucychild
Copy link

I have a Jersey API running on a Grizzly server and have recently starting using swagger to annotate it and ReDoc to output the swagger. Most of the endpoint requests and responses are output as expected with readonly fields in the response but not the request, except for one PUT operation in a certain class called Partner, which outputs all fields (readonly as well as not) in the request, same as the response.

I was able to easily recreate this issue in a new test project I created and noticed that removing the GET operation from this Partner class caused the PUT request to remove the readonly fields from the request and so behave how it should. I added the GET back in to check and the readonly fields were coming through in the request sample again.

Each time the request body in the middle area is correct and does not display the readonly fields, just the request samples on the right hand side.

The swagger.json that produces the incorrect request sample is as follows:
{ "swagger": "2.0", "info": { "description": "Provides endpoints", "version": "1.0", "title": "API" }, "host": "localhost:443", "basePath": "/v1", "tags": [{ "name": "Partner", "description": "Partner operations" }], "schemes": ["http", "https"], "consumes": ["application/json"], "produces": ["application/json"], "paths": { "/partner/{partner_id}": { "put": { "tags": ["Partner"], "summary": "Update Partner", "description": "Updates a partner as specified in the PUT payload", "operationId": "update", "consumes": ["application/json; charset=utf-8"], "produces": ["application/json; charset=utf-8"], "parameters": [{ "name": "partner_id", "in": "path", "description": "ID of partner to be updated", "required": true, "type": "integer", "format": "int32" }, { "in": "body", "name": "partner", "description": "PartnerFacade object that needs to be updated in the database", "required": true, "schema": { "$ref": "#/definitions/PartnerFacade" } }], "responses": { "200": { "description": "Partner updated", "schema": { "$ref": "#/definitions/PartnerFacade" } }, "400": { "description": "Invalid Partner object supplied" } }, "security": [{ "basicAuth": [] }] } } }, "definitions": { "PartnerFacade": { "type": "object", "properties": { "enabledFl": { "type": "boolean", "example": true, "default": false }, "logoUrl": { "type": "string", "example": "http://example.com/url-of-logo" }, "name": { "type": "string", "example": "Partner 1" }, "partnerId": { "type": "integer", "format": "int32", "example": 100, "readOnly": true }, "salesforceId": { "type": "string", "example": "123456", "readOnly": true } } } } }
partner correct

And the swagger.json that produces the correct request sample is as follows:
{ "swagger": "2.0", "info": { "description": "Provides endpoints", "version": "1.0", "title": "API" }, "host": "localhost:443", "basePath": "/v1", "tags": [{ "name": "Partner", "description": "Partner operations" }], "schemes": ["http", "https"], "consumes": ["application/json"], "produces": ["application/json"], "paths": { "/partner/{partner_id}": { "get": { "tags": ["Partner"], "summary": "Get Partner", "description": "Gets a partner with the given id", "operationId": "get", "produces": ["application/json; charset=utf-8"], "parameters": [{ "name": "partner_id", "in": "path", "description": "ID of partner that needs to be retrieved", "required": true, "type": "integer", "format": "int32" }], "responses": { "200": { "description": "Partner retrieved", "schema": { "$ref": "#/definitions/PartnerFacade" } }, "400": { "description": "Invalid partner ID supplied" } }, "security": [{ "basicAuth": [] }] }, "put": { "tags": ["Partner"], "summary": "Update Partner", "description": "Updates a partner as specified in the PUT payload", "operationId": "update", "consumes": ["application/json; charset=utf-8"], "produces": ["application/json; charset=utf-8"], "parameters": [{ "name": "partner_id", "in": "path", "description": "ID of partner to be updated", "required": true, "type": "integer", "format": "int32" }, { "in": "body", "name": "partner", "description": "PartnerFacade object that needs to be updated in the database", "required": true, "schema": { "$ref": "#/definitions/PartnerFacade" } }], "responses": { "200": { "description": "Partner updated", "schema": { "$ref": "#/definitions/PartnerFacade" } }, "400": { "description": "Invalid Partner object supplied" } }, "security": [{ "basicAuth": [] }] } } }, "definitions": { "PartnerFacade": { "type": "object", "properties": { "enabledFl": { "type": "boolean", "example": true, "default": false }, "logoUrl": { "type": "string", "example": "http://example.com/url-of-logo" }, "name": { "type": "string", "example": "Partner 1" }, "partnerId": { "type": "integer", "format": "int32", "example": 100, "readOnly": true }, "salesforceId": { "type": "string", "example": "123456", "readOnly": true } } } } }

partner incorrect

@RomanHotsiy
Copy link
Member

The issue you've reported has been fixed since ReDoc version v1.6.0.
I've just checked your sample on our demo page and it works as expected.

Please update to the latest version.

@lucychild
Copy link
Author

Thanks - I still had 1.5.2 in my project - will be updating it more regularly now

@RomanHotsiy
Copy link
Member

@lucychild I suggest you to wait for the next minor release which will be released in an hour.
The current has some critical issues :(

@lucychild
Copy link
Author

Will do - thanks!

@RomanHotsiy
Copy link
Member

v1.6.1 is available now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants