We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Even the simplest server I could come up with fails on swagger UI with TypeError: Failed to fetch
TypeError: Failed to fetch
{ "consumes": [ "application/json" ], "produces": [ "application/json" ], "schemes": [ "http", "https" ], "swagger": "2.0", "info": { "description": "Title: example", "title": "is an example REST app", "version": "0.0.1" }, "host": "localhost:3000", "basePath": "/v1", "paths": { "/foo": { "get": { "description": "Get a foo", "operationId": "getFoo", "responses": { "200": { "$ref": "#/responses/getFooResponse" } } } } }, "responses": { "getFooResponse": { "description": "GetFooResponse is returned by GET /foo", "schema": { "type": "object", "properties": { "Name": { "description": "Name of the foo", "type": "string" } } } } }, "securityDefinitions": { "bearer": { "type": "apiKey", "name": "Authorization", "in": "header" } }, "security": [ { "bearer": [] } ] }
main.go:
main.go
// Package main is an example REST app // // Title: example // Schemes: http, https // Host: localhost:3000 // BasePath: /v1 // Version: 0.0.1 // // Consumes: // - application/json // // Produces: // - application/json // // Security: // - bearer: // // SecurityDefinitions: // bearer: // type: apiKey // name: Authorization // in: header // swagger:meta package main import ( "encoding/json" "log" "net/http" "time" ) func main() { s := &http.Server{ Addr: ":3000", Handler: &myHandler{}, ReadTimeout: 10 * time.Second, WriteTimeout: 10 * time.Second, MaxHeaderBytes: 1 << 20, } log.Fatal(s.ListenAndServe()) } type myHandler struct{} // GetFoo handles a GET to /foo // // swagger:route GET /foo getFoo // // Get a foo // // Responses: // 200: getFooResponse func (myHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { log.Printf("Got request %+v", r) defer r.Body.Close() var resp GetFooResponse resp.Body.Name = "foo" jsonBody, err := json.Marshal(&resp.Body) if err != nil { http.Error(w, "failed to marshal", 500) return } w.Write(jsonBody) } // GetFooArgs are the parameters to GET /foo // // swagger:parameters getFoo type GetFooArgs struct { } // GetFooResponse is returned by GET /foo // // swagger:response getFooResponse type GetFooResponse struct { // in:body Body struct { // Name of the foo Name string } }
go build && swagger generate spec -o swagger.json ./example & swagger serve swagger.json -F swagger
Through the swagger UI, try to make a GET request to /foo. It will fail.
GET
/foo
swagger version: dev go version: go1.8.3 OS: linux/amd64
The text was updated successfully, but these errors were encountered:
your server needs to add a cors middleware, that's the cause of the failure. #481
Sorry, something went wrong.
No branches or pull requests
Problem statement
Even the simplest server I could come up with fails on swagger UI with
TypeError: Failed to fetch
Swagger specification
Steps to reproduce
main.go
:Through the swagger UI, try to make a
GET
request to/foo
. It will fail.Environment
swagger version: dev
go version: go1.8.3
OS: linux/amd64
The text was updated successfully, but these errors were encountered: