@kmudrick/io-ts-openapi
Advanced tools
Comparing version 0.0.21 to 0.0.22
@@ -15,9 +15,11 @@ #!/usr/bin/env node | ||
useJoda: { type: "boolean" }, | ||
isModel: { type: "boolean" }, | ||
}) | ||
.default({ | ||
useJoda: false, | ||
isModel: false, | ||
}); | ||
(async () => { | ||
const { input, output, useJoda } = await parser.argv; | ||
await (0, program_1.runProgram)(input, output, useJoda); | ||
const { input, output, useJoda, isModel } = await parser.argv; | ||
await (0, program_1.runProgram)(input, output, useJoda, isModel); | ||
return output; | ||
@@ -24,0 +26,0 @@ })().then( |
@@ -6,2 +6,3 @@ declare type UnparsedSchemas = { | ||
export declare function parseFile(file: string): Promise<UnparsedSchemas>; | ||
export declare function parseModelFile(file: string): Promise<UnparsedSchemas>; | ||
export {}; |
@@ -29,3 +29,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.parseFile = void 0; | ||
exports.parseModelFile = exports.parseFile = void 0; | ||
const yaml_1 = __importDefault(require("yaml")); | ||
@@ -90,2 +90,12 @@ const promises_1 = __importDefault(require("fs/promises")); | ||
exports.parseFile = parseFile; | ||
const capitalize = (s) => `${s.charAt(0).toUpperCase()}${s.slice(1)}`; | ||
async function parseModelFile(file) { | ||
const contents = await promises_1.default.readFile(file, "utf8"); | ||
const yaml = yaml_1.default.parse(contents); // handles yaml or json | ||
return Object.entries(yaml).map(([name, content]) => ({ | ||
name: capitalize(name), | ||
content, | ||
})); | ||
} | ||
exports.parseModelFile = parseModelFile; | ||
//# sourceMappingURL=parser.js.map |
@@ -1,1 +0,1 @@ | ||
export declare function runProgram(inputFile: string, outputFile: string, useJoda: boolean): Promise<void>; | ||
export declare function runProgram(inputFile: string, outputFile: string, useJoda: boolean, isModel: boolean): Promise<void>; |
@@ -15,4 +15,5 @@ "use strict"; | ||
const type_codegen_1 = require("./type-codegen"); | ||
async function runProgram(inputFile, outputFile, useJoda) { | ||
const unparsedSchemas = await (0, parser_1.parseFile)(inputFile); | ||
async function runProgram(inputFile, outputFile, useJoda, isModel) { | ||
const parse = isModel ? parser_1.parseModelFile : parser_1.parseFile; | ||
const unparsedSchemas = await parse(inputFile); | ||
const parsed = unparsedSchemas.reduce((acc, entry) => { | ||
@@ -19,0 +20,0 @@ const { name, content } = entry; |
{ | ||
"name": "@kmudrick/io-ts-openapi", | ||
"version": "0.0.21", | ||
"version": "0.0.22", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "repository": { |
@@ -11,10 +11,12 @@ #!/usr/bin/env node | ||
useJoda: { type: "boolean" }, | ||
isModel: { type: "boolean" }, | ||
}) | ||
.default({ | ||
useJoda: false, | ||
isModel: false, | ||
}); | ||
(async () => { | ||
const { input, output, useJoda } = await parser.argv; | ||
await runProgram(input, output, useJoda); | ||
const { input, output, useJoda, isModel } = await parser.argv; | ||
await runProgram(input, output, useJoda, isModel); | ||
return output; | ||
@@ -21,0 +23,0 @@ })().then( |
@@ -64,1 +64,13 @@ import YAML from "yaml"; | ||
} | ||
const capitalize = (s: string): string => | ||
`${s.charAt(0).toUpperCase()}${s.slice(1)}`; | ||
export async function parseModelFile(file: string): Promise<UnparsedSchemas> { | ||
const contents = await fs.readFile(file, "utf8"); | ||
const yaml = YAML.parse(contents); // handles yaml or json | ||
return Object.entries(yaml).map(([name, content]) => ({ | ||
name: capitalize(name), | ||
content, | ||
})); | ||
} |
@@ -6,3 +6,3 @@ import fs from "fs/promises"; | ||
import { formatValidationErrors } from "io-ts-reporters"; | ||
import { parseFile } from "./parser"; | ||
import { parseFile, parseModelFile } from "./parser"; | ||
import { JSONSchema } from "./json-schema"; | ||
@@ -14,5 +14,7 @@ import { toDeclarations, getRuntime, getStatic } from "./type-codegen"; | ||
outputFile: string, | ||
useJoda: boolean | ||
useJoda: boolean, | ||
isModel: boolean | ||
): Promise<void> { | ||
const unparsedSchemas = await parseFile(inputFile); | ||
const parse = isModel ? parseModelFile : parseFile; | ||
const unparsedSchemas = await parse(inputFile); | ||
const parsed: Record<string, JSONSchema> = unparsedSchemas.reduce( | ||
@@ -19,0 +21,0 @@ (acc, entry) => { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
79140
1390