Skip to content

Commit

Permalink
Allow adding a custom server to validate against
Browse files Browse the repository at this point in the history
  • Loading branch information
danielgtaylor committed Mar 19, 2019
1 parent a1ffbf2 commit cc301f8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Expand Up @@ -5,6 +5,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [Unreleased]
- Add `--add-server` to add a custom server when using `--validate-server`.
This allows quickly adding a custom domain or base path that will properly
validate.
- Add `--header` (short `-H`) option to specify a custom header when fetching
the API document. This allows you to pass custom auth info.
- Add `readOnly` and `writeOnly` support to the example generator.
Expand Down
9 changes: 9 additions & 0 deletions apisprout.go
Expand Up @@ -114,6 +114,7 @@ func main() {
addParameter(flags, "watch", "w", false, "Reload when input file changes")
addParameter(flags, "disable-cors", "", false, "Disable CORS headers")
addParameter(flags, "header", "H", "", "Add a custom header when fetching API")
addParameter(flags, "add-server", "", "", "Add a new valid server URL, use with --validate-server")

// Run the app!
root.Execute()
Expand Down Expand Up @@ -292,6 +293,14 @@ func load(uri string, data []byte) (swagger *openapi3.Swagger, router *openapi3f
if err = addLocalServers(swagger); err != nil {
return
}

if cs := viper.GetString("add-server"); cs != "" {
swagger.Servers = append(swagger.Servers, &openapi3.Server{
URL: cs,
Description: "Custom server from command line param",
Variables: make(map[string]*openapi3.ServerVariable),
})
}
}

// Create a new router using the OpenAPI document's declared paths.
Expand Down

0 comments on commit cc301f8

Please sign in to comment.