Skip to content

Commit

Permalink
[ux] warn on default requestBody name, tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lispyclouds committed Dec 21, 2024
1 parent 4125a41 commit d9609cb
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 15 deletions.
2 changes: 1 addition & 1 deletion api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ paths:
- ap

requestBody:
description: The numebers map
description: The numbers map
required: true
x-cli-name: nmap
content:
Expand Down
8 changes: 7 additions & 1 deletion lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,12 @@ func addRequestBody(cmd *cobra.Command, op *v3.Operation, handlerData *HandlerDa
paramName := "climate-data"
if altName := bExts.name; altName != "" {
paramName = altName
} else {
slog.Warn(
fmt.Sprintf("No name set of requestBody, defaulting to %s", paramName),
"id",
op.OperationId,
)
}

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

handler, ok := handlers[op.OperationId]
if !ok {
slog.Warn("Ho handler defined, skipping", "id", op.OperationId)
slog.Warn("No handler defined, skipping", "id", op.OperationId)
continue
}

Expand Down
18 changes: 5 additions & 13 deletions lib_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ import (

func TestLoadFileV3(t *testing.T) {
_, err := LoadFileV3("api.yaml")
if err != nil {
t.Fatalf("LoadFileV3 failed with: %e", err)
}
assert.NoError(t, err)
}

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

expected, ok := assertConf[prefix]
if !ok {
t.Fatalf("Invalid prefix found: %s", prefix)
}
assert.Truef(t, ok, "Invalid prefix found: %s", prefix)

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

assert.NoError(t, err, fmt.Sprintf("Flag: %s Type: %s", name, typ))
assert.NoErrorf(t, err, "Flag: %s Type: %s", name, typ)
}
}

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

func TestBootstrapV3(t *testing.T) {
model, err := LoadFileV3("api.yaml")
if err != nil {
t.Fatalf("LoadFileV3 failed with: %e", err)
}
assert.NoError(t, err)

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

err = BootstrapV3(rootCmd, *model, handlers)
if err != nil {
t.Fatalf("BootstrapV3 failed with: %e", err)
}
assert.NoError(t, err)

var noAlias []string
assertConf := map[string]map[string]any{
Expand Down

0 comments on commit d9609cb

Please sign in to comment.