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 can i generate spec with a simple string response #2942

Open
hunjixin opened this issue May 11, 2023 · 3 comments
Open

how can i generate spec with a simple string response #2942

hunjixin opened this issue May 11, 2023 · 3 comments
Labels
generate spec Related to spec generation from code @response scanner

Comments

@hunjixin
Copy link

hunjixin commented May 11, 2023

Problem statement

when api success, just response with a string value, but swagger simple cannt identy a simple string

Swagger specification

// swagger:route GET /version getVersion
//
// get backend version
//
//     Consumes:
//
//     Produces:
//     - application/text
//
//     Schemes: http, https
//
//     Deprecated: false
//
//     Responses:
//       200: string

and got spec like

   "responses": {
          "200": {
            "$ref": "#/responses/string"
          }
        }

Environment

swagger version: master
go version: go1.19.8
OS: mac

@casualjim
Copy link
Member

By default it wants you to specify headers and body. But you can prefix the response type with body: and then it will do the right thing

// swagger:route GET /version getVersion
//
// get backend version
//
//     Consumes:
//
//     Produces:
//     - application/text
//
//     Schemes: http, https
//
//     Deprecated: false
//
//     Responses:
//       200: body:string

@hunjixin
Copy link
Author

@casualjim thanks, but where can i find docs about this?

@hunjixin
Copy link
Author

@casualjim not work

        "responses": {
          "200": {
            "description": "string",
            "schema": {
              "$ref": "#/definitions/string"
            }
          }
        }

when use this spec to generate client, got error

unsupported type "invalid type"

@hunjixin hunjixin changed the title how can i generate spec with a simple string how can i generate spec with a simple string response Jun 12, 2023
@fredbi fredbi added scanner generate spec Related to spec generation from code labels Dec 20, 2023
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

3 participants