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

How to set a example value for array/string response type? #3013

Open
839735495 opened this issue Dec 22, 2023 · 2 comments
Open

How to set a example value for array/string response type? #3013

839735495 opened this issue Dec 22, 2023 · 2 comments
Labels
generate spec Related to spec generation from code question @response scanner

Comments

@839735495
Copy link

839735495 commented Dec 22, 2023

Problem statement

I have an API which response type is a string array. Does anyone know how to set example value for it? I tried this but not work:

// Ntp servers
// swagger:response getNtpServersResponse
// Example: ["10.10.10.10", "20.20.20.20"]
type _ []string

// swagger:route GET /ntp-servers
// Responses:
//   200: getNtpServersResponse
//   500: Error
func GetNtpServersHandler() {}

Swagger specification

Without any example:

"getNtpServersResponse": {
    "description": "Ntp servers",
    "content": {
        "*/*": {
            "schema": {
                "type": "array",
                "items": {
                    "type": "string"
                }
            }
        }
    }
},

Environment

swagger version: v0.27.0
go version: go1.19.10
OS: RHEL 8.8

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

fredbi commented Dec 22, 2023

Here is an example:

@839735495
Copy link
Author

839735495 commented Dec 25, 2023

Hi @fredbi,
I tried to use swagger:operation to achieve this instead of swagger:route+ swagger:response just like below, which follow the example share by you:

// GetNtpServersHandler
// swagger:operation GET /ntp-servers
// Retrieves the NTP servers
// ---
// responses:
//   '200':
//     description: NTP servers
//     schema:
//       type: array
//       items:
//         type: string
//       example: ["10.10.10.10", "20.20.20.20"]

However, I'd like to know that if there are anyway to set example value to simple "string" or "array" using swagger:response?

// Ntp servers
// swagger:response getNtpServersResponse
type _ []string

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 question @response scanner
Projects
None yet
Development

No branches or pull requests

2 participants