Skip to content

Commit

Permalink
[params] handle non existent schemas, all req bodies as strings
Browse files Browse the repository at this point in the history
  • Loading branch information
lispyclouds committed Dec 15, 2024
1 parent d8910c2 commit 9aca3ea
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Experimental, in dev flux and looking for design/usage feedback!
- Interpolate the HTTP paths when sending to the handler with the path params
- Support more of the OpenAPI types and their checks. eg arrays, enums, objects, multi types etc
- Much better unit tests touching just the public fns and assert shape
- Type checking request bodies

### Installation

Expand Down
25 changes: 12 additions & 13 deletions lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,11 @@ func addParams(cmd *cobra.Command, op *v3.Operation, handlerData *HandlerData) {
cookieParams := []ParamMeta{}

for _, param := range op.Parameters {
t := param.Schema.Schema().Type[0]
schema := param.Schema.Schema()
t := "string"
if schema != nil {
t = schema.Type[0]
}

switch t {
case "string":
Expand Down Expand Up @@ -125,19 +129,14 @@ func addRequestBody(cmd *cobra.Command, op *v3.Operation, handlerData *HandlerDa
paramName = aliases[0]
}

for mime, kind := range body.Content.FromOldest() {
t := kind.Schema.Schema().Type[0]
handlerData.RequestBodyParam = ParamMeta{Name: paramName, Type: t}
// TODO: Handle all the different MIME types and schemas from body.Content
// maybe assert the shape if mime is json and schema is an object
// Treats all request body content as a string as of now
handlerData.RequestBodyParam = ParamMeta{Name: paramName, Type: "string"}
cmd.Flags().String(paramName, "", body.Description)

switch t {
case "object":
cmd.Flags().String(paramName, "", body.Description)
if req := body.Required; req != nil && *req {
cmd.MarkFlagRequired(paramName)
}
default:
slog.Warn("TODO: Unhandled request body type", "mime", mime, "type", kind.Schema.Schema().Type[0])
}
if req := body.Required; req != nil && *req {
cmd.MarkFlagRequired(paramName)
}
}

Expand Down

0 comments on commit 9aca3ea

Please sign in to comment.