Skip to content

Commit a1ffbf2

Browse files
committed
More robust header parsing, update changelog
1 parent f20c066 commit a1ffbf2

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ 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 `--header` (short `-H`) option to specify a custom header when fetching
9+
the API document. This allows you to pass custom auth info.
810
- Add `readOnly` and `writeOnly` support to the example generator.
911
- Revamped support for `--validate-server` (short `-s`)
1012
- Requires the use of server base path(s) on the client.

apisprout.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ func main() {
102102
Version: GitSummary,
103103
Args: cobra.MinimumNArgs(1),
104104
Run: server,
105-
Example: fmt.Sprintf(" %s openapi.yaml", cmd),
105+
Example: fmt.Sprintf(" # Basic usage\n %s openapi.yaml\n\n # Validate server name and use base path\n %s --validate-server openapi.yaml\n\n # Fetch API via HTTP with custom auth header\n %s -H 'Authorization: abc123' http://example.com/openapi.yaml", cmd, cmd, cmd),
106106
}
107107

108108
// Set up global options.
@@ -113,7 +113,7 @@ func main() {
113113
addParameter(flags, "validate-request", "", false, "Check request data structure")
114114
addParameter(flags, "watch", "w", false, "Reload when input file changes")
115115
addParameter(flags, "disable-cors", "", false, "Disable CORS headers")
116-
addParameter(flags, "header", "H", "", "Add custom header")
116+
addParameter(flags, "header", "H", "", "Add a custom header when fetching API")
117117

118118
// Run the app!
119119
root.Execute()
@@ -319,11 +319,11 @@ func server(cmd *cobra.Command, args []string) {
319319
log.Fatal(err)
320320
}
321321
if customHeader := viper.GetString("header"); customHeader != "" {
322-
header := strings.Split(customHeader, ": ")
322+
header := strings.Split(customHeader, ":")
323323
if len(header) != 2 {
324324
log.Fatal("Header format is invalid.")
325325
}
326-
req.Header.Add(header[0], header[1])
326+
req.Header.Add(strings.TrimSpace(header[0]), strings.TrimSpace(header[1]))
327327
}
328328
client := &http.Client{}
329329
resp, err := client.Do(req)

0 commit comments

Comments
 (0)