Skip to content

Commit d9609cb

Browse files
committed
[ux] warn on default requestBody name, tests
1 parent 4125a41 commit d9609cb

File tree

3 files changed

+13
-15
lines changed

3 files changed

+13
-15
lines changed

api.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ paths:
3737
- ap
3838

3939
requestBody:
40-
description: The numebers map
40+
description: The numbers map
4141
required: true
4242
x-cli-name: nmap
4343
content:

lib.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,12 @@ func addRequestBody(cmd *cobra.Command, op *v3.Operation, handlerData *HandlerDa
149149
paramName := "climate-data"
150150
if altName := bExts.name; altName != "" {
151151
paramName = altName
152+
} else {
153+
slog.Warn(
154+
fmt.Sprintf("No name set of requestBody, defaulting to %s", paramName),
155+
"id",
156+
op.OperationId,
157+
)
152158
}
153159

154160
// TODO: Handle all the different MIME types and schemas from body.Content
@@ -244,7 +250,7 @@ func BootstrapV3(rootCmd *cobra.Command, model libopenapi.DocumentModel[v3.Docum
244250

245251
handler, ok := handlers[op.OperationId]
246252
if !ok {
247-
slog.Warn("Ho handler defined, skipping", "id", op.OperationId)
253+
slog.Warn("No handler defined, skipping", "id", op.OperationId)
248254
continue
249255
}
250256

lib_test.go

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ import (
1010

1111
func TestLoadFileV3(t *testing.T) {
1212
_, err := LoadFileV3("api.yaml")
13-
if err != nil {
14-
t.Fatalf("LoadFileV3 failed with: %e", err)
15-
}
13+
assert.NoError(t, err)
1614
}
1715

1816
func TestInterpolatePath(t *testing.T) {
@@ -43,9 +41,7 @@ func assertCmdTree(t *testing.T, cmd *cobra.Command, assertConf map[string]map[s
4341
fmt.Println("Checking cmd level " + prefix)
4442

4543
expected, ok := assertConf[prefix]
46-
if !ok {
47-
t.Fatalf("Invalid prefix found: %s", prefix)
48-
}
44+
assert.Truef(t, ok, "Invalid prefix found: %s", prefix)
4945

5046
assert.Equal(t, expected["Use"], cmd.Use)
5147
assert.Equal(t, expected["Short"], cmd.Short)
@@ -68,7 +64,7 @@ func assertCmdTree(t *testing.T, cmd *cobra.Command, assertConf map[string]map[s
6864
_, err = cmd.Flags().GetBool(name)
6965
}
7066

71-
assert.NoError(t, err, fmt.Sprintf("Flag: %s Type: %s", name, typ))
67+
assert.NoErrorf(t, err, "Flag: %s Type: %s", name, typ)
7268
}
7369
}
7470

@@ -79,9 +75,7 @@ func assertCmdTree(t *testing.T, cmd *cobra.Command, assertConf map[string]map[s
7975

8076
func TestBootstrapV3(t *testing.T) {
8177
model, err := LoadFileV3("api.yaml")
82-
if err != nil {
83-
t.Fatalf("LoadFileV3 failed with: %e", err)
84-
}
78+
assert.NoError(t, err)
8579

8680
handler := func(opts *cobra.Command, args []string, data HandlerData) {
8781
assert.Equal(t, data.PathParams, []ParamMeta{{Name: "p1", Type: Integer}})
@@ -103,9 +97,7 @@ func TestBootstrapV3(t *testing.T) {
10397
}
10498

10599
err = BootstrapV3(rootCmd, *model, handlers)
106-
if err != nil {
107-
t.Fatalf("BootstrapV3 failed with: %e", err)
108-
}
100+
assert.NoError(t, err)
109101

110102
var noAlias []string
111103
assertConf := map[string]map[string]any{

0 commit comments

Comments
 (0)