Skip to content

Commit 5b05d98

Browse files
authored
BREAKING CHANGE: Move to yarn 4 and only output a cjs build, drop (official) 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
1 parent 9318da1 commit 5b05d98

19 files changed

+4388
-1915
lines changed

.github/workflows/release.yml

+3-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ jobs:
1313
- uses: actions/checkout@v3
1414
- uses: actions/setup-node@v3
1515
with:
16-
node-version: 18
17-
- run: yarn install --frozen-lockfile
16+
node-version: latest
17+
cache: 'yarn'
18+
- run: yarn install --immutable
1819
- run: yarn build
1920
- run: yarn test
2021
- run: npx semantic-release --branches main

.github/workflows/test.yml

+5-4
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,20 @@ jobs:
88
strategy:
99
matrix:
1010
node-version:
11-
- 14
12-
- 16
1311
- 18
12+
- 20
13+
- latest
1414
steps:
1515
- uses: actions/checkout@v3
1616
- name: Use Node.js ${{ matrix.node-version }}
1717
uses: actions/setup-node@v3
1818
with:
1919
node-version: ${{ matrix.node-version }}
20+
cache: 'yarn'
2021
- name: yarn install, build, and test
2122
run: |
22-
yarn --frozen-lockfile
23-
yarn build --if-present
23+
yarn install --immutable
24+
yarn build
2425
yarn lint
2526
yarn test
2627
env:

.yarn/install-state.gz

290 KB
Binary file not shown.

.yarn/releases/yarn-4.0.1.cjs

+893
Large diffs are not rendered by default.

.yarnrc.yml

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
nodeLinker: node-modules
2+
3+
yarnPath: .yarn/releases/yarn-4.0.1.cjs

package.json

+26-33
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,16 @@
22
"name": "@openapi-contrib/json-schema-to-openapi-schema",
33
"version": "0.0.0-development",
44
"description": "Converts a JSON Schema to OpenAPI Schema Object",
5-
"bin": {
6-
"json-schema-to-openapi-schema": "bin/json-schema-to-openapi-schema.js"
7-
},
8-
"types": "dist/mjs/index.d.ts",
5+
"bin": "bin/json-schema-to-openapi-schema.js",
6+
"types": "dist/index.d.ts",
97
"files": [
10-
"/bin",
11-
"/dist"
8+
"bin",
9+
"dist"
1210
],
13-
"main": "dist/cjs/index.js",
14-
"module": "dist/mjs/index.js",
15-
"exports": {
16-
".": {
17-
"import": "./dist/mjs/index.js",
18-
"require": "./dist/cjs/index.js"
19-
}
20-
},
11+
"main": "dist/index.js",
2112
"scripts": {
2213
"prepublish": "yarn build",
23-
"build": "rm -fr dist/* && tsc -p tsconfig.json && tsc -p tsconfig-cjs.json && node scripts/fixup.cjs",
14+
"build": "rimraf dist && tsc -p tsconfig.json",
2415
"lint": "eslint . && prettier -c src",
2516
"lint:fix": "eslint . --fix && prettier -c src -w",
2617
"typecheck": "tsc --noEmit",
@@ -31,30 +22,32 @@
3122
"author": "OpenAPI Contrib",
3223
"license": "MIT",
3324
"engines": {
34-
"node": ">=14"
25+
"node": ">=18"
3526
},
3627
"dependencies": {
37-
"@apidevtools/json-schema-ref-parser": "^9.0.9",
38-
"json-schema-walker": "^1.1.0",
39-
"openapi-types": "^12.1.0",
40-
"yargs": "^17.6.2"
28+
"@apidevtools/json-schema-ref-parser": "^11.1.0",
29+
"json-schema-walker": "^2.0.0",
30+
"openapi-types": "^12.1.3",
31+
"yargs": "^17.7.2"
4132
},
4233
"devDependencies": {
43-
"@types/json-schema": "^7.0.11",
44-
"@typescript-eslint/eslint-plugin": "^5.49.0",
45-
"@typescript-eslint/parser": "^5.49.0",
46-
"c8": "^7.12.0",
47-
"eslint": "^8.32.0",
48-
"eslint-config-prettier": "^8.6.0",
49-
"eslint-plugin-prettier": "^4.2.1",
50-
"eslint-plugin-unused-imports": "^2.0.0",
51-
"nock": "^13.3.0",
52-
"prettier": "^2.8.3",
53-
"typescript": "^4.9.4",
54-
"vitest": "^0.28.1"
34+
"@types/json-schema": "^7.0.15",
35+
"@typescript-eslint/eslint-plugin": "^6.10.0",
36+
"@typescript-eslint/parser": "^6.10.0",
37+
"c8": "^8.0.1",
38+
"eslint": "^8.53.0",
39+
"eslint-config-prettier": "^9.0.0",
40+
"eslint-plugin-prettier": "^5.0.1",
41+
"eslint-plugin-unused-imports": "^3.0.0",
42+
"nock": "^13.3.8",
43+
"prettier": "^3.0.3",
44+
"rimraf": "^5.0.5",
45+
"typescript": "^5.2.2",
46+
"vitest": "^0.34.6"
5547
},
5648
"prettier": {
5749
"singleQuote": true,
5850
"useTabs": true
59-
}
51+
},
52+
"packageManager": "[email protected]"
6053
}

scripts/fixup.cjs

-13
This file was deleted.

src/index.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
import type { JSONSchema } from '@apidevtools/json-schema-ref-parser';
21
import type {
32
JSONSchema4,
43
JSONSchema6Definition,
54
JSONSchema7Definition,
65
} from 'json-schema';
7-
import type { Options, SchemaType, SchemaTypeKeys } from './types.js';
6+
import type { Options, SchemaType, SchemaTypeKeys } from './types';
87
import { Walker } from 'json-schema-walker';
9-
import { allowedKeywords } from './const.js';
8+
import { allowedKeywords } from './const';
109
import type { OpenAPIV3 } from 'openapi-types';
10+
import type { JSONSchema } from '@apidevtools/json-schema-ref-parser/dist/lib/types';
1111

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

2222
const handleDefinition = async <T extends JSONSchema4 = JSONSchema4>(
2323
def: JSONSchema7Definition | JSONSchema6Definition | JSONSchema4,
24-
schema: T
24+
schema: T,
2525
) => {
2626
if (typeof def !== 'object') {
2727
return def;
@@ -45,7 +45,7 @@ const handleDefinition = async <T extends JSONSchema4 = JSONSchema4>(
4545
circular: 'ignore',
4646
},
4747
},
48-
}
48+
},
4949
);
5050
await walker.walk(convertSchema, walker.vocabularies.DRAFT_07);
5151
if ('definitions' in walker.rootSchema) {
@@ -72,7 +72,7 @@ const handleDefinition = async <T extends JSONSchema4 = JSONSchema4>(
7272

7373
const convert = async <T extends object = JSONSchema4>(
7474
schema: T,
75-
options?: Options
75+
options?: Options,
7676
): Promise<OpenAPIV3.Document> => {
7777
const walker = new Walker<T>();
7878
const convertDefs = options?.convertUnreferencedDefinitions ?? true;
@@ -271,7 +271,7 @@ function convertIllegalKeywordsAsExtensions(schema: SchemaType) {
271271
.filter(
272272
(keyword) =>
273273
!keyword.startsWith(oasExtensionPrefix) &&
274-
!allowedKeywords.includes(keyword)
274+
!allowedKeywords.includes(keyword),
275275
)
276276
.forEach((keyword: SchemaTypeKeys) => {
277277
const key = `${oasExtensionPrefix}${keyword}` as keyof SchemaType;

src/types.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import type { JSONSchema } from '@apidevtools/json-schema-ref-parser';
2-
import type $RefParser from '@apidevtools/json-schema-ref-parser';
1+
import type { JSONSchema } from '@apidevtools/json-schema-ref-parser/dist/lib/types';
2+
import type { ParserOptions } from '@apidevtools/json-schema-ref-parser/dist/lib/options';
33

44
export type addPrefixToObject = {
55
[K in keyof JSONSchema as `x-${K}`]: JSONSchema[K];
@@ -9,7 +9,7 @@ export interface Options {
99
cloneSchema?: boolean;
1010
dereference?: boolean;
1111
convertUnreferencedDefinitions?: boolean;
12-
dereferenceOptions?: $RefParser.Options;
12+
dereferenceOptions?: ParserOptions | undefined;
1313
}
1414
type ExtendedJSONSchema = addPrefixToObject & JSONSchema;
1515
export type SchemaType = ExtendedJSONSchema & {

test/__snapshots__/circular_schema.test.ts.snap

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Vitest Snapshot v1
1+
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
22

33
exports[`converting circular/openapi.json without circular references turned off 1`] = `
44
{

test/__snapshots__/dereference_schema.test.ts.snap

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Vitest Snapshot v1
1+
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
22

33
exports[`throws an error when dereferecing fails 1`] = `
44
{

test/dereference_schema.test.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,8 @@ it('dereferencing schema with deference option at root', async ({ expect }) => {
192192
expect(result).toEqual(expected);
193193
});
194194

195-
it('dereferencing schema with remote http and https references', async ({
195+
// skip until nock supports native fetch https://github.com/nock/nock/issues/2397
196+
it.skip('dereferencing schema with remote http and https references', async ({
196197
expect,
197198
}) => {
198199
nock('http://foo.bar/')

test/invalid_types.test.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,20 @@ import { getSchema } from './helpers';
44
it('dateTime is invalid type', async ({ expect }) => {
55
const schema = { type: 'dateTime' };
66
await expect(() => convert(schema)).rejects.toThrowError(
7-
/is not a valid type/
7+
/is not a valid type/,
88
);
99
});
1010

1111
it('foo is invalid type', async ({ expect }) => {
1212
const schema = { type: 'foo' };
1313
await expect(() => convert(schema)).rejects.toThrowError(
14-
/is not a valid type/
14+
/is not a valid type/,
1515
);
1616
});
1717

1818
it('invalid type inside complex schema', async ({ expect }) => {
1919
const schema = getSchema('invalid/json-schema.json');
2020
await expect(() => convert(schema)).rejects.toThrowError(
21-
/is not a valid type/
21+
/is not a valid type/,
2222
);
2323
});

test/nullable.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ describe('nullable', () => {
3030
expect(result).toEqual({
3131
[key]: [{ type: 'string', nullable: true }],
3232
});
33-
}
33+
},
3434
);
3535

3636
it('supports nullables inside definitions', async ({ expect }) => {
@@ -209,6 +209,6 @@ describe('nullable', () => {
209209
},
210210
],
211211
});
212-
}
212+
},
213213
);
214214
});

test/tsconfig.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"extends": "../tsconfig.json",
33
"compilerOptions": {
4-
"target": "ES2015",
5-
"lib": ["es2015", "dom"],
4+
"target": "ESNext",
5+
"lib": ["ESNext", "dom"],
66
"types": ["vitest/globals"],
7-
"rootDir": "."
7+
"rootDir": "../"
88
},
99
"include": ["."]
1010
}

tsconfig-cjs.json

-8
This file was deleted.

tsconfig.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"compilerOptions": {
3-
"module": "esnext",
4-
"outDir": "dist/mjs",
3+
"module": "commonjs",
4+
"outDir": "dist",
55
"target": "es2020",
66
"allowJs": true,
77
"allowSyntheticDefaultImports": true,
@@ -12,7 +12,7 @@
1212
"lib": ["esnext"],
1313
"listEmittedFiles": false,
1414
"listFiles": false,
15-
"moduleResolution": "node16",
15+
"moduleResolution": "Node",
1616
"noFallthroughCasesInSwitch": true,
1717
"pretty": true,
1818
"resolveJsonModule": true,

vite.config.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ export default defineConfig({
99
reporters: 'verbose',
1010
},
1111
esbuild: {
12-
target: 'node10',
12+
target: 'node21',
1313
},
1414
});

0 commit comments

Comments
 (0)