Skip to content

Commit

Permalink
BREAKING CHANGE: Move to yarn 4 and only output a cjs build, drop (of…
Browse files Browse the repository at this point in the history
…ficial) support for node 14, bump json-scheme-walker version and openapi types version (#45)

* chore(versions): move to yarn 4, drop release for node 14, only output cjs

BREAKING CHANGE: Move to yarn 4 and only output a cjs build, drop support for node 14

* update build
  • Loading branch information
jonluca authored Nov 11, 2023
1 parent 9318da1 commit 5b05d98
Show file tree
Hide file tree
Showing 19 changed files with 4,388 additions and 1,915 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 18
- run: yarn install --frozen-lockfile
node-version: latest
cache: 'yarn'
- run: yarn install --immutable
- run: yarn build
- run: yarn test
- run: npx semantic-release --branches main
Expand Down
9 changes: 5 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,20 @@ jobs:
strategy:
matrix:
node-version:
- 14
- 16
- 18
- 20
- latest
steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'yarn'
- name: yarn install, build, and test
run: |
yarn --frozen-lockfile
yarn build --if-present
yarn install --immutable
yarn build
yarn lint
yarn test
env:
Expand Down
Binary file added .yarn/install-state.gz
Binary file not shown.
893 changes: 893 additions & 0 deletions .yarn/releases/yarn-4.0.1.cjs

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
nodeLinker: node-modules

yarnPath: .yarn/releases/yarn-4.0.1.cjs
59 changes: 26 additions & 33 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,16 @@
"name": "@openapi-contrib/json-schema-to-openapi-schema",
"version": "0.0.0-development",
"description": "Converts a JSON Schema to OpenAPI Schema Object",
"bin": {
"json-schema-to-openapi-schema": "bin/json-schema-to-openapi-schema.js"
},
"types": "dist/mjs/index.d.ts",
"bin": "bin/json-schema-to-openapi-schema.js",
"types": "dist/index.d.ts",
"files": [
"/bin",
"/dist"
"bin",
"dist"
],
"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": {
"prepublish": "yarn build",
"build": "rm -fr dist/* && tsc -p tsconfig.json && tsc -p tsconfig-cjs.json && node scripts/fixup.cjs",
"build": "rimraf dist && tsc -p tsconfig.json",
"lint": "eslint . && prettier -c src",
"lint:fix": "eslint . --fix && prettier -c src -w",
"typecheck": "tsc --noEmit",
Expand All @@ -31,30 +22,32 @@
"author": "OpenAPI Contrib",
"license": "MIT",
"engines": {
"node": ">=14"
"node": ">=18"
},
"dependencies": {
"@apidevtools/json-schema-ref-parser": "^9.0.9",
"json-schema-walker": "^1.1.0",
"openapi-types": "^12.1.0",
"yargs": "^17.6.2"
"@apidevtools/json-schema-ref-parser": "^11.1.0",
"json-schema-walker": "^2.0.0",
"openapi-types": "^12.1.3",
"yargs": "^17.7.2"
},
"devDependencies": {
"@types/json-schema": "^7.0.11",
"@typescript-eslint/eslint-plugin": "^5.49.0",
"@typescript-eslint/parser": "^5.49.0",
"c8": "^7.12.0",
"eslint": "^8.32.0",
"eslint-config-prettier": "^8.6.0",
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-unused-imports": "^2.0.0",
"nock": "^13.3.0",
"prettier": "^2.8.3",
"typescript": "^4.9.4",
"vitest": "^0.28.1"
"@types/json-schema": "^7.0.15",
"@typescript-eslint/eslint-plugin": "^6.10.0",
"@typescript-eslint/parser": "^6.10.0",
"c8": "^8.0.1",
"eslint": "^8.53.0",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-prettier": "^5.0.1",
"eslint-plugin-unused-imports": "^3.0.0",
"nock": "^13.3.8",
"prettier": "^3.0.3",
"rimraf": "^5.0.5",
"typescript": "^5.2.2",
"vitest": "^0.34.6"
},
"prettier": {
"singleQuote": true,
"useTabs": true
}
},
"packageManager": "[email protected]"
}
13 changes: 0 additions & 13 deletions scripts/fixup.cjs

This file was deleted.

14 changes: 7 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import type { JSONSchema } from '@apidevtools/json-schema-ref-parser';
import type {
JSONSchema4,
JSONSchema6Definition,
JSONSchema7Definition,
} from 'json-schema';
import type { Options, SchemaType, SchemaTypeKeys } from './types.js';
import type { Options, SchemaType, SchemaTypeKeys } from './types';
import { Walker } from 'json-schema-walker';
import { allowedKeywords } from './const.js';
import { allowedKeywords } from './const';
import type { OpenAPIV3 } from 'openapi-types';
import type { JSONSchema } from '@apidevtools/json-schema-ref-parser/dist/lib/types';

class InvalidTypeError extends Error {
constructor(message: string) {
Expand All @@ -21,7 +21,7 @@ const oasExtensionPrefix = 'x-';

const handleDefinition = async <T extends JSONSchema4 = JSONSchema4>(
def: JSONSchema7Definition | JSONSchema6Definition | JSONSchema4,
schema: T
schema: T,
) => {
if (typeof def !== 'object') {
return def;
Expand All @@ -45,7 +45,7 @@ const handleDefinition = async <T extends JSONSchema4 = JSONSchema4>(
circular: 'ignore',
},
},
}
},
);
await walker.walk(convertSchema, walker.vocabularies.DRAFT_07);
if ('definitions' in walker.rootSchema) {
Expand All @@ -72,7 +72,7 @@ const handleDefinition = async <T extends JSONSchema4 = JSONSchema4>(

const convert = async <T extends object = JSONSchema4>(
schema: T,
options?: Options
options?: Options,
): Promise<OpenAPIV3.Document> => {
const walker = new Walker<T>();
const convertDefs = options?.convertUnreferencedDefinitions ?? true;
Expand Down Expand Up @@ -271,7 +271,7 @@ function convertIllegalKeywordsAsExtensions(schema: SchemaType) {
.filter(
(keyword) =>
!keyword.startsWith(oasExtensionPrefix) &&
!allowedKeywords.includes(keyword)
!allowedKeywords.includes(keyword),
)
.forEach((keyword: SchemaTypeKeys) => {
const key = `${oasExtensionPrefix}${keyword}` as keyof SchemaType;
Expand Down
6 changes: 3 additions & 3 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { JSONSchema } from '@apidevtools/json-schema-ref-parser';
import type $RefParser from '@apidevtools/json-schema-ref-parser';
import type { JSONSchema } from '@apidevtools/json-schema-ref-parser/dist/lib/types';
import type { ParserOptions } from '@apidevtools/json-schema-ref-parser/dist/lib/options';

export type addPrefixToObject = {
[K in keyof JSONSchema as `x-${K}`]: JSONSchema[K];
Expand All @@ -9,7 +9,7 @@ export interface Options {
cloneSchema?: boolean;
dereference?: boolean;
convertUnreferencedDefinitions?: boolean;
dereferenceOptions?: $RefParser.Options;
dereferenceOptions?: ParserOptions | undefined;
}
type ExtendedJSONSchema = addPrefixToObject & JSONSchema;
export type SchemaType = ExtendedJSONSchema & {
Expand Down
2 changes: 1 addition & 1 deletion test/__snapshots__/circular_schema.test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Vitest Snapshot v1
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`converting circular/openapi.json without circular references turned off 1`] = `
{
Expand Down
2 changes: 1 addition & 1 deletion test/__snapshots__/dereference_schema.test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Vitest Snapshot v1
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`throws an error when dereferecing fails 1`] = `
{
Expand Down
3 changes: 2 additions & 1 deletion test/dereference_schema.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,8 @@ it('dereferencing schema with deference option at root', async ({ expect }) => {
expect(result).toEqual(expected);
});

it('dereferencing schema with remote http and https references', async ({
// skip until nock supports native fetch https://github.com/nock/nock/issues/2397
it.skip('dereferencing schema with remote http and https references', async ({
expect,
}) => {
nock('http://foo.bar/')
Expand Down
6 changes: 3 additions & 3 deletions test/invalid_types.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@ import { getSchema } from './helpers';
it('dateTime is invalid type', async ({ expect }) => {
const schema = { type: 'dateTime' };
await expect(() => convert(schema)).rejects.toThrowError(
/is not a valid type/
/is not a valid type/,
);
});

it('foo is invalid type', async ({ expect }) => {
const schema = { type: 'foo' };
await expect(() => convert(schema)).rejects.toThrowError(
/is not a valid type/
/is not a valid type/,
);
});

it('invalid type inside complex schema', async ({ expect }) => {
const schema = getSchema('invalid/json-schema.json');
await expect(() => convert(schema)).rejects.toThrowError(
/is not a valid type/
/is not a valid type/,
);
});
4 changes: 2 additions & 2 deletions test/nullable.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe('nullable', () => {
expect(result).toEqual({
[key]: [{ type: 'string', nullable: true }],
});
}
},
);

it('supports nullables inside definitions', async ({ expect }) => {
Expand Down Expand Up @@ -209,6 +209,6 @@ describe('nullable', () => {
},
],
});
}
},
);
});
6 changes: 3 additions & 3 deletions test/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"target": "ES2015",
"lib": ["es2015", "dom"],
"target": "ESNext",
"lib": ["ESNext", "dom"],
"types": ["vitest/globals"],
"rootDir": "."
"rootDir": "../"
},
"include": ["."]
}
8 changes: 0 additions & 8 deletions tsconfig-cjs.json

This file was deleted.

6 changes: 3 additions & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"compilerOptions": {
"module": "esnext",
"outDir": "dist/mjs",
"module": "commonjs",
"outDir": "dist",
"target": "es2020",
"allowJs": true,
"allowSyntheticDefaultImports": true,
Expand All @@ -12,7 +12,7 @@
"lib": ["esnext"],
"listEmittedFiles": false,
"listFiles": false,
"moduleResolution": "node16",
"moduleResolution": "Node",
"noFallthroughCasesInSwitch": true,
"pretty": true,
"resolveJsonModule": true,
Expand Down
2 changes: 1 addition & 1 deletion vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ export default defineConfig({
reporters: 'verbose',
},
esbuild: {
target: 'node10',
target: 'node21',
},
});
Loading

0 comments on commit 5b05d98

Please sign in to comment.