Skip to content

Commit

Permalink
BREAKING CHANGE: #51 Bump versions, change build to only be cjs, add …
Browse files Browse the repository at this point in the history
…cli (#68)

* BREAKING CHANGE: #51 Bump versions, change build to only be cjs, add cli

* remove present

* add readme
  • Loading branch information
jonluca authored Jul 11, 2023
1 parent abd2e4a commit e1873a6
Show file tree
Hide file tree
Showing 9 changed files with 1,328 additions and 1,172 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: yarn install, build, and test
run: |
yarn --frozen-lockfile
yarn build --if-present
yarn build
yarn lint
yarn test
env:
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ If you need to do the conversion in reverse, checkout [json-schema-to-openapi-sc
npm install --save @openapi-contrib/openapi-schema-to-json-schema
```

### CLI

```bash
npx openapi-schema-to-json-schema --input openapi.json --output json-schema.json
```

## Converting OpenAPI schema

Here's a small example to get the idea:
Expand Down
51 changes: 27 additions & 24 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,52 +2,55 @@
"name": "@openapi-contrib/openapi-schema-to-json-schema",
"version": "0.0.0-development",
"description": "Converts OpenAPI Schema Object to JSON Schema",
"types": "dist/mjs/index.d.ts",
"types": "dist/index.d.ts",
"files": [
"/dist"
"dist",
"src",
"package.json",
"tsconfig.json"
],
"main": "dist/cjs/index.js",
"module": "dist/mjs/index.js",
"exports": {
".": {
"import": "./dist/mjs/index.js",
"require": "./dist/cjs/index.js"
}
},
"main": "dist/index.js",
"scripts": {
"build": "rm -fr dist/* && tsc -p tsconfig.json && tsc -p tsconfig-cjs.json && node scripts/fixup.cjs",
"build": "rimraf dist && tsc -p tsconfig.json",
"test": "vitest",
"coverage": "vitest --coverage",
"lint": "eslint . && prettier -c src",
"typecheck": "tsc --noEmit",
"lint:fix": "eslint . --fix && prettier -c src -w"
},
"repository": "github:openapi-contrib/openapi-schema-to-json-schema",
"repository": "https://github.com/openapi-contrib/openapi-schema-to-json-schema",
"author": "OpenAPI Contrib",
"license": "MIT",
"bin": "dist/bin.js",
"dependencies": {
"@types/node": "^20.2.5",
"@types/json-schema": "^7.0.12",
"@types/node": "^20.4.1",
"fast-deep-equal": "^3.1.3",
"openapi-typescript": "^5.4.1"
"openapi-typescript": "^5.4.1",
"yargs": "^17.7.2"
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^5.59.8",
"@typescript-eslint/parser": "^5.59.8",
"c8": "^7.14.0",
"eslint": "^8.42.0",
"@types/yargs": "^17.0.24",
"@typescript-eslint/eslint-plugin": "^6.0.0",
"@typescript-eslint/parser": "^6.0.0",
"c8": "^8.0.0",
"eslint": "^8.44.0",
"eslint-config-prettier": "^8.8.0",
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-unused-imports": "^2.0.0",
"prettier": "^2.8.8",
"semantic-release": "^21.0.3",
"typescript": "^5.1.3",
"vitest": "^0.31.4"
"eslint-plugin-prettier": "^5.0.0",
"eslint-plugin-unused-imports": "^3.0.0",
"prettier": "^3.0.0",
"rimraf": "^5.0.1",
"semantic-release": "^21.0.7",
"typescript": "^5.1.6",
"vitest": "^0.33.0"
},
"prettier": {
"printWidth": 120,
"useTabs": false,
"arrowParens": "always",
"trailingComma": "all"
},
"engines": {
"node": ">=14.0.0"
}
}
13 changes: 0 additions & 13 deletions scripts/fixup.cjs

This file was deleted.

37 changes: 37 additions & 0 deletions src/bin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/env node

import yargs from "yargs";
import { hideBin } from "yargs/helpers";
import { openapiSchemaToJsonSchema } from "./index.js";
import fs from "fs/promises";
import * as process from "process";
import type { AcceptibleInputSchema } from "./openapi-schema-types";
const args = yargs(hideBin(process.argv))
.options({
input: { type: "string", alias: "f", demandOption: true },
output: { type: "string", alias: "o" },
})
.parseSync();

const { input, output } = args;

const getFileContents = async () => {
try {
const fileContents = await fs.readFile(input, "utf-8");
return JSON.parse(fileContents) as AcceptibleInputSchema;
} catch (e: any) {
console.error(`Error: ${e.message}`);
process.exit(1);
}
};

(async () => {
try {
const fileContents = await getFileContents();
const convertedSchema = await openapiSchemaToJsonSchema(fileContents);
const outputFile = output || input.replace(/\.json$/, "-converted.json");
await fs.writeFile(outputFile, JSON.stringify(convertedSchema, null, 2));
} catch (e: any) {
console.error(`Error: ${e.message}`);
}
})();
6 changes: 3 additions & 3 deletions src/lib/utils/cloneDeep.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// From https://dev.to/salyadav/deep-clone-of-js-objects-with-circular-dependency-4if7
const isArray = (val) => {
const isArray = (val: unknown) => {
return Array.isArray(val);
};

const isObject = (val) => {
const isObject = (val: unknown) => {
return {}.toString.call(val) === "[object Object]" && !isArray(val);
};

export const cloneDeep = (val, history = new Set()) => {
export const cloneDeep = (val: unknown, history = new Set()) => {
const stack = history || new Set();

if (stack.has(val)) {
Expand Down
8 changes: 0 additions & 8 deletions tsconfig-cjs.json

This file was deleted.

9 changes: 4 additions & 5 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
{
"compilerOptions": {
"module": "esnext",
"outDir": "dist/mjs",
"module": "CommonJS",
"outDir": "dist",
"target": "es2020",
"allowJs": true,
"allowSyntheticDefaultImports": true,
"baseUrl": "src",
"declaration": true,
"esModuleInterop": true,
"inlineSourceMap": false,
"lib": ["esnext"],
"lib": ["ES2020"],
"listEmittedFiles": false,
"listFiles": false,
"moduleResolution": "node",
"noFallthroughCasesInSwitch": true,
"pretty": true,
"resolveJsonModule": true,
"rootDir": "src",
"skipLibCheck": true,
"noImplicitAny": false,
"strict": true,
"noUnusedParameters": true,
"noImplicitAny": false,
"sourceMap": true
},
"compileOnSave": false,
Expand Down
Loading

0 comments on commit e1873a6

Please sign in to comment.