Skip to content

Commit 0d48b75

Browse files
authored
Merge pull request go-swagger#2359 from go-swagger/swagger-ui
adds swaggerui middleware as default /docs site
2 parents a46478c + cd0c25b commit 0d48b75

File tree

36 files changed

+534
-250
lines changed

36 files changed

+534
-250
lines changed

cmd/swagger/commands/serve.go

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"log"
88
"net"
99
"net/http"
10-
"net/url"
1110
"path"
1211
"strconv"
1312

@@ -87,17 +86,12 @@ func (s *ServeCmd) Execute(args []string) error {
8786
}, handler)
8887
visit = fmt.Sprintf("http://%s:%d%s", sh, sp, path.Join(basePath, "docs"))
8988
} else if visit != "" || s.Flavor == "swagger" {
90-
if visit == "" {
91-
visit = "http://petstore.swagger.io/"
92-
}
93-
u, err := url.Parse(visit)
94-
if err != nil {
95-
return err
96-
}
97-
q := u.Query()
98-
q.Add("url", fmt.Sprintf("http://%s:%d%s", sh, sp, path.Join(basePath, "swagger.json")))
99-
u.RawQuery = q.Encode()
100-
visit = u.String()
89+
handler = middleware.SwaggerUI(middleware.SwaggerUIOpts{
90+
BasePath: basePath,
91+
SpecURL: path.Join(basePath, "swagger.json"),
92+
Path: "docs",
93+
}, handler)
94+
visit = fmt.Sprintf("http://%s:%d%s", sh, sp, path.Join(basePath, "docs"))
10195
}
10296
}
10397

examples/authentication/restapi/configure_auth_sample.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ func configureAPI(api *operations.AuthSampleAPI) http.Handler {
3131
// Example:
3232
// api.Logger = log.Printf
3333

34+
api.UseSwaggerUI()
35+
// To continue using redoc as your UI, uncomment the following line
36+
// api.UseRedoc()
37+
3438
api.JSONConsumer = runtime.JSONConsumer()
3539

3640
api.JSONProducer = runtime.JSONProducer()

examples/authentication/restapi/operations/auth_sample_api.go

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/composed-auth/restapi/operations/multi_auth_example_api.go

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/contributed-templates/stratoscale/client/pet/pet_create_responses.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/contributed-templates/stratoscale/client/pet/pet_delete_responses.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/contributed-templates/stratoscale/client/pet/pet_get_responses.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/contributed-templates/stratoscale/client/pet/pet_list_responses.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/contributed-templates/stratoscale/client/pet/pet_update_responses.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/contributed-templates/stratoscale/client/pet/pet_upload_image_responses.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)