Skip to content

Commit

Permalink
fix(openapi): updates docs
Browse files Browse the repository at this point in the history
  • Loading branch information
morlay committed Apr 23, 2024
1 parent 02e848a commit f74da0e
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 20 deletions.
2 changes: 1 addition & 1 deletion nodepkg/jsoncue/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@innoai-tech/jsoncue",
"version": "0.1.3",
"version": "0.1.4",
"monobundle": {
"build": {
"clean": true
Expand Down
1 change: 1 addition & 0 deletions nodepkg/jsoncue/src/astutil/stringify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class writer {

if (entities.length == 0) {
this.#p.write("{}");
return;
}

if (entities.length == 1) {
Expand Down
19 changes: 14 additions & 5 deletions webapp/openapi-playground/mod/openapi/RequestBuilder.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
type AnyType,
component,
component$, observableRef,
component$, JSONSchemaDecoder, observableRef, refName,
render,
rx, subscribeOnMountedUntilUnmount,
subscribeUntilUnmount,
Expand Down Expand Up @@ -44,11 +45,17 @@ export const RequestBuilder = component$({
const propSchemas: Record<string, any> = {};

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 {
Expand All @@ -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")) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import {
type AnyType,
component$,
JSONSchemaDecoder,
refName,
rx,
subscribeUntilUnmount,
t,
Expand All @@ -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";

Expand All @@ -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 () => (
<Box
sx={{
Expand All @@ -64,7 +51,7 @@ export const JSONCueEditorInput = component$(
>
<Editor
field$={props.field$}
schema={rawSchema}
schema={props.field$.typedef}
/>
</EditorContextProvider>
</Box>
Expand Down

0 comments on commit f74da0e

Please sign in to comment.