fix(ts-schema): typescript to JSON Schema now working (#183)

* updated dependencies

* fix(ts-schema): typescript to JSON Schema now working

fix #182

* added more data in typescript value

* updated svgr

* updated jsonld

* update dependencies

* added stale bot

* fixes

* fixes

* fixes
This commit is contained in:
Ritesh Kumar authored and GitHub committed 2020-06-05 01:50:14 +05:30
1 parent 27b46790f0
commit b69461b66e
14 files changed
+877 -601

No files matched your search

+17
View File
@@ -0,0 +1,17 @@
# Number of days of inactivity before an issue becomes stale
daysUntilStale: 60
# Number of days of inactivity before a stale issue is closed
daysUntilClose: 7
# Issues with these labels will never be considered stale
exemptLabels:
- pinned
- security
# Label to use when marking an issue as stale
staleLabel: wontfix
# Comment to post when marking an issue as stale. Set to `false` to disable
markComment: >
This issue has been automatically marked as stale because it has not had
recent activity. It will be closed if no further activity occurs. Thank you
for your contributions.
# Comment to post when closing a stale issue. Set to `false` to disable
closeComment: false
+14
View File
@@ -349,3 +349,17 @@ export const CounterExample = () => {
</div>
);
}`;
export const typeScriptInterface = `export interface Root {
userId: number;
id: number;
title: string;
completed: boolean;
}
export interface Props {
/** The user's name */
name: string;
/** Should the name be rendered in bold */
priority?: boolean
}`;
+1 -6
View File
@@ -40,12 +40,7 @@ const config = {
"java",
"pug"
],
features: [
"folding",
"goToDefinitionMouse",
"referenceSearch",
"coreCommands"
]
features: ["folding"]
})
);
+17 -17
View File
@@ -37,10 +37,10 @@
"@graphql-codegen/typescript-stencil-apollo": "^1.4.0",
"@graphql-codegen/typescript-urql": "^1.4.0",
"@khanacademy/flow-to-ts": "^0.1.6",
"@svgr/core": "^4.3.2",
"@svgr/plugin-jsx": "^4.3.2",
"@types/jsonld": "^1.5.0",
"@walmartlabs/json-to-simple-graphql-schema": "^2.0.0",
"@svgr/core": "^5.4.0",
"@svgr/plugin-jsx": "^5.4.0",
"@types/jsonld": "^1.5.1",
"@walmartlabs/json-to-simple-graphql-schema": "^2.0.1",
"babel-plugin-json-to-proptypes": "^0.1.0",
"babel-plugin-object-styles-to-template": "^0.2.2",
"babel-standalone": "^6.26.0",
@@ -55,37 +55,37 @@
"html2pug": "^4.0.0",
"htmltojsx": "^0.3.0",
"is-capitalized": "^1.0.0",
"is-svg": "^4.2.0",
"is-svg": "^4.2.1",
"json-schema-to-openapi-schema": "^0.3.0",
"json-schema-to-typescript": "^8.0.0",
"json-schema-to-typescript": "^9.1.0",
"json-to-go": "gist:0d0b8324131c80eeb7e1df20001be32f",
"json-ts": "^1.6.4",
"json_typegen_wasm": "^0.4.0",
"jsonld": "^1.6.2",
"jsonld": "^3.1.1",
"load-script": "^1.0.0",
"lodash": "^4.17.15",
"markdown": "^0.5.0",
"monaco-editor": "0.17.1",
"next": "9.1.1",
"nprogress": "^0.2.0",
"postcss": "^7.0.26",
"postcss": "^7.0.32",
"postcss-js": "^2.0.3",
"qrcode.react": "^0.9.3",
"react": "^16.12.0",
"react-dom": "^16.12.0",
"qrcode.react": "^1.0.0",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-dropzone": "^10.2.1",
"react-ga": "^2.7.0",
"rust-keywords": "^1.1.0",
"sha1": "^1.1.1",
"snack-sdk": "^2.3.1",
"snack-sdk": "^2.6.2",
"stringify-object": "^3.3.0",
"svg-to-dataurl": "^1.0.0",
"svgo": "^1.3.2",
"tempy": "^0.3.0",
"tempy": "^0.5.0",
"text-encoding-utf-8": "^1.0.2",
"transform-json-types": "^0.7.0",
"ts-json-schema-generator": "^0.58.1",
"typescript": "3.5.3",
"ts-json-schema-generator": "^0.70.0",
"typescript": "3.9.5",
"xml-js": "^1.6.11",
"yaml": "^1.7.2"
},
@@ -93,10 +93,10 @@
"@babel/helper-create-regexp-features-plugin": "^7.7.4",
"@next/bundle-analyzer": "^9.0.2",
"@now/node": "^0.12.0",
"@types/lodash": "^4.14.135",
"@types/lodash": "^4.14.155",
"@types/prettier": "^1.18.0",
"@types/react": "^16.8.23",
"@types/svgo": "^1.2.1",
"@types/svgo": "^1.3.3",
"@zeit/next-css": "^1.0.1",
"babel-plugin-module-resolver": "^3.2.0",
"husky": "^3.0.1",
+12
View File
@@ -0,0 +1,12 @@
import { NextApiRequest, NextApiResponse } from "next";
import html2pug from "html2pug";
export default (req: NextApiRequest, res: NextApiResponse) => {
try {
const { value, settings } = JSON.parse(req.body);
const result = html2pug(value, settings);
res.status(200).send(result);
} catch (e) {
res.status(500).send(e.message);
}
};
+5 -22
View File
@@ -1,37 +1,20 @@
import { NextApiRequest, NextApiResponse } from "next";
import { SchemaGenerator } from "ts-json-schema-generator";
import * as ts from "typescript";
import { createFormatter } from "ts-json-schema-generator/dist/factory/formatter";
import { createParser } from "ts-json-schema-generator/dist/factory/parser";
import { createProgram } from "ts-json-schema-generator/dist/factory/program";
import { Config } from "ts-json-schema-generator/dist/src/Config";
import tempy from "tempy";
import fs from "fs";
import path from "path";
import * as tsj from "ts-json-schema-generator";
export default (req: NextApiRequest, res: NextApiResponse) => {
try {
const filePath = tempy.file({ extension: "ts" });
fs.writeFileSync(filePath, req.body);
const filePath = tempy.writeSync(req.body, { extension: "ts" });
const config: Config = {
path: path.resolve(filePath),
path: filePath,
expose: "all",
topRef: true,
jsDoc: "extended",
type: "*"
};
const program = createProgram(config);
const generator: SchemaGenerator = new SchemaGenerator(
program,
createParser(program, config),
// @ts-ignore
createFormatter(config)
);
const schema = generator.createSchema("*");
fs.unlink(filePath, () => {});
res.status(200).send(schema);
const schema = tsj.createGenerator(config).createSchema(config.type);
res.status(200).send(JSON.stringify(schema, null, 2));
} catch (e) {
res.status(500).send(e.message);
}
+7 -6
View File
@@ -3,8 +3,7 @@ import * as React from "react";
import { useCallback } from "react";
import { useSettings } from "@hooks/useSettings";
import Form, { InputType } from "@components/Form";
import html2pug from "html2pug";
import minify from "@assets/vendor/html-minifier";
import request from "@utils/request";
const formFields = [
{
@@ -55,10 +54,12 @@ export default function() {
}, []);
const transformer = useCallback(
async ({ value }) => {
return html2pug(value, minify, settings);
},
[settings, minify]
({ value }) =>
request("/api/html-to-pug", {
value,
settings
}),
[settings]
);
return (
+1 -1
View File
@@ -5,7 +5,7 @@ import { normalize } from "jsonld";
export default function() {
const transformer = useCallback(async ({ value }) => {
return (await normalize(JSON.parse(value))) as Promise<string>;
return normalize(JSON.parse(value));
}, []);
return (
+2 -2
View File
@@ -5,9 +5,9 @@ import { toRDF } from "jsonld";
export default function() {
const transformer = useCallback(async ({ value }) => {
return toRDF(JSON.parse(value), {
return (toRDF(JSON.parse(value), {
format: "application/n-quads"
}) as Promise<string>;
}) as unknown) as Promise<string>;
}, []);
return (
+1 -1
View File
@@ -36,7 +36,7 @@ export default function() {
sessionId: Math.random()
.toString(36)
.substr(2, 8),
sdkVersion: "33.0.0"
sdkVersion: "37.0.0"
});
snackSession.current.startAsync();
+1
View File
@@ -15,6 +15,7 @@ export default function() {
transformer={transformer}
editorTitle="TypeScript"
editorLanguage="typescript"
editorDefaultValue="typeScriptInterface"
resultTitle="JSON Schema"
resultLanguage={"json"}
resultEditorProps={{
-18
View File
@@ -1,18 +0,0 @@
diff --git a/node_modules/html2pug/src/index.js b/node_modules/html2pug/src/index.js
index 57a6b6a..d8a43c7 100644
--- a/node_modules/html2pug/src/index.js
+++ b/node_modules/html2pug/src/index.js
@@ -1,4 +1,3 @@
-const { minify } = require('html-minifier')
const { parse, parseFragment } = require('parse5')
const Pugify = require('./parser')
@@ -17,7 +16,7 @@ const defaultOptions = {
preserveLineBreaks: true,
}
-module.exports = (sourceHtml, options = {}) => {
+module.exports = (sourceHtml,minify, options = {}) => {
// Minify source HTML
const opts = { ...defaultOptions, ...options }
const html = minify(sourceHtml, opts)
@@ -14,10 +14,10 @@ index 1c2c709..ccc647b 100644
exports.format = format;
//# sourceMappingURL=formatter.js.map
diff --git a/node_modules/json-schema-to-typescript/dist/src/index.js b/node_modules/json-schema-to-typescript/dist/src/index.js
index 068d6dc..b7c5ac9 100644
index c3e750a..0acfe57 100644
--- a/node_modules/json-schema-to-typescript/dist/src/index.js
+++ b/node_modules/json-schema-to-typescript/dist/src/index.js
@@ -59,9 +59,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
@@ -60,9 +60,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
}
};
Object.defineProperty(exports, "__esModule", { value: true });
@@ -27,9 +27,9 @@ index 068d6dc..b7c5ac9 100644
var formatter_1 = require("./formatter");
var generator_1 = require("./generator");
var normalizer_1 = require("./normalizer");
@@ -88,17 +86,7 @@ exports.DEFAULT_OPTIONS = {
},
unreachableDefinitions: false
@@ -91,17 +89,7 @@ exports.DEFAULT_OPTIONS = {
unreachableDefinitions: false,
unknownAny: true
};
-function compileFromFile(filename, options) {
- if (options === void 0) { options = exports.DEFAULT_OPTIONS; }
+794 -523
View File
File diff suppressed because it is too large. Load diff