Skip to content

Commit d725351

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

File tree

2 files changed

+11
-13
lines changed

2 files changed

+11
-13
lines changed

lib.go

Lines changed: 6 additions & 0 deletions
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

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)