Skip to content

Commit

Permalink
fix: console erroring with bad jsonschema values (#2006)
Browse files Browse the repository at this point in the history
This doesn't fully fix the issue with jsonschema and `TypeAlias`ed
fields, but will keep the console from failing completely when the
schema is not valid.

See #2004 
See #1991
  • Loading branch information
wesbillman authored Jul 8, 2024
1 parent 8fedcd7 commit e455dba
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
10 changes: 8 additions & 2 deletions backend/schema/jsonschema.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ func DataToJSONSchema(sch *Schema, ref Ref) (*jsonschema.Schema, error) {
case *Enum:
root.Definitions[r.String()] = jsonschema.SchemaOrBool{TypeObject: nodeToJSSchema(n, refs)}

case *Config, *Database, *Secret, *Verb, *FSM, *TypeAlias, *Topic, *Subscription:
case *TypeAlias:
root.Definitions[r.String()] = jsonschema.SchemaOrBool{TypeObject: nodeToJSSchema(n.Type, refs)}

case *Config, *Database, *Secret, *Verb, *FSM, *Topic, *Subscription:
return nil, fmt.Errorf("reference to unsupported node type %T", decl)
}
}
Expand Down Expand Up @@ -183,11 +186,14 @@ func nodeToJSSchema(node Node, refs map[RefKey]*Ref) *jsonschema.Schema {
case *TypeParameter:
return &jsonschema.Schema{}

case *TypeAlias:
return nodeToJSSchema(node.Type, refs)

case Decl, *Field, Metadata, *MetadataCalls, *MetadataDatabases, *MetadataIngress,
*MetadataAlias, IngressPathComponent, *IngressPathLiteral, *IngressPathParameter, *Module,
*Schema, Type, *Database, *Verb, *EnumVariant, *MetadataCronJob, Value,
*StringValue, *IntValue, *TypeValue, *Config, *Secret, Symbol, Named,
*FSM, *FSMTransition, *TypeAlias, *MetadataRetry, *Topic, *Subscription, *MetadataSubscriber:
*FSM, *FSMTransition, *MetadataRetry, *Topic, *Subscription, *MetadataSubscriber:
panic(fmt.Sprintf("unsupported node type %T", node))

default:
Expand Down
14 changes: 10 additions & 4 deletions frontend/src/features/verbs/verb.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,18 @@ export const defaultRequest = (verb?: Verb): string => {
requiredOnly: true
})

let fake = JSONSchemaFaker.generate(schema)
if (fake) {
fake = processJsonValue(fake)
try {
let fake = JSONSchemaFaker.generate(schema)
if (fake) {
fake = processJsonValue(fake)
}

return JSON.stringify(fake, null, 2) ?? '{}'
} catch (error) {
console.error(error)
return '{}'
}

return JSON.stringify(fake, null, 2) ?? '{}'
}

export const ingress = (verb?: Verb) => {
Expand Down

0 comments on commit e455dba

Please sign in to comment.