Skip to content

Commit

Permalink
fix: use body as root for ingress verb form fix console issue (#1943)
Browse files Browse the repository at this point in the history
Fixes #1863
  • Loading branch information
wesbillman authored Jul 3, 2024
1 parent f4cb64a commit f86b537
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
5 changes: 3 additions & 2 deletions backend/controller/console.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import (
"encoding/json"
"errors"
"fmt"
"github.com/reugn/go-quartz/logger"
"time"

"github.com/reugn/go-quartz/logger"

"connectrpc.com/connect"
"github.com/alecthomas/types/optional"
"google.golang.org/protobuf/types/known/durationpb"
Expand Down Expand Up @@ -100,7 +101,7 @@ func (c *ConsoleService) GetModules(ctx context.Context, req *connect.Request[pb
v := decl.ToProto().(*schemapb.Verb)
verbSchema := schema.VerbFromProto(v)
var jsonRequestSchema string
if verbSchema.Request == nil {
if verbSchema.Request != nil {
if requestData, ok := verbSchema.Request.(*schema.Ref); ok {
jsonSchema, err := schema.DataToJSONSchema(sch, *requestData)
if err != nil {
Expand Down
29 changes: 17 additions & 12 deletions frontend/src/features/verbs/verb.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,15 @@ export const simpleJsonSchema = (verb: Verb): any => {
let schema = JSON.parse(verb.jsonRequestSchema)

if (schema.properties && isHttpIngress(verb)) {
schema = {
...schema,
type: schema.properties.body.type,
properties: {
body: schema.properties.body
},
required: schema.required.includes('body') ? ['body'] : []
const bodySchema = schema.properties.body
if (bodySchema) {
schema = {
...bodySchema,
definitions: schema.definitions,
required: schema.required.includes('body') ? bodySchema.required : []
}
} else {
schema = {}
}
}

Expand All @@ -58,7 +60,6 @@ export const defaultRequest = (verb?: Verb): string => {
}

const schema = simpleJsonSchema(verb)

JSONSchemaFaker.option({
alwaysFakeOptionals: false,
useDefaultValue: true,
Expand Down Expand Up @@ -138,15 +139,19 @@ export const createVerbRequest = (path: string, verb?: Verb, editorText?: strin
return new Uint8Array()
}

const requestJson = JSON.parse(editorText)
let requestJson = JSON.parse(editorText)

if (isHttpIngress(verb)) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const newRequestJson: Record<string, any> = {}
const httpIngress = ingress(verb)
if (httpIngress) {
requestJson['method'] = httpIngress.method
requestJson['path'] = path.replace(basePath, '')
newRequestJson.method = httpIngress.method
newRequestJson.path = path.replace(basePath, '')
}
requestJson.headers = JSON.parse(headers ?? '{}')
newRequestJson.headers = JSON.parse(headers ?? '{}')
newRequestJson.body = requestJson
requestJson = newRequestJson
}

const buffer = Buffer.from(JSON.stringify(requestJson))
Expand Down

0 comments on commit f86b537

Please sign in to comment.