Skip to content

Commit 03d3f64

Browse files
committed
Upgrade dependencies
1 parent 571cd8c commit 03d3f64

28 files changed

+4496
-6216
lines changed

package-lock.json

Lines changed: 681 additions & 623 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"prepare": "npm run build",
1414
"prepublishOnly": "rm -rf dist && npm run build",
1515
"postpublish": "git push && git push --tags",
16-
"test": "(cd tests && npm test)"
16+
"test": "npm test --prefix ./tests"
1717
},
1818
"keywords": [
1919
"openapi",
@@ -34,22 +34,22 @@
3434
},
3535
"homepage": "https://github.com/Q42/openapi-typescript-validator",
3636
"peerDependencies": {
37-
"ajv": "^8.0.0",
38-
"ajv-formats": "^2.0.0"
37+
"ajv": "^8.17.1"
3938
},
4039
"dependencies": {
41-
"@openapi-contrib/openapi-schema-to-json-schema": "^3.0.4",
42-
"ajv": "^8.0.0",
43-
"ajv-formats": "^2.0.0",
44-
"js-yaml": "^4.0.0",
45-
"json-schema-to-typescript": "^11.0.2",
46-
"lodash.keyby": "^4.6.0"
40+
"@openapi-contrib/openapi-schema-to-json-schema": "^5.1.0",
41+
"ajv": "^8.17.1",
42+
"ajv-formats": "^3.0.1",
43+
"js-yaml": "^4.1.0",
44+
"json-schema-to-typescript": "^15.0.4",
45+
"lodash.keyby": "^4.6.0",
46+
"openapi-typescript-validator": "^4.0.0"
4747
},
4848
"devDependencies": {
49-
"@types/js-yaml": "^4.0.0",
50-
"@types/lodash.keyby": "^4.6.6",
51-
"@types/object-hash": "^1.3.4",
52-
"prettier": "^2.2.1",
53-
"typescript": "^4.2.2"
49+
"@types/js-yaml": "^4.0.9",
50+
"@types/lodash.keyby": "^4.6.9",
51+
"@types/object-hash": "^3.0.6",
52+
"prettier": "^3.7.0",
53+
"typescript": "^5.9.3"
5454
}
5555
}

src/GenerateOptions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { FormatsPluginOptions } from 'ajv-formats';
1+
import { FormatsPluginOptions } from "ajv-formats";
22
import { Options } from "prettier";
33
import { SchemaType } from "./parse-schema";
44

@@ -30,7 +30,7 @@ export interface GenerateOptions {
3030
/**
3131
* adds the "ajv-formats" packages
3232
* @default false
33-
*/
33+
*/
3434
addFormats?: boolean;
3535

3636
/**

src/builder.ts

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,7 @@ type PropertyBaseOptions = Pick<
1818
"title" | "description" | "default"
1919
>;
2020

21-
type ObjectBaseOptions = Pick<
22-
JSONSchema,
23-
"title" | "description" | "default"
24-
>;
21+
type ObjectBaseOptions = Pick<JSONSchema, "title" | "description" | "default">;
2522

2623
type ArrayOptions = PropertyBaseOptions;
2724

@@ -64,24 +61,23 @@ export const boolean = (options: BooleanOptions = {}): PropertyValue => ({
6461
});
6562

6663
export const any = (options: JSONSchema = {}): PropertyValue => ({
67-
...options
68-
})
64+
...options,
65+
});
6966

7067
export const anonymousData = (options: JSONSchema): PropertyValue => ({
7168
additionalProperties: { type: "string" },
7269
...options,
7370
});
7471

75-
76-
const stringFormat = (format: FormatName) => (
77-
options: FormatOptions = {}
78-
): PropertyValue => {
79-
return {
80-
type: "string",
81-
format,
82-
...(options ?? {}),
72+
const stringFormat =
73+
(format: FormatName) =>
74+
(options: FormatOptions = {}): PropertyValue => {
75+
return {
76+
type: "string",
77+
format,
78+
...(options ?? {}),
79+
};
8380
};
84-
};
8581

8682
export const date = stringFormat("date");
8783
export const time = stringFormat("time");
@@ -133,7 +129,10 @@ export const ref = (refName: string): SchemaObject => ({
133129
const autoRef = (type: SchemaObjectOrRef): SchemaObject =>
134130
typeof type === "string" ? ref(type) : type;
135131

136-
export const array = (itemType: SchemaObjectOrRef, options: ArrayOptions = {}): SchemaObject => ({
132+
export const array = (
133+
itemType: SchemaObjectOrRef,
134+
options: ArrayOptions = {},
135+
): SchemaObject => ({
137136
type: "array",
138137
items: autoRef(itemType),
139138
...options,

src/generate.ts

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import keyby from "lodash.keyby";
22
import { parseSchema } from "./parse-schema";
3-
import { GenerateOptions } from "./GenerateOptions";
3+
import type { GenerateOptions } from "./GenerateOptions";
44
import { generateMetaFile } from "./generate/generate-meta";
55
import { generateCompileBasedDecoders } from "./generate/generate-compile-decoders";
66
import {
@@ -21,7 +21,7 @@ export async function generate(options: GenerateOptions) {
2121
: options.directory;
2222

2323
console.info(
24-
`Start generating files for ${schemaType} schema: ${schemaFile}`
24+
`Start generating files for ${schemaType} schema: ${schemaFile}`,
2525
);
2626

2727
const schema = await parseSchema(schemaFile, schemaType);
@@ -39,37 +39,37 @@ export async function generate(options: GenerateOptions) {
3939
});
4040

4141
if (options.skipDecoders !== true && definitionNames.length > 0) {
42-
generateAjvValidator(prettierOptions, directories);
42+
await generateAjvValidator(prettierOptions, directories);
4343

4444
if (!options.standalone) {
45-
generateCompileBasedDecoders(
45+
await generateCompileBasedDecoders(
4646
definitionNames,
4747
options.addFormats ?? false,
4848
options.formatOptions,
4949
directories,
50-
prettierOptions
50+
prettierOptions,
5151
);
5252
} else if (options.standalone.mergeDecoders === true) {
53-
generateStandaloneMergedDecoders(
53+
await generateStandaloneMergedDecoders(
5454
definitionNames,
5555
schema,
5656
options.addFormats ?? false,
5757
options.formatOptions,
5858
options.esm ? "module" : options.standalone.validatorOutput,
5959
options.esm ?? false,
6060
directories,
61-
prettierOptions
61+
prettierOptions,
6262
);
6363
} else {
64-
generateStandaloneDecoders(
64+
await generateStandaloneDecoders(
6565
definitionNames,
6666
schema,
6767
options.addFormats ?? false,
6868
options.formatOptions,
6969
options.esm ? "module" : options.standalone.validatorOutput,
7070
options.esm ?? false,
7171
directories,
72-
prettierOptions
72+
prettierOptions,
7373
);
7474
}
7575
}
@@ -78,12 +78,17 @@ export async function generate(options: GenerateOptions) {
7878
schema,
7979
{ skipSchemaFile: options.skipSchemaFile },
8080
prettierOptions,
81-
directories
81+
directories,
8282
);
83-
generateHelpers(prettierOptions, directories);
83+
await generateHelpers(prettierOptions, directories);
8484

8585
if (options.skipMetaFile !== true) {
86-
generateMetaFile(allDefinitions, directories, prettierOptions, options.esm ?? false);
86+
await generateMetaFile(
87+
allDefinitions,
88+
directories,
89+
prettierOptions,
90+
options.esm ?? false,
91+
);
8792
}
8893

8994
console.info(`Successfully generated files for ${schemaFile}`);

src/generate/generate-ajv-validator.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import { format, Options } from "prettier";
1+
import { format, type Options } from "prettier";
22
import { writeFileSync, mkdirSync } from "fs";
33
import path from "path";
44

5-
export function generateAjvValidator(
5+
export async function generateAjvValidator(
66
prettierOptions: Options,
7-
outDirs: string[]
7+
outDirs: string[],
88
) {
9-
const helpers = format(helpersTemplate, prettierOptions);
9+
const helpers = await format(helpersTemplate, prettierOptions);
1010

1111
outDirs.forEach((outDir) => {
1212
mkdirSync(outDir, { recursive: true });

src/generate/generate-compile-decoders.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,39 +4,39 @@ import path from "path";
44
import { createDecoderName } from "./generation-utils";
55
import { FormatsPluginOptions } from "ajv-formats";
66

7-
export function generateCompileBasedDecoders(
7+
export async function generateCompileBasedDecoders(
88
definitionNames: string[],
99
addFormats: boolean,
1010
formatOptions: FormatsPluginOptions | undefined,
1111
outDirs: string[],
12-
prettierOptions: Options
13-
): void {
12+
prettierOptions: Options,
13+
): Promise<void> {
1414
const decoders = definitionNames
1515
.map((definitionName) =>
1616
decoderTemplate
1717
.replace(/\$DecoderName/g, createDecoderName(definitionName))
1818
.replace(/\$Class/g, definitionName)
19-
.trim()
19+
.trim(),
2020
)
2121
.join("\n");
2222

2323
const rawDecoderOutput = decodersFileTemplate
2424
.replace(
2525
/\$Imports/g,
26-
addFormats ? 'import addFormats from "ajv-formats"' : ""
26+
addFormats ? 'import addFormats from "ajv-formats"' : "",
2727
)
2828
.replace(
2929
/\$Formats/g,
3030
addFormats
3131
? `addFormats(ajv, ${
3232
formatOptions ? JSON.stringify(formatOptions) : "undefined"
3333
});`
34-
: ""
34+
: "",
3535
)
3636
.replace(/\$ModelImports/g, definitionNames.join(", "))
3737
.replace(/\$Decoders/g, decoders);
3838

39-
const decoderOutput = format(rawDecoderOutput, prettierOptions);
39+
const decoderOutput = await format(rawDecoderOutput, prettierOptions);
4040

4141
outDirs.forEach((outDir) => {
4242
mkdirSync(outDir, { recursive: true });

src/generate/generate-helpers.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ import { format, Options } from "prettier";
22
import { writeFileSync, mkdirSync } from "fs";
33
import path from "path";
44

5-
export function generateHelpers(
5+
export async function generateHelpers(
66
prettierOptions: Options,
7-
outDirs: string[]
8-
) {
9-
const helpers = format(helpersTemplate, prettierOptions);
7+
outDirs: string[],
8+
): Promise<void> {
9+
const helpers = await format(helpersTemplate, prettierOptions);
1010

1111
outDirs.forEach((outDir) => {
1212
mkdirSync(outDir, { recursive: true });

src/generate/generate-meta.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ import { mkdirSync, writeFileSync } from "fs";
33
import path from "path";
44
import { ValidatorOutput } from "../GenerateOptions";
55

6-
export function generateMetaFile(
6+
export async function generateMetaFile(
77
definitionNames: string[],
88
outDirs: string[],
99
prettierOptions: Options,
10-
esm: boolean
11-
): void {
10+
esm: boolean,
11+
): Promise<void> {
1212
const metas = definitionNames
1313
.map((definitionName) => {
1414
return `${definitionName}: info<${definitionName}>('${definitionName}', '#/definitions/${definitionName}'),`;
@@ -17,9 +17,9 @@ export function generateMetaFile(
1717

1818
const rawOutput = metaTemplate(esm)
1919
.replace(/\$Definitions/g, metas)
20-
.replace(/\$ModelImports/g, definitionNames.join(", "))
20+
.replace(/\$ModelImports/g, definitionNames.join(", "));
2121

22-
const output = format(rawOutput, prettierOptions);
22+
const output = await format(rawOutput, prettierOptions);
2323

2424
outDirs.forEach((outDir) => {
2525
mkdirSync(outDir, { recursive: true });
@@ -45,5 +45,5 @@ export interface SchemaInfo<T> {
4545
function info<T>(definitionName: string, schemaRef: string): SchemaInfo<T> {
4646
return { definitionName, schemaRef };
4747
}
48-
`
49-
}
48+
`;
49+
};

src/generate/generate-models.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
import { mkdirSync, writeFileSync } from "fs";
2-
import path from 'path';
3-
import { compile } from 'json-schema-to-typescript';
4-
import { format, Options } from 'prettier';
5-
import { ParsedSchema } from '../parse-schema';
6-
import { GenerateOptions } from '../GenerateOptions';
2+
import path from "path";
3+
import { compile } from "json-schema-to-typescript";
4+
import { format, Options } from "prettier";
5+
import { ParsedSchema } from "../parse-schema";
6+
import { GenerateOptions } from "../GenerateOptions";
77

88
export async function generateModels(
99
schema: ParsedSchema,
10-
options: Pick<GenerateOptions, 'skipSchemaFile'>,
10+
options: Pick<GenerateOptions, "skipSchemaFile">,
1111
prettierOptions: Options,
12-
outDirs: string[]
12+
outDirs: string[],
1313
): Promise<void> {
1414
const compiledTypescriptModels = await compile(
1515
JSON.parse(schema.json),
16-
"Schema"
16+
"Schema",
1717
);
1818
const rawTypescriptModels = modelsFileTemplate
1919
.replace(/\$Models/g, compiledTypescriptModels)
2020
.replace(/\s*\[k: string\]: unknown;/g, "") // Allow additional properties in schema but not in typescript
2121
.replace(/export interface Schema \{[^]*?\n\}/, "");
2222

23-
const typescriptModels = format(rawTypescriptModels, prettierOptions);
23+
const typescriptModels = await format(rawTypescriptModels, prettierOptions);
2424

2525
outDirs.forEach((outDir) => {
2626
mkdirSync(outDir, { recursive: true });

0 commit comments

Comments
 (0)