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

Example spec for swagger:response does not produce example output #3035

Open
jyturley opened this issue Dec 31, 2023 · 4 comments
Open

Example spec for swagger:response does not produce example output #3035

jyturley opened this issue Dec 31, 2023 · 4 comments
Labels
generate spec Related to spec generation from code @response scanner

Comments

@jyturley
Copy link

Problem statement

The docs on this page provide an example of how to produce a swagger response spec from annotations. However running swagger generate spec -o swagger.yaml does not produce the example output.

Swagger specification

I've copy pasted the example annotation in a test file in package main:

package main

// A ValidationError is an error that is used when the required input fails validation.
// swagger:response validationError
type ValidationError struct {
	// The error message
	// in: body
	Body struct {
		// The validation message
		//
		// Required: true
		// Example: Expected type int
		Message string
		// An optional field name to which this validation applies
		FieldName string
	}
}

Steps to reproduce

Output:

paths: {}
responses:
    validationError:
        description: A ValidationError is an error that is used when the required input fails validation.
swagger: "2.0"

What it should be:

---
responses:
  validationError:
    description: A ValidationError is an error that is used when the required input fails validation.
    schema:
      type: object
      description: The error message
      required:
      - Message
      properties:
        Message:
          type: string
          description: The validation message
          example: Expected type int
        FieldName:
          type: string
          description: an optional field name to which this validation applies

Notably, the schemas and the properties fields are missing. Am I calling this incorrectly here?

Environment

swagger version: v0.30.5
go version: 1.21.5 darwin/arm64
OS: macOS 12.6

@fredbi fredbi added scanner generate spec Related to spec generation from code labels Dec 31, 2023
@fredbi
Copy link
Contributor

fredbi commented Dec 31, 2023

Tested from current master.
go-swagger version: 59c3c59
go version go1.21.4 linux/amd64

using the above code as main.go and typing, from the same folder:

swagger generate spec -c .
{
  "swagger": "2.0",
  "paths": {},
  "responses": {
    "validationError": {
      "description": "A ValidationError is an error that is used when the required input fails validation.",
      "schema": {
        "type": "object",
        "required": [
          "Message"
        ],
        "properties": {
          "FieldName": {
            "description": "An optional field name to which this validation applies",
            "type": "string"
          },
          "Message": {
            "description": "The validation message",
            "type": "string",
            "example": "Expected type int"
          }
        }
      }
    }
  }
}

This looks pretty much like what was expected, right?

fredbi added a commit to fredbi/go-swagger that referenced this issue Dec 31, 2023
Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
fredbi added a commit to fredbi/go-swagger that referenced this issue Dec 31, 2023
Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
@jyturley
Copy link
Author

Yes this looks correct, glad to know I'm not going crazy. Although it seems I can checkout that commit in the repo, so I cant verify myself on my machine

fredbi added a commit to fredbi/go-swagger that referenced this issue Jan 2, 2024
Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
fredbi added a commit to fredbi/go-swagger that referenced this issue Jan 4, 2024
Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
fredbi added a commit to fredbi/go-swagger that referenced this issue Jan 4, 2024
Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
fredbi added a commit to fredbi/go-swagger that referenced this issue Jan 4, 2024
Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
fredbi added a commit to fredbi/go-swagger that referenced this issue Jan 7, 2024
Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
fredbi added a commit to fredbi/go-swagger that referenced this issue Jan 7, 2024
Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
fredbi added a commit to fredbi/go-swagger that referenced this issue Jan 7, 2024
Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
@kvizdos
Copy link

kvizdos commented Feb 10, 2024

I am facing the same issue. Opened another issue yesterday, but I've since closed it to align with this.

Edit: tested go 1.22 and 1.21.5 on Darwin. Used both static build files of Swagger and homebrew installs.

@AbhinavArora95
Copy link

Faced the same issue. The referenced models within the the swagger:response struct are not generating for the following go versions

  • go1.22.0 darwin/arm64
  • go1.22.1 darwin/arm64

But everything else the same, correct expected docs are generating for:

  • go1.21.4 darwin/arm64

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
generate spec Related to spec generation from code @response scanner
Projects
None yet
Development

No branches or pull requests

4 participants