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

Parameters in swagger:route produce validation warnings #1785

Closed
3 tasks
mhr3 opened this issue Nov 5, 2018 · 6 comments
Closed
3 tasks

Parameters in swagger:route produce validation warnings #1785

mhr3 opened this issue Nov 5, 2018 · 6 comments

Comments

@mhr3
Copy link

mhr3 commented Nov 5, 2018

Problem statement

When generating a spec from source, specifying parameter types in swagger:route can produce warnings during validation.

Steps to reproduce

	/* swagger:route PUT /pet/{id} pets users updatePet
	Update a pet based on the parameters.
	Parameters:
	+ name:        id
	  description: The pet id
	  in:          path
	  type:  string
	  required:    true
	+ name:        request
	  description: The request model.
	  in:          body
	  type:        petModel
	Responses:
	200: body:someResponse
	422: body:validationError
 */

The above definition produces:

        ...
        "parameters": [
          {
            "type": "string",
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "type": "object",
            "name": "request",
            "in": "body",
            "required": true,
            "schema": {
              "type": "object",
              "$ref": "#/definitions/petModel"
            }
          }

Few issues in the generated spec:

  • the type: object is invalid outside of the schema object
  • the schema: { type: string } is invalid
  • IMO path parameters should default to type: string automatically (afterall type is required there)

Environment

swagger version: 0.17.2
go version: 1.11
OS: linux

@casualjim
Copy link
Member

the syntax in the doc comments is wrong.
https://goswagger.io/use/spec/route.html

@mhr3
Copy link
Author

mhr3 commented Nov 5, 2018

The docs don't even mention a way to do this, I went by the tests, still, that's a separate issue, no?

@casualjim
Copy link
Member

You link parameters through parameter structs, not by defining them in the location where you did.

If you want to define things like this, there is swagger:operation which allows you to put the yaml for the operation instead

@mhr3
Copy link
Author

mhr3 commented Nov 5, 2018

I'm aware of swagger:parameters, but I found it difficult to deal with the disconnect between routes and their params, this way to define them in swagger:route was more natural. Any plans to keep this direction of defining it as well? IMO being able to link a route to the param structs would make things nicer to use, ie:

// swagger:param
type PetIDParam struct {
  // in: path
  ID string
}

...
swagger:route GET /pets/{id} getPet
Parameters: PetIDParam

Basically similar to how responses are defined (though params should accept n definitions, not just one)

@casualjim
Copy link
Member

you can use swagger:operation for that

https://goswagger.io/use/spec/operation.html

@mhr3
Copy link
Author

mhr3 commented Nov 5, 2018

Right, but that uses raw yaml, I'd rather have stronger consistency guarantees.

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

No branches or pull requests

2 participants