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

API fails swagger validation #4010

Closed
stevegt opened this issue May 21, 2018 · 9 comments · Fixed by #4220 or #4236
Closed

API fails swagger validation #4010

stevegt opened this issue May 21, 2018 · 9 comments · Fixed by #4220 or #4236
Labels
type/bug type/docs This PR mainly updates/creates documentation
Milestone

Comments

@stevegt
Copy link
Contributor

stevegt commented May 21, 2018

Either I'm doing something wrong or the API (as of d94472e) is not currently emitting swagger-compliant JSON. This is causing problems when trying to use various parsers and client generators/libraries to create gitea clients, as they try to validate when parsing. The error messages I'm getting vary by library, but as a simple check, try this:

$ curl https://try.gitea.io/swagger.v1.json > swagger.v1.json 
$ npm install -g swagger-cli
$ swagger-cli validate swagger.v1.json 
Swagger schema validation failed. 
  Missing required property: description at #/responses/parameterBodies
 
JSON_OBJECT_VALIDATION_FAILED

I've tried other parsers and validators, both CLI and online, and get different errors; still trying to figure out if there's any common denominator other than PEBCAK. Anyone else seeing this?

@lafriks lafriks added type/docs This PR mainly updates/creates documentation type/bug labels May 21, 2018
@stevegt
Copy link
Contributor Author

stevegt commented May 22, 2018

I'm sure many here already know this, but I finally realized that we're also getting a validation error at the bottom of https://try.gitea.io/api/swagger. If you click on the little red "Error" badge at the bottom of the page, you get a set of errors from swagger.io's own validator:

https://online.swagger.io/validator/debug?url=https://try.gitea.io/swagger.v1.json

@sapk
Copy link
Member

sapk commented May 23, 2018

Yes, this is mostly some description missing and few corner case like /markdown/raw.

This could maybe easely fix by updating comments that are used to generate the json with https://github.com/go-swagger/go-swagger

@stevegt
Copy link
Contributor Author

stevegt commented May 26, 2018

Starting work on these. For future reference, a quick way to get an easy-to-read list of errors from the swagger.io online validator is:

curl -X POST -d @public/swagger.v1.json -H 'Content-Type:application/json' http://online.swagger.io/validator/debug | json2yaml

@stevegt
Copy link
Contributor Author

stevegt commented May 28, 2018

So far it appears that at least some of these are more than just missing/wrong comments -- unless I'm misunderstanding something, the /responses/* errors are related to missing code. It's been a couple of days since I had a chance to look, but iirc those comments need to point at code that I couldn't find and may not exist yet. It could be that just adding a description field will make the validator happy, but I haven't had a chance to try that yet.

@sapk
Copy link
Member

sapk commented May 28, 2018

Some comments especially responses are under https://github.com/go-gitea/go-sdk that is under vendor/ in gitea repo.

stevegt added a commit to stevegt/gitea that referenced this issue May 30, 2018
* Partial fix for go-gitea#4010

Swagger needs a comment line above each swagger:response comment -- it
uses these to populate the description: fields.  Adding minimal text
for now on the way to getting swagger validate to pass.  Many standard
swagger client libraries will not work at all with gitea until validate
passes, so prioritizing that over better descriptions for now.

Signed-off-by: Steve Traugott <stevegt@t7a.org>
@stevegt
Copy link
Contributor Author

stevegt commented May 30, 2018

This local command provides a more comprehensive error list than the swagger.io online validator command I mention above, and the output is equally easy to read:

swagger validate public/swagger.v1.json

stevegt added a commit to stevegt/gitea that referenced this issue May 30, 2018
* Partial fix for go-gitea#4010

Swagger needs a description field in each swagger:operation response.  Adding
minimal text for now on the way to getting swagger validate to pass.  Many
standard swagger client libraries will not work with gitea until validate
passes, so prioritizing that over better descriptions for now.

Signed-off-by: Steve Traugott <stevegt@t7a.org>
lunny pushed a commit that referenced this issue May 31, 2018
* Partial fix for #4010

Swagger needs a comment line above each swagger:response comment -- it
uses these to populate the description: fields.  Adding minimal text
for now on the way to getting swagger validate to pass.  Many standard
swagger client libraries will not work at all with gitea until validate
passes, so prioritizing that over better descriptions for now.

Signed-off-by: Steve Traugott <stevegt@t7a.org>
lunny pushed a commit that referenced this issue Jun 1, 2018
* Partial fix for #4010

Swagger needs a description field in each swagger:operation response.  Adding
minimal text for now on the way to getting swagger validate to pass.  Many
standard swagger client libraries will not work with gitea until validate
passes, so prioritizing that over better descriptions for now.

Signed-off-by: Steve Traugott <stevegt@t7a.org>
stevegt added a commit to stevegt/gitea that referenced this issue Jun 1, 2018
* Partial fix for go-gitea#4010

Swagger validation needs 'required: true' for parameters that are in
the URL path.

Signed-off-by: Steve Traugott <stevegt@t7a.org>
lafriks pushed a commit that referenced this issue Jun 2, 2018
* Partial fix for #4010

Swagger validation needs 'required: true' for parameters that are in
the URL path.

Signed-off-by: Steve Traugott <stevegt@t7a.org>
appleboy pushed a commit that referenced this issue Jun 12, 2018
Fix all the resting errors to have a valid swagger file.

They are still some warnings but nothing blocking.

Doing so I found that some request still misses son parameters for some POST/PUT/PATCH request. This means the a client generated from the swagger file will not work completely. 

Fix #4088 by activating validation in drone
Should fix #4010.
@MikeRalphson
Copy link

Thanks for the fixes - the definition still contains some errors:

  "security": [
    {
      "BasicAuth": [
        "[]"
      ]
    },
    {
      "Token": [
        "[]"
      ]
    },
    {
      "AccessToken": [
        "[]"
      ]
    },
    {
      "AuthorizationHeaderToken": [
        "[]"
      ]
    }
  ]

The scopes arrays themselves should be empty, they should not contain strings with the value [].

@sapk
Copy link
Member

sapk commented Jun 12, 2018

@MikeRalphson this should be fixed in #4236
It was not catched by the validator that we used.

@MikeRalphson
Copy link

@sapk The fix in #4236 LGTM. Thanks.

@lunny lunny added this to the 1.5.0 milestone Jun 13, 2018
stevegt added a commit to stevegt/gitea that referenced this issue Jun 13, 2018
lunny pushed a commit that referenced this issue Jun 15, 2018
* fixes a warning remaining from #4010 and #4220
@go-gitea go-gitea locked and limited conversation to collaborators Nov 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type/bug type/docs This PR mainly updates/creates documentation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants