Skip to content

Commit

Permalink
--wip-- [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
Edward Irby committed Aug 29, 2023
1 parent e264cbc commit 1cf63d6
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions console/client/src/features/verbs/VerbForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,17 @@ export const VerbForm: React.FC<Props> = ({module, verb}) => {
const [editorText, setEditorText] = React.useState<string>('')
const [response, setResponse] = React.useState<string | null>(null)
const [error, setError] = React.useState<string | null>(null)

// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const [schema, setSchema] = React.useState<Schema>()
useEffect(() => {
if (verb?.jsonRequestSchema) {
JSONSchemaFaker.option('maxItems', 2)
JSONSchemaFaker.option('alwaysFakeOptionals', true)

// eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-assignment
const schema = JSON.parse(verb.jsonRequestSchema) as Schema
setEditorText(JSON.stringify(JSONSchemaFaker.generate(schema), null, 2))
const verbSchema = JSON.parse(verb.jsonRequestSchema) as Schema
setSchema(verbSchema)
setEditorText(JSON.stringify(JSONSchemaFaker.generate(verbSchema), null, 2))
}
}, [])

Expand Down Expand Up @@ -67,6 +69,17 @@ export const VerbForm: React.FC<Props> = ({module, verb}) => {
setError(String(error))
}
}
const handleEditorWillMount = monaco => {
verb?.jsonRequestSchema && monaco.languages.json.jsonDefaults.setDiagnosticsOptions({
validate: true,
schemas: [{
uri: 'http://myserver/json-schema',
fileMatch: ['*'],
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
schema,
}],
})
}

return (
<>
Expand All @@ -85,6 +98,7 @@ export const VerbForm: React.FC<Props> = ({module, verb}) => {
scrollBeyondLastLine: false,
}}
onChange={handleEditorChange}
beforeMount={handleEditorWillMount}
/>
</div>

Expand Down

0 comments on commit 1cf63d6

Please sign in to comment.