-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Closed
Description
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
- Write Go code
- Generate spec:
swagger generate spec -o ./open_api/base.yaml
- See the spec result
Also there's no error on my spec generation:
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
Labels
No labels