Skip to content

Commit cc301f8

Browse files
committed
Allow adding a custom server to validate against
1 parent a1ffbf2 commit cc301f8

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
55
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
66

77
## [Unreleased]
8+
- Add `--add-server` to add a custom server when using `--validate-server`.
9+
This allows quickly adding a custom domain or base path that will properly
10+
validate.
811
- Add `--header` (short `-H`) option to specify a custom header when fetching
912
the API document. This allows you to pass custom auth info.
1013
- Add `readOnly` and `writeOnly` support to the example generator.

apisprout.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ func main() {
114114
addParameter(flags, "watch", "w", false, "Reload when input file changes")
115115
addParameter(flags, "disable-cors", "", false, "Disable CORS headers")
116116
addParameter(flags, "header", "H", "", "Add a custom header when fetching API")
117+
addParameter(flags, "add-server", "", "", "Add a new valid server URL, use with --validate-server")
117118

118119
// Run the app!
119120
root.Execute()
@@ -292,6 +293,14 @@ func load(uri string, data []byte) (swagger *openapi3.Swagger, router *openapi3f
292293
if err = addLocalServers(swagger); err != nil {
293294
return
294295
}
296+
297+
if cs := viper.GetString("add-server"); cs != "" {
298+
swagger.Servers = append(swagger.Servers, &openapi3.Server{
299+
URL: cs,
300+
Description: "Custom server from command line param",
301+
Variables: make(map[string]*openapi3.ServerVariable),
302+
})
303+
}
295304
}
296305

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

0 commit comments

Comments
 (0)