Skip to content

Commit 062646c

Browse files
Merge pull request #27 from danielgtaylor/autoconfig-exclude
feat: ability to exclude autoconfig prompt vars
2 parents a60171e + 08b98cb commit 062646c

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

cli/autoconfig.go

+4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ type AutoConfigVar struct {
77
Example string `json:"example,omitempty"`
88
Default interface{} `json:"default,omitempty"`
99
Enum []interface{} `json:"enum,omitempty"`
10+
11+
// Exclude the value from being sent to the server. This essentially makes
12+
// it a value which is only used in param templates.
13+
Exclude bool `json:"exclude,omitempty"`
1014
}
1115

1216
// AutoConfig holds an API's automatic configuration settings for the CLI. These

cli/interactive.go

+14-3
Original file line numberDiff line numberDiff line change
@@ -95,21 +95,32 @@ func askLoadBaseAPI(a asker, config *APIConfig) {
9595
def = fmt.Sprintf("%v", v.Default)
9696
}
9797

98+
// If a description is present, prefer to display it over the variable
99+
// name used a server arguments or in templates, since you don't
100+
// always have control over that value.
101+
promptText := name
102+
if v.Description != "" {
103+
promptText = v.Description
104+
}
105+
98106
if len(v.Enum) > 0 {
99107
enumStr := []string{}
100108
for val := range v.Enum {
101109
enumStr = append(enumStr, fmt.Sprintf("%v", val))
102110
}
103-
responses[name] = a.askSelect(name, enumStr, def, v.Description)
111+
responses[name] = a.askSelect(promptText, enumStr, def, "")
104112
} else {
105-
responses[name] = a.askInput(name, def, v.Default == nil, v.Description)
113+
responses[name] = a.askInput(promptText, def, v.Default == nil, "")
106114
}
107115
}
108116

109117
// Generate params from user inputs.
110118
params := map[string]string{}
111119
for name, resp := range responses {
112-
params[name] = resp
120+
// Only include the param if the variable wasn't excluded.
121+
if !ac.Prompt[name].Exclude {
122+
params[name] = resp
123+
}
113124
}
114125

115126
for name, template := range ac.Auth.Params {

docs/openapi.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -88,20 +88,21 @@ Valid types for the security setting when not using a security scheme defined wi
8888
| `oauth-client-credentials` | OAuth2 pre-shared client key/secret (m2m) |
8989
| `oauth-authorization-code` | OAuth2 authorization code (user login) |
9090

91-
By default, all prompt variables become auth parameters of the same name. Additionally, a template system can be used to augment the value or create new params. Any value within `{...}` will get replaced by the value of the param with the given name. For example:
91+
By default, all prompt variables become auth parameters of the same name. This can be disabled by setting `exclude` to `true` if desired. Additionally, a template system can be used to augment the value or create new params. Any value within `{...}` will get replaced by the value of the param with the given name. For example:
9292

9393
```yaml
9494
x-cli-config:
9595
prompt:
9696
org:
9797
description: Organization ID
9898
example: github
99+
exclude: true
99100
params:
100101
audience: https://example.com/{org}
101102
some_static_value: foo
102103
```
103104

104-
The above will prompt the user for an `org` and then fill in the params using the value from the user when creating the API configuration profile.
105+
The above will prompt the user for an `org` and then fill in the params using the value from the user when creating the API configuration profile. Since `exclude` is set, the `org` parameter is never sent to the server and is only used to fill in the param template for `audience`.
105106

106107
#### Auth Parameters
107108

0 commit comments

Comments
 (0)