diff --git a/nodepkg/jsoncue/package.json b/nodepkg/jsoncue/package.json index 249e948c..f5e246dc 100644 --- a/nodepkg/jsoncue/package.json +++ b/nodepkg/jsoncue/package.json @@ -1,6 +1,6 @@ { "name": "@innoai-tech/jsoncue", - "version": "0.1.3", + "version": "0.1.4", "monobundle": { "build": { "clean": true diff --git a/nodepkg/jsoncue/src/astutil/stringify.ts b/nodepkg/jsoncue/src/astutil/stringify.ts index a4e92a0a..22084637 100644 --- a/nodepkg/jsoncue/src/astutil/stringify.ts +++ b/nodepkg/jsoncue/src/astutil/stringify.ts @@ -54,6 +54,7 @@ class writer { if (entities.length == 0) { this.#p.write("{}"); + return; } if (entities.length == 1) { diff --git a/webapp/openapi-playground/mod/openapi/RequestBuilder.tsx b/webapp/openapi-playground/mod/openapi/RequestBuilder.tsx index 24a874ae..56e4e923 100644 --- a/webapp/openapi-playground/mod/openapi/RequestBuilder.tsx +++ b/webapp/openapi-playground/mod/openapi/RequestBuilder.tsx @@ -1,6 +1,7 @@ import { + type AnyType, component, - component$, observableRef, + component$, JSONSchemaDecoder, observableRef, refName, render, rx, subscribeOnMountedUntilUnmount, subscribeUntilUnmount, @@ -44,11 +45,17 @@ export const RequestBuilder = component$({ const propSchemas: Record = {}; for (const p of props.operation.parameters ?? []) { - const x = t.custom().use( + let x: AnyType = JSONSchemaDecoder.decode(p.schema, (ref) => { + return [openapi$.schema(ref) ?? {}, refName(ref)]; + }).use( f.label(`${p.name}, in=${JSON.stringify(p.in)}`), - rawSchema(p.schema) + rawSchema(p.schema), ); + if (!p.required) { + x = x.optional(); + } + if (["object", "array"].includes(p.schema.type ?? "")) { propSchemas[p.name] = x.use(f.inputBy(JSONCueEditorInput)); } else { @@ -62,9 +69,11 @@ export const RequestBuilder = component$({ if (first) { const [contentType, content] = first; - const x = t.custom().use( + const x = JSONSchemaDecoder.decode(content.schema ?? {}, (ref) => { + return [openapi$.schema(ref) ?? {}, refName(ref)]; + }).use( f.label(`body, content-type = ${JSON.stringify(contentType)}`), - rawSchema(content.schema) + rawSchema(content.schema), ); if (contentType.includes("json")) { diff --git a/webapp/openapi-playground/mod/openapi/components/JSONCueEditor.tsx b/webapp/openapi-playground/mod/openapi/components/JSONCueEditor.tsx index cf020de9..a52c949d 100644 --- a/webapp/openapi-playground/mod/openapi/components/JSONCueEditor.tsx +++ b/webapp/openapi-playground/mod/openapi/components/JSONCueEditor.tsx @@ -1,8 +1,6 @@ import { type AnyType, component$, - JSONSchemaDecoder, - refName, rx, subscribeUntilUnmount, t, @@ -27,7 +25,6 @@ import { JSONCue } from "@innoai-tech/jsoncue"; import { keymap } from "@codemirror/view"; import type { Extension } from "@codemirror/state"; import { linter } from "@codemirror/lint"; -import { OpenAPIProvider } from "../OpenAPIProvider.tsx"; import { jsoncueCompletions } from "@innoai-tech/jsoncue/codemirror"; import { isUndefined } from "../util/typed.ts"; @@ -37,18 +34,8 @@ export const JSONCueEditorInput = component$( readOnly: t.boolean().optional() }, (props, {}) => { - const openapi$ = OpenAPIProvider.use(); - const editorContext = createEditorContext(!isUndefined(props.field$.input) ? JSONCue.stringify(props.field$.input) : ""); - let rawSchema = JSONSchemaDecoder.decode(props.field$.meta["rawSchema"] ?? {}, (ref) => { - return [openapi$.schema(ref) ?? {}, refName(ref)]; - }); - - if (props.field$.optional) { - rawSchema = rawSchema.optional(); - } - return () => (