@ng-openapi/zod 0.0.12-pr-92-feature-single-request-parameter-0b340a2.0 → 0.0.12-pr-103-refactored-d262edf.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.cjs +80 -134
- package/index.d.ts +167 -28
- package/index.js +80 -134
- package/package.json +1 -1
package/index.cjs
CHANGED
|
@@ -38,111 +38,6 @@ module.exports = __toCommonJS(index_exports);
|
|
|
38
38
|
// src/lib/zod.generator.ts
|
|
39
39
|
var path2 = __toESM(require("path"), 1);
|
|
40
40
|
|
|
41
|
-
// ../../shared/src/utils/string.utils.ts
|
|
42
|
-
function camelCase(str2) {
|
|
43
|
-
return str2.replace(/[-_\s]+(.)?/g, (_, char) => char ? char.toUpperCase() : "").replace(/^./, (char) => char.toLowerCase());
|
|
44
|
-
}
|
|
45
|
-
__name(camelCase, "camelCase");
|
|
46
|
-
function pascalCase(str2) {
|
|
47
|
-
return str2.replace(/[-_\s]+(.)?/g, (_, char) => char ? char.toUpperCase() : "").replace(/^./, (char) => char.toUpperCase());
|
|
48
|
-
}
|
|
49
|
-
__name(pascalCase, "pascalCase");
|
|
50
|
-
|
|
51
|
-
// ../../shared/src/utils/functions/extract-paths.ts
|
|
52
|
-
function extractPaths(swaggerPaths = {}, methods = [
|
|
53
|
-
"get",
|
|
54
|
-
"post",
|
|
55
|
-
"put",
|
|
56
|
-
"patch",
|
|
57
|
-
"delete",
|
|
58
|
-
"options",
|
|
59
|
-
"head"
|
|
60
|
-
]) {
|
|
61
|
-
const paths = [];
|
|
62
|
-
Object.entries(swaggerPaths).forEach(([path3, pathItem]) => {
|
|
63
|
-
methods.forEach((method) => {
|
|
64
|
-
if (pathItem[method]) {
|
|
65
|
-
const operation = pathItem[method];
|
|
66
|
-
paths.push({
|
|
67
|
-
path: path3,
|
|
68
|
-
method: method.toUpperCase(),
|
|
69
|
-
operationId: operation.operationId,
|
|
70
|
-
summary: operation.summary,
|
|
71
|
-
description: operation.description,
|
|
72
|
-
tags: operation.tags || [],
|
|
73
|
-
parameters: parseParameters(operation.parameters || [], pathItem.parameters || []),
|
|
74
|
-
requestBody: operation.requestBody,
|
|
75
|
-
responses: operation.responses || {}
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
});
|
|
79
|
-
});
|
|
80
|
-
return paths;
|
|
81
|
-
}
|
|
82
|
-
__name(extractPaths, "extractPaths");
|
|
83
|
-
function parseParameters(operationParams, pathParams) {
|
|
84
|
-
const allParams = [
|
|
85
|
-
...pathParams,
|
|
86
|
-
...operationParams
|
|
87
|
-
];
|
|
88
|
-
return allParams.map((param) => ({
|
|
89
|
-
name: param.name,
|
|
90
|
-
in: param.in,
|
|
91
|
-
required: param.required || param.in === "path",
|
|
92
|
-
schema: param.schema,
|
|
93
|
-
type: param.type,
|
|
94
|
-
format: param.format,
|
|
95
|
-
description: param.description
|
|
96
|
-
}));
|
|
97
|
-
}
|
|
98
|
-
__name(parseParameters, "parseParameters");
|
|
99
|
-
|
|
100
|
-
// ../../shared/src/utils/content-types.constants.ts
|
|
101
|
-
var CONTENT_TYPES = {
|
|
102
|
-
MULTIPART: "multipart/form-data",
|
|
103
|
-
FORM_URLENCODED: "application/x-www-form-urlencoded",
|
|
104
|
-
JSON: "application/json"
|
|
105
|
-
};
|
|
106
|
-
|
|
107
|
-
// ../../shared/src/config/constants.ts
|
|
108
|
-
var disableLinting = `/* @ts-nocheck */
|
|
109
|
-
/* eslint-disable */
|
|
110
|
-
/* @noformat */
|
|
111
|
-
/* @formatter:off */
|
|
112
|
-
`;
|
|
113
|
-
var authorComment = `/**
|
|
114
|
-
* Generated by ng-openapi
|
|
115
|
-
`;
|
|
116
|
-
var defaultHeaderComment = disableLinting + authorComment;
|
|
117
|
-
var TYPE_GENERATOR_HEADER_COMMENT = defaultHeaderComment + `* Generated TypeScript interfaces from Swagger specification
|
|
118
|
-
* Do not edit this file manually
|
|
119
|
-
*/
|
|
120
|
-
`;
|
|
121
|
-
var SERVICE_INDEX_GENERATOR_HEADER_COMMENT = defaultHeaderComment + `* Generated service exports
|
|
122
|
-
* Do not edit this file manually
|
|
123
|
-
*/
|
|
124
|
-
`;
|
|
125
|
-
var REQUEST_PARAMS_GENERATOR_HEADER_COMMENT = defaultHeaderComment + `* Generated request parameter interfaces
|
|
126
|
-
* Do not edit this file manually
|
|
127
|
-
*/
|
|
128
|
-
`;
|
|
129
|
-
var MAIN_INDEX_GENERATOR_HEADER_COMMENT = defaultHeaderComment + `* Entrypoint for the client
|
|
130
|
-
* Do not edit this file manually
|
|
131
|
-
*/
|
|
132
|
-
`;
|
|
133
|
-
var PROVIDER_GENERATOR_HEADER_COMMENT = defaultHeaderComment + `* Generated provider functions for easy setup
|
|
134
|
-
* Do not edit this file manually
|
|
135
|
-
*/
|
|
136
|
-
`;
|
|
137
|
-
var ZOD_PLUGIN_GENERATOR_HEADER_COMMENT = /* @__PURE__ */ __name((validatorName) => defaultHeaderComment + `* Generated Zod Schemas for ${validatorName}
|
|
138
|
-
* Do not edit this file manually
|
|
139
|
-
*/
|
|
140
|
-
`, "ZOD_PLUGIN_GENERATOR_HEADER_COMMENT");
|
|
141
|
-
var ZOD_PLUGIN_INDEX_GENERATOR_HEADER_COMMENT = defaultHeaderComment + `* Generated Zod Schemas exports
|
|
142
|
-
* Do not edit this file manually
|
|
143
|
-
*/
|
|
144
|
-
`;
|
|
145
|
-
|
|
146
41
|
// ../../../node_modules/js-yaml/dist/js-yaml.mjs
|
|
147
42
|
function isNothing(subject) {
|
|
148
43
|
return typeof subject === "undefined" || subject === null;
|
|
@@ -2845,9 +2740,65 @@ var safeLoad = renamed("safeLoad", "load");
|
|
|
2845
2740
|
var safeLoadAll = renamed("safeLoadAll", "loadAll");
|
|
2846
2741
|
var safeDump = renamed("safeDump", "dump");
|
|
2847
2742
|
|
|
2743
|
+
// ../../shared/src/utils/content-types.constants.ts
|
|
2744
|
+
var CONTENT_TYPES = {
|
|
2745
|
+
MULTIPART: "multipart/form-data",
|
|
2746
|
+
FORM_URLENCODED: "application/x-www-form-urlencoded",
|
|
2747
|
+
JSON: "application/json"
|
|
2748
|
+
};
|
|
2749
|
+
|
|
2750
|
+
// ../../shared/src/utils/string.utils.ts
|
|
2751
|
+
function camelCase(str2) {
|
|
2752
|
+
return str2.replace(/[-_.\s]+(.)?/g, (_, char) => char ? char.toUpperCase() : "").replace(/^./, (char) => char.toLowerCase());
|
|
2753
|
+
}
|
|
2754
|
+
__name(camelCase, "camelCase");
|
|
2755
|
+
function pascalCase(str2) {
|
|
2756
|
+
return str2.replace(/[-_.\s]+(.)?/g, (_, char) => char ? char.toUpperCase() : "").replace(/^./, (char) => char.toUpperCase());
|
|
2757
|
+
}
|
|
2758
|
+
__name(pascalCase, "pascalCase");
|
|
2759
|
+
|
|
2760
|
+
// ../../shared/src/config/constants.ts
|
|
2761
|
+
var disableLinting = `/* @ts-nocheck */
|
|
2762
|
+
/* eslint-disable */
|
|
2763
|
+
/* @noformat */
|
|
2764
|
+
/* @formatter:off */
|
|
2765
|
+
`;
|
|
2766
|
+
var authorComment = `/**
|
|
2767
|
+
* Generated by ng-openapi
|
|
2768
|
+
`;
|
|
2769
|
+
var defaultHeaderComment = disableLinting + authorComment;
|
|
2770
|
+
var TYPE_GENERATOR_HEADER_COMMENT = defaultHeaderComment + `* Generated TypeScript interfaces from Swagger specification
|
|
2771
|
+
* Do not edit this file manually
|
|
2772
|
+
*/
|
|
2773
|
+
`;
|
|
2774
|
+
var SERVICE_INDEX_GENERATOR_HEADER_COMMENT = defaultHeaderComment + `* Generated service exports
|
|
2775
|
+
* Do not edit this file manually
|
|
2776
|
+
*/
|
|
2777
|
+
`;
|
|
2778
|
+
var REQUEST_PARAMS_GENERATOR_HEADER_COMMENT = defaultHeaderComment + `* Generated request parameter interfaces
|
|
2779
|
+
* Do not edit this file manually
|
|
2780
|
+
*/
|
|
2781
|
+
`;
|
|
2782
|
+
var MAIN_INDEX_GENERATOR_HEADER_COMMENT = defaultHeaderComment + `* Entrypoint for the client
|
|
2783
|
+
* Do not edit this file manually
|
|
2784
|
+
*/
|
|
2785
|
+
`;
|
|
2786
|
+
var PROVIDER_GENERATOR_HEADER_COMMENT = defaultHeaderComment + `* Generated provider functions for easy setup
|
|
2787
|
+
* Do not edit this file manually
|
|
2788
|
+
*/
|
|
2789
|
+
`;
|
|
2790
|
+
var ZOD_PLUGIN_GENERATOR_HEADER_COMMENT = /* @__PURE__ */ __name((validatorName) => defaultHeaderComment + `* Generated Zod Schemas for ${validatorName}
|
|
2791
|
+
* Do not edit this file manually
|
|
2792
|
+
*/
|
|
2793
|
+
`, "ZOD_PLUGIN_GENERATOR_HEADER_COMMENT");
|
|
2794
|
+
var ZOD_PLUGIN_INDEX_GENERATOR_HEADER_COMMENT = defaultHeaderComment + `* Generated Zod Schemas exports
|
|
2795
|
+
* Do not edit this file manually
|
|
2796
|
+
*/
|
|
2797
|
+
`;
|
|
2798
|
+
|
|
2848
2799
|
// src/lib/utils/is-reference-object.ts
|
|
2849
2800
|
function isReferenceObject(obj) {
|
|
2850
|
-
return
|
|
2801
|
+
return typeof obj === "object" && obj !== null && "$ref" in obj;
|
|
2851
2802
|
}
|
|
2852
2803
|
__name(isReferenceObject, "isReferenceObject");
|
|
2853
2804
|
|
|
@@ -2856,17 +2807,17 @@ var ZodSchemaBuilder = class {
|
|
|
2856
2807
|
static {
|
|
2857
2808
|
__name(this, "ZodSchemaBuilder");
|
|
2858
2809
|
}
|
|
2859
|
-
|
|
2810
|
+
spec;
|
|
2860
2811
|
config;
|
|
2861
2812
|
options;
|
|
2862
|
-
constructor(
|
|
2863
|
-
this.
|
|
2813
|
+
constructor(spec, config, options) {
|
|
2814
|
+
this.spec = spec;
|
|
2864
2815
|
this.config = config;
|
|
2865
2816
|
this.options = options;
|
|
2866
2817
|
}
|
|
2867
2818
|
async buildSchema(schema2, name, buildOptions = {}) {
|
|
2868
2819
|
if (isReferenceObject(schema2)) {
|
|
2869
|
-
const resolved = this.
|
|
2820
|
+
const resolved = this.spec.resolveReference(schema2.$ref);
|
|
2870
2821
|
return this.buildSchema(resolved, name, buildOptions);
|
|
2871
2822
|
}
|
|
2872
2823
|
if (buildOptions.removeReadOnly && schema2.properties) {
|
|
@@ -2912,7 +2863,7 @@ var ZodSchemaBuilder = class {
|
|
|
2912
2863
|
}
|
|
2913
2864
|
async buildStringSchema(schema2, buildOptions) {
|
|
2914
2865
|
if (schema2.enum && schema2.enum.every((v) => typeof v === "string")) {
|
|
2915
|
-
const enumValues = schema2.enum.map((v) => `'${this.escapeString(v)}'`).join(", ");
|
|
2866
|
+
const enumValues = schema2.enum.map((v) => `'${this.escapeString(String(v))}'`).join(", ");
|
|
2916
2867
|
return `z.enum([${enumValues}])`;
|
|
2917
2868
|
}
|
|
2918
2869
|
if (schema2.format) {
|
|
@@ -3067,8 +3018,7 @@ ${properties.join(",\n")}
|
|
|
3067
3018
|
...schema2
|
|
3068
3019
|
};
|
|
3069
3020
|
filtered.properties = Object.entries(schema2.properties).reduce((acc, [key, value]) => {
|
|
3070
|
-
|
|
3071
|
-
if (!propSchema.readOnly) {
|
|
3021
|
+
if (!value.readOnly) {
|
|
3072
3022
|
acc[key] = value;
|
|
3073
3023
|
}
|
|
3074
3024
|
return acc;
|
|
@@ -3119,15 +3069,15 @@ var ZodSchemaGenerator = class {
|
|
|
3119
3069
|
static {
|
|
3120
3070
|
__name(this, "ZodSchemaGenerator");
|
|
3121
3071
|
}
|
|
3122
|
-
|
|
3072
|
+
spec;
|
|
3123
3073
|
config;
|
|
3124
3074
|
options;
|
|
3125
3075
|
schemaBuilder;
|
|
3126
|
-
constructor(
|
|
3127
|
-
this.
|
|
3076
|
+
constructor(spec, config, options) {
|
|
3077
|
+
this.spec = spec;
|
|
3128
3078
|
this.config = config;
|
|
3129
3079
|
this.options = options;
|
|
3130
|
-
this.schemaBuilder = new ZodSchemaBuilder(
|
|
3080
|
+
this.schemaBuilder = new ZodSchemaBuilder(spec, config, options);
|
|
3131
3081
|
}
|
|
3132
3082
|
async generateParametersValidator(parameters, operationName, suffix) {
|
|
3133
3083
|
const properties = {};
|
|
@@ -3253,21 +3203,21 @@ var ZodSchemaGenerator = class {
|
|
|
3253
3203
|
}
|
|
3254
3204
|
resolveRequestBody(requestBody) {
|
|
3255
3205
|
if (isReferenceObject(requestBody)) {
|
|
3256
|
-
const resolved = this.
|
|
3206
|
+
const resolved = this.spec.resolveReference(requestBody.$ref);
|
|
3257
3207
|
return resolved;
|
|
3258
3208
|
}
|
|
3259
3209
|
return requestBody;
|
|
3260
3210
|
}
|
|
3261
3211
|
resolveResponse(response) {
|
|
3262
3212
|
if (isReferenceObject(response)) {
|
|
3263
|
-
const resolved = this.
|
|
3213
|
+
const resolved = this.spec.resolveReference(response.$ref);
|
|
3264
3214
|
return resolved;
|
|
3265
3215
|
}
|
|
3266
3216
|
return response;
|
|
3267
3217
|
}
|
|
3268
3218
|
resolveSchema(schema2) {
|
|
3269
3219
|
if (isReferenceObject(schema2)) {
|
|
3270
|
-
const resolved = this.
|
|
3220
|
+
const resolved = this.spec.resolveReference(schema2.$ref);
|
|
3271
3221
|
return resolved;
|
|
3272
3222
|
}
|
|
3273
3223
|
return schema2;
|
|
@@ -3350,33 +3300,29 @@ var ZodGenerator = class {
|
|
|
3350
3300
|
__name(this, "ZodGenerator");
|
|
3351
3301
|
}
|
|
3352
3302
|
project;
|
|
3353
|
-
parser;
|
|
3354
3303
|
spec;
|
|
3355
3304
|
config;
|
|
3356
3305
|
options;
|
|
3357
3306
|
schemaGenerator;
|
|
3358
3307
|
indexGenerator;
|
|
3359
|
-
|
|
3360
|
-
|
|
3361
|
-
this.
|
|
3362
|
-
this.
|
|
3363
|
-
this.spec =
|
|
3308
|
+
onWarning;
|
|
3309
|
+
constructor(context, options) {
|
|
3310
|
+
this.config = context.config;
|
|
3311
|
+
this.project = context.project;
|
|
3312
|
+
this.spec = context.spec;
|
|
3313
|
+
this.onWarning = context.onWarning;
|
|
3364
3314
|
this.options = {
|
|
3365
3315
|
...DEFAULT_OPTIONS,
|
|
3366
3316
|
...options
|
|
3367
3317
|
};
|
|
3368
|
-
|
|
3369
|
-
|
|
3370
|
-
throw new Error(`Invalid or unsupported specification format. Expected OpenAPI 3.x or Swagger 2.x. ${versionInfo ? `Found: ${versionInfo.type} ${versionInfo.version}` : "No version info found"}`);
|
|
3371
|
-
}
|
|
3372
|
-
this.schemaGenerator = new ZodSchemaGenerator(this.parser, this.config, this.options);
|
|
3373
|
-
this.indexGenerator = new ZodIndexGenerator(project);
|
|
3318
|
+
this.schemaGenerator = new ZodSchemaGenerator(context.spec, this.config, this.options);
|
|
3319
|
+
this.indexGenerator = new ZodIndexGenerator(context.project);
|
|
3374
3320
|
}
|
|
3375
3321
|
async generate(outputRoot) {
|
|
3376
3322
|
const outputDir = path2.join(outputRoot, "validators");
|
|
3377
|
-
const paths =
|
|
3323
|
+
const paths = this.spec.operations;
|
|
3378
3324
|
if (paths.length === 0) {
|
|
3379
|
-
|
|
3325
|
+
this.onWarning?.("No API paths found in the specification");
|
|
3380
3326
|
return;
|
|
3381
3327
|
}
|
|
3382
3328
|
const controllerGroups = this.groupPathsByController(paths);
|
package/index.d.ts
CHANGED
|
@@ -1,18 +1,79 @@
|
|
|
1
|
-
import { ScriptTarget, ModuleKind
|
|
2
|
-
import {
|
|
1
|
+
import { Project, ScriptTarget, ModuleKind } from 'ts-morph';
|
|
2
|
+
import { ParameterType, XML, ExternalDocs, Info, Path, BodyParameter, QueryParameter, Security, Tag } from 'swagger-schema-official';
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* An operation parameter. OpenAPI 3.x carries the type in `schema`;
|
|
6
|
+
* Swagger 2.0 puts `type`/`format` directly on the parameter — consumers
|
|
7
|
+
* must handle both (or use the normalized model, which precomputes them).
|
|
8
|
+
*/
|
|
9
|
+
interface Parameter {
|
|
10
|
+
name: string;
|
|
11
|
+
in: "query" | "path" | "header" | "cookie";
|
|
12
|
+
required?: boolean;
|
|
13
|
+
schema?: SwaggerDefinition;
|
|
14
|
+
type?: string;
|
|
15
|
+
format?: string;
|
|
16
|
+
description?: string;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* One operation of the spec, flattened to (path, method). Raw-ish view —
|
|
20
|
+
* generators consume its precomputed extension NormalizedOperation instead.
|
|
21
|
+
*/
|
|
22
|
+
interface PathInfo {
|
|
23
|
+
path: string;
|
|
24
|
+
method: string;
|
|
25
|
+
operationId?: string;
|
|
26
|
+
summary?: string;
|
|
27
|
+
description?: string;
|
|
28
|
+
tags?: string[];
|
|
29
|
+
parameters?: Parameter[];
|
|
30
|
+
requestBody?: RequestBody;
|
|
31
|
+
responses?: Record<string, SwaggerResponse>;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Operation request body, keyed by content type — the OpenAPI 3.x shape.
|
|
35
|
+
* Swagger 2.0 `in: "body"` parameters are NOT yet lifted into this shape;
|
|
36
|
+
* 2.0 operations currently generate without a body parameter.
|
|
37
|
+
*/
|
|
38
|
+
interface RequestBody {
|
|
39
|
+
required?: boolean;
|
|
40
|
+
content?: Record<string, {
|
|
41
|
+
schema?: SwaggerDefinition;
|
|
42
|
+
}>;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* A single response entry, keyed by content type — the OpenAPI 3.x shape.
|
|
46
|
+
* A Swagger 2.0 response's direct `schema` is NOT yet mapped into `content`;
|
|
47
|
+
* 2.0 responses currently type as `any`.
|
|
48
|
+
*/
|
|
4
49
|
interface SwaggerResponse {
|
|
5
50
|
description?: string;
|
|
6
51
|
content?: Record<string, {
|
|
7
|
-
schema?:
|
|
52
|
+
schema?: SwaggerDefinition;
|
|
8
53
|
}>;
|
|
9
54
|
}
|
|
55
|
+
/** OpenAPI 3.x security scheme (subset of the spec's fields). */
|
|
56
|
+
interface OpenApiSecurityScheme {
|
|
57
|
+
type?: "apiKey" | "http" | "oauth2" | "openIdConnect";
|
|
58
|
+
description?: string;
|
|
59
|
+
name?: string;
|
|
60
|
+
in?: "query" | "header" | "cookie";
|
|
61
|
+
scheme?: string;
|
|
62
|
+
bearerFormat?: string;
|
|
63
|
+
flows?: Record<string, unknown>;
|
|
64
|
+
openIdConnectUrl?: string;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* A JSON-Schema-ish definition as it appears in the spec, shared by
|
|
68
|
+
* Swagger 2.0 and OpenAPI 3.x (3.0's `nullable` and 3.1's type arrays
|
|
69
|
+
* both flow through `type`/`nullable`). May contain unresolved `$ref`s.
|
|
70
|
+
*/
|
|
10
71
|
interface SwaggerDefinition {
|
|
11
72
|
type?: ParameterType | undefined;
|
|
12
73
|
format?: string | undefined;
|
|
13
74
|
title?: string | undefined;
|
|
14
75
|
description?: string | undefined;
|
|
15
|
-
default?:
|
|
76
|
+
default?: unknown;
|
|
16
77
|
multipleOf?: number | undefined;
|
|
17
78
|
maximum?: number | undefined;
|
|
18
79
|
exclusiveMaximum?: boolean | undefined;
|
|
@@ -26,7 +87,9 @@ interface SwaggerDefinition {
|
|
|
26
87
|
uniqueItems?: boolean | undefined;
|
|
27
88
|
maxProperties?: number | undefined;
|
|
28
89
|
minProperties?: number | undefined;
|
|
29
|
-
enum?:
|
|
90
|
+
enum?: Array<string | number> | undefined;
|
|
91
|
+
/** OpenAPI 3.1 (JSON Schema); normalizeSchema folds it into a single-value `enum`. */
|
|
92
|
+
const?: unknown;
|
|
30
93
|
items?: SwaggerDefinition | SwaggerDefinition[] | undefined;
|
|
31
94
|
$ref?: string | undefined;
|
|
32
95
|
allOf?: SwaggerDefinition[] | undefined;
|
|
@@ -39,11 +102,16 @@ interface SwaggerDefinition {
|
|
|
39
102
|
nullable?: boolean | undefined;
|
|
40
103
|
xml?: XML | undefined;
|
|
41
104
|
externalDocs?: ExternalDocs | undefined;
|
|
42
|
-
example?:
|
|
105
|
+
example?: unknown;
|
|
43
106
|
required?: string[] | undefined;
|
|
44
107
|
oneOf?: SwaggerDefinition[];
|
|
45
108
|
anyOf?: SwaggerDefinition[];
|
|
46
109
|
}
|
|
110
|
+
/**
|
|
111
|
+
* The raw parsed spec document. Exactly one of `swagger` ("2.x") or
|
|
112
|
+
* `openapi` ("3.x") identifies the version; everything version-specific
|
|
113
|
+
* is resolved once by normalizeSpec.
|
|
114
|
+
*/
|
|
47
115
|
interface SwaggerSpec {
|
|
48
116
|
openapi: string;
|
|
49
117
|
swagger: string;
|
|
@@ -75,67 +143,138 @@ interface SwaggerSpec {
|
|
|
75
143
|
tags?: Tag[] | undefined;
|
|
76
144
|
components?: {
|
|
77
145
|
schemas?: Record<string, SwaggerDefinition>;
|
|
146
|
+
securitySchemes?: Record<string, OpenApiSecurityScheme | Security>;
|
|
78
147
|
};
|
|
79
148
|
}
|
|
80
149
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
150
|
+
type ResponseKind = "json" | "blob" | "arraybuffer" | "text";
|
|
151
|
+
/**
|
|
152
|
+
* A spec operation with everything the generators need precomputed once at
|
|
153
|
+
* normalization time. Generators must not re-derive any of these fields or
|
|
154
|
+
* resolve $refs during emission — that is exactly the duplication this model
|
|
155
|
+
* exists to remove (REFACTORING_PLAN.md phase 2.2).
|
|
156
|
+
*/
|
|
157
|
+
interface NormalizedOperation extends PathInfo {
|
|
158
|
+
/** parameters with in === "path" */
|
|
159
|
+
pathParams: Parameter[];
|
|
160
|
+
/** parameters with in === "query" */
|
|
161
|
+
queryParams: Parameter[];
|
|
162
|
+
hasBody: boolean;
|
|
163
|
+
isMultipart: boolean;
|
|
164
|
+
/** urlencoded body without a JSON alternative */
|
|
165
|
+
isUrlEncoded: boolean;
|
|
166
|
+
/** ref-resolved multipart body schema (set only when isMultipart) */
|
|
167
|
+
formDataSchema?: SwaggerDefinition;
|
|
168
|
+
/** field names of formDataSchema's properties */
|
|
169
|
+
formDataFields: string[];
|
|
170
|
+
/** ref-resolved urlencoded body schema (set only when isUrlEncoded) */
|
|
171
|
+
urlEncodedSchema?: SwaggerDefinition;
|
|
172
|
+
/** field names of urlEncodedSchema's properties */
|
|
173
|
+
urlEncodedFields: string[];
|
|
174
|
+
/** derived from the first success response (200/201/202/204/206) */
|
|
175
|
+
responseType: ResponseKind;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/** Detected spec flavor and its literal version string (e.g. openapi "3.0.3"). */
|
|
179
|
+
interface SpecVersion {
|
|
180
|
+
type: "swagger" | "openapi";
|
|
181
|
+
version: string;
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Version-free view of a parsed spec: Swagger 2.0 vs OpenAPI 3.x differences
|
|
185
|
+
* are resolved once at normalization time. Generators consume this instead of
|
|
186
|
+
* touching the raw SwaggerSpec.
|
|
187
|
+
*/
|
|
188
|
+
interface NormalizedSpec {
|
|
189
|
+
version: SpecVersion | null;
|
|
190
|
+
/** 2.0 `definitions` or 3.x `components.schemas`, whichever the spec has */
|
|
191
|
+
definitions: Record<string, SwaggerDefinition>;
|
|
192
|
+
operations: NormalizedOperation[];
|
|
193
|
+
/** Lookup for "#/definitions/X" and "#/components/schemas/X" style refs */
|
|
91
194
|
resolveReference(ref: string): SwaggerDefinition | undefined;
|
|
92
|
-
getAllDefinitionNames(): string[];
|
|
93
|
-
getSpec(): SwaggerSpec;
|
|
94
|
-
getPaths(): Record<string, any>;
|
|
95
|
-
isValidSpec(): boolean;
|
|
96
|
-
getSpecVersion(): {
|
|
97
|
-
type: "swagger" | "openapi";
|
|
98
|
-
version: string;
|
|
99
|
-
} | null;
|
|
100
195
|
}
|
|
101
196
|
|
|
197
|
+
/**
|
|
198
|
+
* Everything a plugin generator receives from the orchestrator.
|
|
199
|
+
*
|
|
200
|
+
* Plugins consume the version-free NormalizedSpec — never the raw spec or the
|
|
201
|
+
* SwaggerParser — and emit through the shared ts-morph Project so the
|
|
202
|
+
* orchestrator can track written files.
|
|
203
|
+
*/
|
|
204
|
+
interface PluginGeneratorContext {
|
|
205
|
+
/** Version-free spec model; $refs resolved, per-operation fields precomputed. */
|
|
206
|
+
spec: NormalizedSpec;
|
|
207
|
+
/** Shared ts-morph project all generators emit through. */
|
|
208
|
+
project: Project;
|
|
209
|
+
/** Full user-facing config; plugins should read only the slice they need. */
|
|
210
|
+
config: GeneratorConfig;
|
|
211
|
+
/** Sink for non-fatal diagnostics — plugins must never log directly. */
|
|
212
|
+
onWarning?: (message: string) => void;
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Constructor contract for plugin generator classes (what GeneratorConfig.plugins accepts).
|
|
216
|
+
*/
|
|
217
|
+
interface IPluginGeneratorClass {
|
|
218
|
+
new (context: PluginGeneratorContext): IPluginGenerator;
|
|
219
|
+
}
|
|
102
220
|
/**
|
|
103
221
|
* Interface for generator instances
|
|
104
222
|
*/
|
|
105
223
|
interface IPluginGenerator {
|
|
106
224
|
/**
|
|
107
|
-
* Generate code files
|
|
225
|
+
* Generate code files under the given output root.
|
|
108
226
|
*/
|
|
109
227
|
generate(outputRoot: string): Promise<void>;
|
|
110
228
|
}
|
|
111
229
|
|
|
230
|
+
/**
|
|
231
|
+
* The user-facing configuration (config file or programmatic call).
|
|
232
|
+
* Validated at the boundary by validateGeneratorConfig, which throws
|
|
233
|
+
* ConfigValidationError listing every problem at once — see
|
|
234
|
+
* https://ng-openapi.dev for full option documentation.
|
|
235
|
+
*/
|
|
112
236
|
interface GeneratorConfig {
|
|
237
|
+
/** Path or http(s) URL of the OpenAPI 3.x / Swagger 2.x spec (.json/.yaml/.yml). */
|
|
113
238
|
input: string;
|
|
239
|
+
/** Output directory; created if missing. */
|
|
114
240
|
output: string;
|
|
241
|
+
/** Distinguishes tokens/providers when several clients coexist in one app. */
|
|
115
242
|
clientName?: string;
|
|
243
|
+
/** Custom acceptance check run on the parsed spec; returning false aborts generation. */
|
|
116
244
|
validateInput?: (spec: SwaggerSpec) => boolean;
|
|
117
245
|
options: {
|
|
246
|
+
/** How date/date-time formats are typed in generated models. */
|
|
118
247
|
dateType: "string" | "Date";
|
|
248
|
+
/** Emit TS enums or literal-union types for spec enums. */
|
|
119
249
|
enumStyle: "enum" | "union";
|
|
120
250
|
validation?: {
|
|
251
|
+
/** Adds a `parse` hook to RequestOptions for response validation. */
|
|
121
252
|
response?: boolean;
|
|
122
253
|
};
|
|
254
|
+
/** Set false to generate models only. Default: true. */
|
|
123
255
|
generateServices?: boolean;
|
|
256
|
+
/** Read enum member names from JSON-encoded descriptions (see EnumValueObject). */
|
|
124
257
|
generateEnumBasedOnDescription?: boolean;
|
|
258
|
+
/** Default headers added to every request when not already present. */
|
|
125
259
|
customHeaders?: Record<string, string>;
|
|
260
|
+
/** Pin the Angular responseType per response content type. */
|
|
126
261
|
responseTypeMapping?: {
|
|
127
262
|
[contentType: string]: "json" | "blob" | "arraybuffer" | "text";
|
|
128
263
|
};
|
|
264
|
+
/** Derive method names from operationIds; throws when an operation has none. */
|
|
129
265
|
customizeMethodName?: (operationId: string) => string;
|
|
266
|
+
/** Collapse each method's parameters into a single request object. */
|
|
130
267
|
useSingleRequestParameter?: boolean;
|
|
131
268
|
};
|
|
269
|
+
/** Overrides for the ts-morph compiler settings used during generation. */
|
|
132
270
|
compilerOptions?: {
|
|
133
271
|
declaration?: boolean;
|
|
134
272
|
target?: ScriptTarget;
|
|
135
273
|
module?: ModuleKind;
|
|
136
274
|
strict?: boolean;
|
|
137
275
|
};
|
|
138
|
-
|
|
276
|
+
/** Plugin generator classes, run after core generation (see PluginGeneratorContext). */
|
|
277
|
+
plugins?: IPluginGeneratorClass[];
|
|
139
278
|
}
|
|
140
279
|
|
|
141
280
|
interface ZodPluginOptions {
|
|
@@ -172,13 +311,13 @@ interface ZodPluginOptions {
|
|
|
172
311
|
|
|
173
312
|
declare class ZodGenerator implements IPluginGenerator {
|
|
174
313
|
private project;
|
|
175
|
-
private parser;
|
|
176
314
|
private spec;
|
|
177
315
|
private config;
|
|
178
316
|
private options;
|
|
179
317
|
private schemaGenerator;
|
|
180
318
|
private indexGenerator;
|
|
181
|
-
|
|
319
|
+
private readonly onWarning?;
|
|
320
|
+
constructor(context: PluginGeneratorContext, options?: ZodPluginOptions);
|
|
182
321
|
generate(outputRoot: string): Promise<void>;
|
|
183
322
|
private groupPathsByController;
|
|
184
323
|
private generateValidatorFile;
|
package/index.js
CHANGED
|
@@ -4,111 +4,6 @@ var __name = (target, value) => __defProp(target, "name", { value, configurable:
|
|
|
4
4
|
// src/lib/zod.generator.ts
|
|
5
5
|
import * as path2 from "path";
|
|
6
6
|
|
|
7
|
-
// ../../shared/src/utils/string.utils.ts
|
|
8
|
-
function camelCase(str2) {
|
|
9
|
-
return str2.replace(/[-_\s]+(.)?/g, (_, char) => char ? char.toUpperCase() : "").replace(/^./, (char) => char.toLowerCase());
|
|
10
|
-
}
|
|
11
|
-
__name(camelCase, "camelCase");
|
|
12
|
-
function pascalCase(str2) {
|
|
13
|
-
return str2.replace(/[-_\s]+(.)?/g, (_, char) => char ? char.toUpperCase() : "").replace(/^./, (char) => char.toUpperCase());
|
|
14
|
-
}
|
|
15
|
-
__name(pascalCase, "pascalCase");
|
|
16
|
-
|
|
17
|
-
// ../../shared/src/utils/functions/extract-paths.ts
|
|
18
|
-
function extractPaths(swaggerPaths = {}, methods = [
|
|
19
|
-
"get",
|
|
20
|
-
"post",
|
|
21
|
-
"put",
|
|
22
|
-
"patch",
|
|
23
|
-
"delete",
|
|
24
|
-
"options",
|
|
25
|
-
"head"
|
|
26
|
-
]) {
|
|
27
|
-
const paths = [];
|
|
28
|
-
Object.entries(swaggerPaths).forEach(([path3, pathItem]) => {
|
|
29
|
-
methods.forEach((method) => {
|
|
30
|
-
if (pathItem[method]) {
|
|
31
|
-
const operation = pathItem[method];
|
|
32
|
-
paths.push({
|
|
33
|
-
path: path3,
|
|
34
|
-
method: method.toUpperCase(),
|
|
35
|
-
operationId: operation.operationId,
|
|
36
|
-
summary: operation.summary,
|
|
37
|
-
description: operation.description,
|
|
38
|
-
tags: operation.tags || [],
|
|
39
|
-
parameters: parseParameters(operation.parameters || [], pathItem.parameters || []),
|
|
40
|
-
requestBody: operation.requestBody,
|
|
41
|
-
responses: operation.responses || {}
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
|
-
});
|
|
46
|
-
return paths;
|
|
47
|
-
}
|
|
48
|
-
__name(extractPaths, "extractPaths");
|
|
49
|
-
function parseParameters(operationParams, pathParams) {
|
|
50
|
-
const allParams = [
|
|
51
|
-
...pathParams,
|
|
52
|
-
...operationParams
|
|
53
|
-
];
|
|
54
|
-
return allParams.map((param) => ({
|
|
55
|
-
name: param.name,
|
|
56
|
-
in: param.in,
|
|
57
|
-
required: param.required || param.in === "path",
|
|
58
|
-
schema: param.schema,
|
|
59
|
-
type: param.type,
|
|
60
|
-
format: param.format,
|
|
61
|
-
description: param.description
|
|
62
|
-
}));
|
|
63
|
-
}
|
|
64
|
-
__name(parseParameters, "parseParameters");
|
|
65
|
-
|
|
66
|
-
// ../../shared/src/utils/content-types.constants.ts
|
|
67
|
-
var CONTENT_TYPES = {
|
|
68
|
-
MULTIPART: "multipart/form-data",
|
|
69
|
-
FORM_URLENCODED: "application/x-www-form-urlencoded",
|
|
70
|
-
JSON: "application/json"
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
// ../../shared/src/config/constants.ts
|
|
74
|
-
var disableLinting = `/* @ts-nocheck */
|
|
75
|
-
/* eslint-disable */
|
|
76
|
-
/* @noformat */
|
|
77
|
-
/* @formatter:off */
|
|
78
|
-
`;
|
|
79
|
-
var authorComment = `/**
|
|
80
|
-
* Generated by ng-openapi
|
|
81
|
-
`;
|
|
82
|
-
var defaultHeaderComment = disableLinting + authorComment;
|
|
83
|
-
var TYPE_GENERATOR_HEADER_COMMENT = defaultHeaderComment + `* Generated TypeScript interfaces from Swagger specification
|
|
84
|
-
* Do not edit this file manually
|
|
85
|
-
*/
|
|
86
|
-
`;
|
|
87
|
-
var SERVICE_INDEX_GENERATOR_HEADER_COMMENT = defaultHeaderComment + `* Generated service exports
|
|
88
|
-
* Do not edit this file manually
|
|
89
|
-
*/
|
|
90
|
-
`;
|
|
91
|
-
var REQUEST_PARAMS_GENERATOR_HEADER_COMMENT = defaultHeaderComment + `* Generated request parameter interfaces
|
|
92
|
-
* Do not edit this file manually
|
|
93
|
-
*/
|
|
94
|
-
`;
|
|
95
|
-
var MAIN_INDEX_GENERATOR_HEADER_COMMENT = defaultHeaderComment + `* Entrypoint for the client
|
|
96
|
-
* Do not edit this file manually
|
|
97
|
-
*/
|
|
98
|
-
`;
|
|
99
|
-
var PROVIDER_GENERATOR_HEADER_COMMENT = defaultHeaderComment + `* Generated provider functions for easy setup
|
|
100
|
-
* Do not edit this file manually
|
|
101
|
-
*/
|
|
102
|
-
`;
|
|
103
|
-
var ZOD_PLUGIN_GENERATOR_HEADER_COMMENT = /* @__PURE__ */ __name((validatorName) => defaultHeaderComment + `* Generated Zod Schemas for ${validatorName}
|
|
104
|
-
* Do not edit this file manually
|
|
105
|
-
*/
|
|
106
|
-
`, "ZOD_PLUGIN_GENERATOR_HEADER_COMMENT");
|
|
107
|
-
var ZOD_PLUGIN_INDEX_GENERATOR_HEADER_COMMENT = defaultHeaderComment + `* Generated Zod Schemas exports
|
|
108
|
-
* Do not edit this file manually
|
|
109
|
-
*/
|
|
110
|
-
`;
|
|
111
|
-
|
|
112
7
|
// ../../../node_modules/js-yaml/dist/js-yaml.mjs
|
|
113
8
|
function isNothing(subject) {
|
|
114
9
|
return typeof subject === "undefined" || subject === null;
|
|
@@ -2811,9 +2706,65 @@ var safeLoad = renamed("safeLoad", "load");
|
|
|
2811
2706
|
var safeLoadAll = renamed("safeLoadAll", "loadAll");
|
|
2812
2707
|
var safeDump = renamed("safeDump", "dump");
|
|
2813
2708
|
|
|
2709
|
+
// ../../shared/src/utils/content-types.constants.ts
|
|
2710
|
+
var CONTENT_TYPES = {
|
|
2711
|
+
MULTIPART: "multipart/form-data",
|
|
2712
|
+
FORM_URLENCODED: "application/x-www-form-urlencoded",
|
|
2713
|
+
JSON: "application/json"
|
|
2714
|
+
};
|
|
2715
|
+
|
|
2716
|
+
// ../../shared/src/utils/string.utils.ts
|
|
2717
|
+
function camelCase(str2) {
|
|
2718
|
+
return str2.replace(/[-_.\s]+(.)?/g, (_, char) => char ? char.toUpperCase() : "").replace(/^./, (char) => char.toLowerCase());
|
|
2719
|
+
}
|
|
2720
|
+
__name(camelCase, "camelCase");
|
|
2721
|
+
function pascalCase(str2) {
|
|
2722
|
+
return str2.replace(/[-_.\s]+(.)?/g, (_, char) => char ? char.toUpperCase() : "").replace(/^./, (char) => char.toUpperCase());
|
|
2723
|
+
}
|
|
2724
|
+
__name(pascalCase, "pascalCase");
|
|
2725
|
+
|
|
2726
|
+
// ../../shared/src/config/constants.ts
|
|
2727
|
+
var disableLinting = `/* @ts-nocheck */
|
|
2728
|
+
/* eslint-disable */
|
|
2729
|
+
/* @noformat */
|
|
2730
|
+
/* @formatter:off */
|
|
2731
|
+
`;
|
|
2732
|
+
var authorComment = `/**
|
|
2733
|
+
* Generated by ng-openapi
|
|
2734
|
+
`;
|
|
2735
|
+
var defaultHeaderComment = disableLinting + authorComment;
|
|
2736
|
+
var TYPE_GENERATOR_HEADER_COMMENT = defaultHeaderComment + `* Generated TypeScript interfaces from Swagger specification
|
|
2737
|
+
* Do not edit this file manually
|
|
2738
|
+
*/
|
|
2739
|
+
`;
|
|
2740
|
+
var SERVICE_INDEX_GENERATOR_HEADER_COMMENT = defaultHeaderComment + `* Generated service exports
|
|
2741
|
+
* Do not edit this file manually
|
|
2742
|
+
*/
|
|
2743
|
+
`;
|
|
2744
|
+
var REQUEST_PARAMS_GENERATOR_HEADER_COMMENT = defaultHeaderComment + `* Generated request parameter interfaces
|
|
2745
|
+
* Do not edit this file manually
|
|
2746
|
+
*/
|
|
2747
|
+
`;
|
|
2748
|
+
var MAIN_INDEX_GENERATOR_HEADER_COMMENT = defaultHeaderComment + `* Entrypoint for the client
|
|
2749
|
+
* Do not edit this file manually
|
|
2750
|
+
*/
|
|
2751
|
+
`;
|
|
2752
|
+
var PROVIDER_GENERATOR_HEADER_COMMENT = defaultHeaderComment + `* Generated provider functions for easy setup
|
|
2753
|
+
* Do not edit this file manually
|
|
2754
|
+
*/
|
|
2755
|
+
`;
|
|
2756
|
+
var ZOD_PLUGIN_GENERATOR_HEADER_COMMENT = /* @__PURE__ */ __name((validatorName) => defaultHeaderComment + `* Generated Zod Schemas for ${validatorName}
|
|
2757
|
+
* Do not edit this file manually
|
|
2758
|
+
*/
|
|
2759
|
+
`, "ZOD_PLUGIN_GENERATOR_HEADER_COMMENT");
|
|
2760
|
+
var ZOD_PLUGIN_INDEX_GENERATOR_HEADER_COMMENT = defaultHeaderComment + `* Generated Zod Schemas exports
|
|
2761
|
+
* Do not edit this file manually
|
|
2762
|
+
*/
|
|
2763
|
+
`;
|
|
2764
|
+
|
|
2814
2765
|
// src/lib/utils/is-reference-object.ts
|
|
2815
2766
|
function isReferenceObject(obj) {
|
|
2816
|
-
return
|
|
2767
|
+
return typeof obj === "object" && obj !== null && "$ref" in obj;
|
|
2817
2768
|
}
|
|
2818
2769
|
__name(isReferenceObject, "isReferenceObject");
|
|
2819
2770
|
|
|
@@ -2822,17 +2773,17 @@ var ZodSchemaBuilder = class {
|
|
|
2822
2773
|
static {
|
|
2823
2774
|
__name(this, "ZodSchemaBuilder");
|
|
2824
2775
|
}
|
|
2825
|
-
|
|
2776
|
+
spec;
|
|
2826
2777
|
config;
|
|
2827
2778
|
options;
|
|
2828
|
-
constructor(
|
|
2829
|
-
this.
|
|
2779
|
+
constructor(spec, config, options) {
|
|
2780
|
+
this.spec = spec;
|
|
2830
2781
|
this.config = config;
|
|
2831
2782
|
this.options = options;
|
|
2832
2783
|
}
|
|
2833
2784
|
async buildSchema(schema2, name, buildOptions = {}) {
|
|
2834
2785
|
if (isReferenceObject(schema2)) {
|
|
2835
|
-
const resolved = this.
|
|
2786
|
+
const resolved = this.spec.resolveReference(schema2.$ref);
|
|
2836
2787
|
return this.buildSchema(resolved, name, buildOptions);
|
|
2837
2788
|
}
|
|
2838
2789
|
if (buildOptions.removeReadOnly && schema2.properties) {
|
|
@@ -2878,7 +2829,7 @@ var ZodSchemaBuilder = class {
|
|
|
2878
2829
|
}
|
|
2879
2830
|
async buildStringSchema(schema2, buildOptions) {
|
|
2880
2831
|
if (schema2.enum && schema2.enum.every((v) => typeof v === "string")) {
|
|
2881
|
-
const enumValues = schema2.enum.map((v) => `'${this.escapeString(v)}'`).join(", ");
|
|
2832
|
+
const enumValues = schema2.enum.map((v) => `'${this.escapeString(String(v))}'`).join(", ");
|
|
2882
2833
|
return `z.enum([${enumValues}])`;
|
|
2883
2834
|
}
|
|
2884
2835
|
if (schema2.format) {
|
|
@@ -3033,8 +2984,7 @@ ${properties.join(",\n")}
|
|
|
3033
2984
|
...schema2
|
|
3034
2985
|
};
|
|
3035
2986
|
filtered.properties = Object.entries(schema2.properties).reduce((acc, [key, value]) => {
|
|
3036
|
-
|
|
3037
|
-
if (!propSchema.readOnly) {
|
|
2987
|
+
if (!value.readOnly) {
|
|
3038
2988
|
acc[key] = value;
|
|
3039
2989
|
}
|
|
3040
2990
|
return acc;
|
|
@@ -3085,15 +3035,15 @@ var ZodSchemaGenerator = class {
|
|
|
3085
3035
|
static {
|
|
3086
3036
|
__name(this, "ZodSchemaGenerator");
|
|
3087
3037
|
}
|
|
3088
|
-
|
|
3038
|
+
spec;
|
|
3089
3039
|
config;
|
|
3090
3040
|
options;
|
|
3091
3041
|
schemaBuilder;
|
|
3092
|
-
constructor(
|
|
3093
|
-
this.
|
|
3042
|
+
constructor(spec, config, options) {
|
|
3043
|
+
this.spec = spec;
|
|
3094
3044
|
this.config = config;
|
|
3095
3045
|
this.options = options;
|
|
3096
|
-
this.schemaBuilder = new ZodSchemaBuilder(
|
|
3046
|
+
this.schemaBuilder = new ZodSchemaBuilder(spec, config, options);
|
|
3097
3047
|
}
|
|
3098
3048
|
async generateParametersValidator(parameters, operationName, suffix) {
|
|
3099
3049
|
const properties = {};
|
|
@@ -3219,21 +3169,21 @@ var ZodSchemaGenerator = class {
|
|
|
3219
3169
|
}
|
|
3220
3170
|
resolveRequestBody(requestBody) {
|
|
3221
3171
|
if (isReferenceObject(requestBody)) {
|
|
3222
|
-
const resolved = this.
|
|
3172
|
+
const resolved = this.spec.resolveReference(requestBody.$ref);
|
|
3223
3173
|
return resolved;
|
|
3224
3174
|
}
|
|
3225
3175
|
return requestBody;
|
|
3226
3176
|
}
|
|
3227
3177
|
resolveResponse(response) {
|
|
3228
3178
|
if (isReferenceObject(response)) {
|
|
3229
|
-
const resolved = this.
|
|
3179
|
+
const resolved = this.spec.resolveReference(response.$ref);
|
|
3230
3180
|
return resolved;
|
|
3231
3181
|
}
|
|
3232
3182
|
return response;
|
|
3233
3183
|
}
|
|
3234
3184
|
resolveSchema(schema2) {
|
|
3235
3185
|
if (isReferenceObject(schema2)) {
|
|
3236
|
-
const resolved = this.
|
|
3186
|
+
const resolved = this.spec.resolveReference(schema2.$ref);
|
|
3237
3187
|
return resolved;
|
|
3238
3188
|
}
|
|
3239
3189
|
return schema2;
|
|
@@ -3316,33 +3266,29 @@ var ZodGenerator = class {
|
|
|
3316
3266
|
__name(this, "ZodGenerator");
|
|
3317
3267
|
}
|
|
3318
3268
|
project;
|
|
3319
|
-
parser;
|
|
3320
3269
|
spec;
|
|
3321
3270
|
config;
|
|
3322
3271
|
options;
|
|
3323
3272
|
schemaGenerator;
|
|
3324
3273
|
indexGenerator;
|
|
3325
|
-
|
|
3326
|
-
|
|
3327
|
-
this.
|
|
3328
|
-
this.
|
|
3329
|
-
this.spec =
|
|
3274
|
+
onWarning;
|
|
3275
|
+
constructor(context, options) {
|
|
3276
|
+
this.config = context.config;
|
|
3277
|
+
this.project = context.project;
|
|
3278
|
+
this.spec = context.spec;
|
|
3279
|
+
this.onWarning = context.onWarning;
|
|
3330
3280
|
this.options = {
|
|
3331
3281
|
...DEFAULT_OPTIONS,
|
|
3332
3282
|
...options
|
|
3333
3283
|
};
|
|
3334
|
-
|
|
3335
|
-
|
|
3336
|
-
throw new Error(`Invalid or unsupported specification format. Expected OpenAPI 3.x or Swagger 2.x. ${versionInfo ? `Found: ${versionInfo.type} ${versionInfo.version}` : "No version info found"}`);
|
|
3337
|
-
}
|
|
3338
|
-
this.schemaGenerator = new ZodSchemaGenerator(this.parser, this.config, this.options);
|
|
3339
|
-
this.indexGenerator = new ZodIndexGenerator(project);
|
|
3284
|
+
this.schemaGenerator = new ZodSchemaGenerator(context.spec, this.config, this.options);
|
|
3285
|
+
this.indexGenerator = new ZodIndexGenerator(context.project);
|
|
3340
3286
|
}
|
|
3341
3287
|
async generate(outputRoot) {
|
|
3342
3288
|
const outputDir = path2.join(outputRoot, "validators");
|
|
3343
|
-
const paths =
|
|
3289
|
+
const paths = this.spec.operations;
|
|
3344
3290
|
if (paths.length === 0) {
|
|
3345
|
-
|
|
3291
|
+
this.onWarning?.("No API paths found in the specification");
|
|
3346
3292
|
return;
|
|
3347
3293
|
}
|
|
3348
3294
|
const controllerGroups = this.groupPathsByController(paths);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ng-openapi/zod",
|
|
3
|
-
"version": "0.0.12-pr-
|
|
3
|
+
"version": "0.0.12-pr-103-refactored-d262edf.0",
|
|
4
4
|
"description": "Zod validation plugin for ng-openapi - Generate Zod schemas from OpenAPI specifications",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"angular",
|