Skip to content

Response schema is not generated #2902

@zainafifaldi

Description

@zainafifaldi

Problem statement

Hi Team, I'm asking here since I couldn't find any solutions on the internet. Apologize if I missed some reference.

I followed the documentation here. Everything looks good and my spec file is generated well, except in the responses field.
I have no idea why, but the response schema couldn't be generated even though with some kind of experiments.

Swagger specification

Here is my Go code:

// Dummy API:
//
//	version: 1.0.0
//	title: Dummy API
//
// BasePath: /dummy/api
//
// Produces:
// - application/json
//
// Consumes:
// - application/json
//
// Security:
// - apiKey
//
// SecurityDefinitions
//
//	apiKey:
//	  type: apiKey
//	  in: header
//	  name: x-api-key
//
// swagger:meta
//
//go:generate swagger generate spec
package api

// ServeAPI serves the API for this record store
func ServeAPI(host, basePath string, schemes []string) error {

	// swagger:route GET /pets pets users listPets
	//
	// Lists pets filtered by some parameters.
	//
	// This will show all available pets by default.
	// You can get the pets that are out of stock
	//
	//     Consumes:
	//     - application/json
	//     - application/x-protobuf
	//
	//     Produces:
	//     - application/json
	//     - application/x-protobuf
	//
	//     Schemes: http, https, ws, wss
	//
	//     Deprecated: true
	//
	//     Security:
	//       apiKey:
	//
	//     Parameters:
	//       + name: limit
	//         in: query
	//         description: maximum numnber of results to return
	//         required: false
	//         type: integer
	//         format: int32
	//
	//     Responses:
	//       422: validationError
	return nil
}

// 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
	}
}

And here is the spec file I got (no reference for response validationError):

basePath: /dummy/api
consumes:
    - application/json
info:
    title: 'Dummy API:'
    version: 1.0.0
paths:
    /pets:
        get:
            consumes:
                - application/json
                - application/x-protobuf
            deprecated: true
            description: |-
                This will show all available pets by default.
                You can get the pets that are out of stock
            operationId: listPets
            parameters:
                - description: maximum numnber of results to return
                  format: int32
                  in: query
                  name: limit
                  type: integer
            produces:
                - application/json
                - application/x-protobuf
            responses:
                "422":
                    $ref: '#/responses/validationError'
            schemes:
                - http
                - https
                - ws
                - wss
            security:
                - api_key: []
            summary: Lists pets filtered by some parameters.
            tags:
                - pets
                - users
produces:
    - application/json
security:
    - apiKey: []
    - type:
        - apiKey
    - in:
        - header
    - name:
        - x-api-key
swagger: "2.0"

Notice that there's no responses generated.

Steps to reproduce

  1. Write Go code
  2. Generate spec:
    swagger generate spec -o ./open_api/base.yaml
  3. See the spec result

Also there's no error on my spec generation:
Screenshot 2023-02-10 at 19 01 02

Environment

swagger version: v0.30.3
go version: go1.19.4
OS: Ventura 13.0.1

Update:
go version in go.mod file: 1.16

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions