From c0867beff19600a4d616badf46693c52d5567c46 Mon Sep 17 00:00:00 2001 From: John Schulz Date: Sun, 21 Feb 2021 10:22:17 -0500 Subject: [PATCH] Fix 500 for json schema to openapi schema (#268) * Use same package in packageUrl, view, package.json Trying a hunch for https://github.com/ritz078/transform/issues/247 Either way, I don't know how these relate but it seems like they should all be the same. I also can't find any other reference to the wework package. * Move OpenAPI conversion to api --- pages/api/json-schema-to-openapi-schema.ts | 15 +++++++++++++++ pages/json-schema-to-openapi-schema.tsx | 22 ++++++++++++---------- utils/routes.tsx | 2 +- 3 files changed, 28 insertions(+), 11 deletions(-) create mode 100644 pages/api/json-schema-to-openapi-schema.ts diff --git a/pages/api/json-schema-to-openapi-schema.ts b/pages/api/json-schema-to-openapi-schema.ts new file mode 100644 index 0000000..069ab13 --- /dev/null +++ b/pages/api/json-schema-to-openapi-schema.ts @@ -0,0 +1,15 @@ +import { NextApiRequest, NextApiResponse } from "next"; +import toOpenApi from "@openapi-contrib/json-schema-to-openapi-schema"; + +export default async (req: NextApiRequest, res: NextApiResponse) => { + try { + const jsonSchema = req.body; + const openApiSchema = await toOpenApi(JSON.parse(jsonSchema), { + cloneSchema: true + }); + + res.status(200).send(JSON.stringify(openApiSchema, null, 2)); + } catch (e) { + res.status(500).send(e.message); + } +}; diff --git a/pages/json-schema-to-openapi-schema.tsx b/pages/json-schema-to-openapi-schema.tsx index 79ac9b0..3f910f0 100644 --- a/pages/json-schema-to-openapi-schema.tsx +++ b/pages/json-schema-to-openapi-schema.tsx @@ -1,18 +1,12 @@ import ConversionPanel, { Transformer } from "@components/ConversionPanel"; import * as React from "react"; import { useCallback } from "react"; -import toOpenApi from "@openapi-contrib/json-schema-to-openapi-schema"; +import request from "@utils/request"; +import { Alert } from "evergreen-ui"; export default function() { - const transformer = useCallback( - async ({ value }) => - JSON.stringify( - toOpenApi(JSON.parse(value), { - cloneSchema: true - }), - null, - 2 - ), + const transformer = useCallback( + ({ value }) => request("/api/json-schema-to-openapi-schema", value), [] ); @@ -24,6 +18,14 @@ export default function() { editorDefaultValue="jsonSchema" resultTitle="Open API Schema" resultLanguage={"json"} + resultEditorProps={{ + topNotifications: () => ( + + ) + }} /> ); } diff --git a/utils/routes.tsx b/utils/routes.tsx index 4bbeba9..5696a04 100644 --- a/utils/routes.tsx +++ b/utils/routes.tsx @@ -151,7 +151,7 @@ export const categorizedRoutes = [ label: "to OpenAPI Schema", path: "json-schema-to-openapi-schema", packageName: "json-schema-to-openapi-schema", - packageUrl: "https://github.com/wework/json-schema-to-openapi-schema" + packageUrl: "https://github.com/openapi-contrib/json-schema-to-openapi-schema" }, { label: "to Protobuf",