ng-openapi 0.0.40-pr-8-feature-url-support.0 → 0.0.41-pr-8-feature-url-support-60ba418.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/cli.cjs +49 -45
- package/index.d.ts +37 -36
- package/index.js +50 -45
- package/package.json +1 -1
package/cli.cjs
CHANGED
|
@@ -38,52 +38,17 @@ var SwaggerParser = class _SwaggerParser {
|
|
|
38
38
|
__name(this, "SwaggerParser");
|
|
39
39
|
}
|
|
40
40
|
spec;
|
|
41
|
-
constructor(spec) {
|
|
41
|
+
constructor(spec, config) {
|
|
42
|
+
const generateClient = config.generateClientIf?.(spec) ?? true;
|
|
43
|
+
if (!generateClient) {
|
|
44
|
+
throw new Error("Client generation is disabled by configuration. Check your `generateClientIf` condition.");
|
|
45
|
+
}
|
|
42
46
|
this.spec = spec;
|
|
43
47
|
}
|
|
44
|
-
static async create(swaggerPathOrUrl) {
|
|
48
|
+
static async create(swaggerPathOrUrl, config) {
|
|
45
49
|
const swaggerContent = await _SwaggerParser.loadContent(swaggerPathOrUrl);
|
|
46
50
|
const spec = _SwaggerParser.parseSpecContent(swaggerContent, swaggerPathOrUrl);
|
|
47
|
-
return new _SwaggerParser(spec);
|
|
48
|
-
}
|
|
49
|
-
getDefinitions() {
|
|
50
|
-
return this.spec.definitions || this.spec.components?.schemas || {};
|
|
51
|
-
}
|
|
52
|
-
getDefinition(name) {
|
|
53
|
-
const definitions = this.getDefinitions();
|
|
54
|
-
return definitions[name];
|
|
55
|
-
}
|
|
56
|
-
resolveReference(ref) {
|
|
57
|
-
const parts = ref.split("/");
|
|
58
|
-
const definitionName = parts[parts.length - 1];
|
|
59
|
-
return this.getDefinition(definitionName);
|
|
60
|
-
}
|
|
61
|
-
getAllDefinitionNames() {
|
|
62
|
-
return Object.keys(this.getDefinitions());
|
|
63
|
-
}
|
|
64
|
-
getSpec() {
|
|
65
|
-
return this.spec;
|
|
66
|
-
}
|
|
67
|
-
getPaths() {
|
|
68
|
-
return this.spec.paths || {};
|
|
69
|
-
}
|
|
70
|
-
isValidSpec() {
|
|
71
|
-
return !!(this.spec.swagger && this.spec.swagger.startsWith("2.") || this.spec.openapi && this.spec.openapi.startsWith("3."));
|
|
72
|
-
}
|
|
73
|
-
getSpecVersion() {
|
|
74
|
-
if (this.spec.swagger) {
|
|
75
|
-
return {
|
|
76
|
-
type: "swagger",
|
|
77
|
-
version: this.spec.swagger
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
if (this.spec.openapi) {
|
|
81
|
-
return {
|
|
82
|
-
type: "openapi",
|
|
83
|
-
version: this.spec.openapi
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
return null;
|
|
51
|
+
return new _SwaggerParser(spec, config);
|
|
87
52
|
}
|
|
88
53
|
static async loadContent(pathOrUrl) {
|
|
89
54
|
if (_SwaggerParser.isUrl(pathOrUrl)) {
|
|
@@ -180,6 +145,45 @@ var SwaggerParser = class _SwaggerParser {
|
|
|
180
145
|
}
|
|
181
146
|
return "json";
|
|
182
147
|
}
|
|
148
|
+
getDefinitions() {
|
|
149
|
+
return this.spec.definitions || this.spec.components?.schemas || {};
|
|
150
|
+
}
|
|
151
|
+
getDefinition(name) {
|
|
152
|
+
const definitions = this.getDefinitions();
|
|
153
|
+
return definitions[name];
|
|
154
|
+
}
|
|
155
|
+
resolveReference(ref) {
|
|
156
|
+
const parts = ref.split("/");
|
|
157
|
+
const definitionName = parts[parts.length - 1];
|
|
158
|
+
return this.getDefinition(definitionName);
|
|
159
|
+
}
|
|
160
|
+
getAllDefinitionNames() {
|
|
161
|
+
return Object.keys(this.getDefinitions());
|
|
162
|
+
}
|
|
163
|
+
getSpec() {
|
|
164
|
+
return this.spec;
|
|
165
|
+
}
|
|
166
|
+
getPaths() {
|
|
167
|
+
return this.spec.paths || {};
|
|
168
|
+
}
|
|
169
|
+
isValidSpec() {
|
|
170
|
+
return !!(this.spec.swagger && this.spec.swagger.startsWith("2.") || this.spec.openapi && this.spec.openapi.startsWith("3."));
|
|
171
|
+
}
|
|
172
|
+
getSpecVersion() {
|
|
173
|
+
if (this.spec.swagger) {
|
|
174
|
+
return {
|
|
175
|
+
type: "swagger",
|
|
176
|
+
version: this.spec.swagger
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
if (this.spec.openapi) {
|
|
180
|
+
return {
|
|
181
|
+
type: "openapi",
|
|
182
|
+
version: this.spec.openapi
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
return null;
|
|
186
|
+
}
|
|
183
187
|
};
|
|
184
188
|
|
|
185
189
|
// src/lib/core/generator.ts
|
|
@@ -251,7 +255,7 @@ var TypeGenerator = class _TypeGenerator {
|
|
|
251
255
|
});
|
|
252
256
|
}
|
|
253
257
|
static async create(swaggerPathOrUrl, outputRoot, config) {
|
|
254
|
-
const parser = await SwaggerParser.create(swaggerPathOrUrl);
|
|
258
|
+
const parser = await SwaggerParser.create(swaggerPathOrUrl, config);
|
|
255
259
|
return new _TypeGenerator(parser, outputRoot, config);
|
|
256
260
|
}
|
|
257
261
|
generate() {
|
|
@@ -2115,7 +2119,7 @@ var ServiceGenerator = class _ServiceGenerator {
|
|
|
2115
2119
|
this.methodGenerator = new ServiceMethodGenerator(config);
|
|
2116
2120
|
}
|
|
2117
2121
|
static async create(swaggerPathOrUrl, project, config) {
|
|
2118
|
-
const parser = await SwaggerParser.create(swaggerPathOrUrl);
|
|
2122
|
+
const parser = await SwaggerParser.create(swaggerPathOrUrl, config);
|
|
2119
2123
|
return new _ServiceGenerator(parser, project, config);
|
|
2120
2124
|
}
|
|
2121
2125
|
generate(outputRoot) {
|
|
@@ -2517,7 +2521,7 @@ async function generateFromConfig(config) {
|
|
|
2517
2521
|
__name(generateFromConfig, "generateFromConfig");
|
|
2518
2522
|
|
|
2519
2523
|
// package.json
|
|
2520
|
-
var version = "0.0.
|
|
2524
|
+
var version = "0.0.40";
|
|
2521
2525
|
|
|
2522
2526
|
// src/lib/cli.ts
|
|
2523
2527
|
var program = new import_commander.Command();
|
package/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { ParameterType, XML, ExternalDocs, Info, Path, BodyParameter, QueryParameter, Security, Tag } from 'swagger-schema-official';
|
|
2
1
|
import { ScriptTarget, ModuleKind } from 'ts-morph';
|
|
3
2
|
import { HttpInterceptor } from '@angular/common/http';
|
|
3
|
+
import { Info, ExternalDocs, Path, ParameterType, XML, BodyParameter, QueryParameter, Security, Tag } from 'swagger-schema-official';
|
|
4
4
|
|
|
5
5
|
interface MethodGenerationContext {
|
|
6
6
|
pathParams: Array<{
|
|
@@ -26,35 +26,6 @@ interface TypeSchema {
|
|
|
26
26
|
[key: string]: any;
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
interface GeneratorConfig {
|
|
30
|
-
input: string;
|
|
31
|
-
output: string;
|
|
32
|
-
clientName?: string;
|
|
33
|
-
options: {
|
|
34
|
-
dateType: "string" | "Date";
|
|
35
|
-
enumStyle: "enum" | "union";
|
|
36
|
-
generateServices?: boolean;
|
|
37
|
-
generateEnumBasedOnDescription?: boolean;
|
|
38
|
-
customHeaders?: Record<string, string>;
|
|
39
|
-
responseTypeMapping?: {
|
|
40
|
-
[contentType: string]: "json" | "blob" | "arraybuffer" | "text";
|
|
41
|
-
};
|
|
42
|
-
customizeMethodName?: (operationId: string) => string;
|
|
43
|
-
};
|
|
44
|
-
compilerOptions?: {
|
|
45
|
-
declaration?: boolean;
|
|
46
|
-
target?: ScriptTarget;
|
|
47
|
-
module?: ModuleKind;
|
|
48
|
-
strict?: boolean;
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
interface NgOpenapiClientConfig {
|
|
52
|
-
clientName: string;
|
|
53
|
-
basePath: string;
|
|
54
|
-
enableDateTransform?: boolean;
|
|
55
|
-
interceptors?: (new (...args: HttpInterceptor[]) => HttpInterceptor)[];
|
|
56
|
-
}
|
|
57
|
-
|
|
58
29
|
interface Parameter {
|
|
59
30
|
name: string;
|
|
60
31
|
in: "query" | "path" | "header" | "cookie";
|
|
@@ -162,10 +133,45 @@ type EnumValueObject = {
|
|
|
162
133
|
Value: number;
|
|
163
134
|
};
|
|
164
135
|
|
|
136
|
+
interface GeneratorConfig {
|
|
137
|
+
input: string;
|
|
138
|
+
output: string;
|
|
139
|
+
clientName?: string;
|
|
140
|
+
generateClientIf?: (swaggerSpec: SwaggerSpec) => boolean;
|
|
141
|
+
options: {
|
|
142
|
+
dateType: "string" | "Date";
|
|
143
|
+
enumStyle: "enum" | "union";
|
|
144
|
+
generateServices?: boolean;
|
|
145
|
+
generateEnumBasedOnDescription?: boolean;
|
|
146
|
+
customHeaders?: Record<string, string>;
|
|
147
|
+
responseTypeMapping?: {
|
|
148
|
+
[contentType: string]: "json" | "blob" | "arraybuffer" | "text";
|
|
149
|
+
};
|
|
150
|
+
customizeMethodName?: (operationId: string) => string;
|
|
151
|
+
};
|
|
152
|
+
compilerOptions?: {
|
|
153
|
+
declaration?: boolean;
|
|
154
|
+
target?: ScriptTarget;
|
|
155
|
+
module?: ModuleKind;
|
|
156
|
+
strict?: boolean;
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
interface NgOpenapiClientConfig {
|
|
160
|
+
clientName: string;
|
|
161
|
+
basePath: string;
|
|
162
|
+
enableDateTransform?: boolean;
|
|
163
|
+
interceptors?: (new (...args: HttpInterceptor[]) => HttpInterceptor)[];
|
|
164
|
+
}
|
|
165
|
+
|
|
165
166
|
declare class SwaggerParser {
|
|
166
167
|
private readonly spec;
|
|
167
168
|
private constructor();
|
|
168
|
-
static create(swaggerPathOrUrl: string): Promise<SwaggerParser>;
|
|
169
|
+
static create(swaggerPathOrUrl: string, config: GeneratorConfig): Promise<SwaggerParser>;
|
|
170
|
+
private static loadContent;
|
|
171
|
+
private static isUrl;
|
|
172
|
+
private static fetchUrlContent;
|
|
173
|
+
private static parseSpecContent;
|
|
174
|
+
private static detectFormat;
|
|
169
175
|
getDefinitions(): Record<string, SwaggerDefinition>;
|
|
170
176
|
getDefinition(name: string): SwaggerDefinition | undefined;
|
|
171
177
|
resolveReference(ref: string): SwaggerDefinition | undefined;
|
|
@@ -177,11 +183,6 @@ declare class SwaggerParser {
|
|
|
177
183
|
type: "swagger" | "openapi";
|
|
178
184
|
version: string;
|
|
179
185
|
} | null;
|
|
180
|
-
private static loadContent;
|
|
181
|
-
private static isUrl;
|
|
182
|
-
private static fetchUrlContent;
|
|
183
|
-
private static parseSpecContent;
|
|
184
|
-
private static detectFormat;
|
|
185
186
|
}
|
|
186
187
|
|
|
187
188
|
/**
|
package/index.js
CHANGED
|
@@ -83,57 +83,22 @@ var fs = __toESM(require("fs"));
|
|
|
83
83
|
var path = __toESM(require("path"));
|
|
84
84
|
var yaml = __toESM(require("js-yaml"));
|
|
85
85
|
var _SwaggerParser = class _SwaggerParser {
|
|
86
|
-
constructor(spec) {
|
|
86
|
+
constructor(spec, config) {
|
|
87
87
|
__publicField(this, "spec");
|
|
88
|
+
var _a, _b;
|
|
89
|
+
const generateClient = (_b = (_a = config.generateClientIf) == null ? void 0 : _a.call(config, spec)) != null ? _b : true;
|
|
90
|
+
if (!generateClient) {
|
|
91
|
+
throw new Error("Client generation is disabled by configuration. Check your `generateClientIf` condition.");
|
|
92
|
+
}
|
|
88
93
|
this.spec = spec;
|
|
89
94
|
}
|
|
90
|
-
static create(swaggerPathOrUrl) {
|
|
95
|
+
static create(swaggerPathOrUrl, config) {
|
|
91
96
|
return __async(this, null, function* () {
|
|
92
97
|
const swaggerContent = yield _SwaggerParser.loadContent(swaggerPathOrUrl);
|
|
93
98
|
const spec = _SwaggerParser.parseSpecContent(swaggerContent, swaggerPathOrUrl);
|
|
94
|
-
return new _SwaggerParser(spec);
|
|
99
|
+
return new _SwaggerParser(spec, config);
|
|
95
100
|
});
|
|
96
101
|
}
|
|
97
|
-
getDefinitions() {
|
|
98
|
-
var _a;
|
|
99
|
-
return this.spec.definitions || ((_a = this.spec.components) == null ? void 0 : _a.schemas) || {};
|
|
100
|
-
}
|
|
101
|
-
getDefinition(name) {
|
|
102
|
-
const definitions = this.getDefinitions();
|
|
103
|
-
return definitions[name];
|
|
104
|
-
}
|
|
105
|
-
resolveReference(ref) {
|
|
106
|
-
const parts = ref.split("/");
|
|
107
|
-
const definitionName = parts[parts.length - 1];
|
|
108
|
-
return this.getDefinition(definitionName);
|
|
109
|
-
}
|
|
110
|
-
getAllDefinitionNames() {
|
|
111
|
-
return Object.keys(this.getDefinitions());
|
|
112
|
-
}
|
|
113
|
-
getSpec() {
|
|
114
|
-
return this.spec;
|
|
115
|
-
}
|
|
116
|
-
getPaths() {
|
|
117
|
-
return this.spec.paths || {};
|
|
118
|
-
}
|
|
119
|
-
isValidSpec() {
|
|
120
|
-
return !!(this.spec.swagger && this.spec.swagger.startsWith("2.") || this.spec.openapi && this.spec.openapi.startsWith("3."));
|
|
121
|
-
}
|
|
122
|
-
getSpecVersion() {
|
|
123
|
-
if (this.spec.swagger) {
|
|
124
|
-
return {
|
|
125
|
-
type: "swagger",
|
|
126
|
-
version: this.spec.swagger
|
|
127
|
-
};
|
|
128
|
-
}
|
|
129
|
-
if (this.spec.openapi) {
|
|
130
|
-
return {
|
|
131
|
-
type: "openapi",
|
|
132
|
-
version: this.spec.openapi
|
|
133
|
-
};
|
|
134
|
-
}
|
|
135
|
-
return null;
|
|
136
|
-
}
|
|
137
102
|
static loadContent(pathOrUrl) {
|
|
138
103
|
return __async(this, null, function* () {
|
|
139
104
|
if (_SwaggerParser.isUrl(pathOrUrl)) {
|
|
@@ -233,6 +198,46 @@ var _SwaggerParser = class _SwaggerParser {
|
|
|
233
198
|
}
|
|
234
199
|
return "json";
|
|
235
200
|
}
|
|
201
|
+
getDefinitions() {
|
|
202
|
+
var _a;
|
|
203
|
+
return this.spec.definitions || ((_a = this.spec.components) == null ? void 0 : _a.schemas) || {};
|
|
204
|
+
}
|
|
205
|
+
getDefinition(name) {
|
|
206
|
+
const definitions = this.getDefinitions();
|
|
207
|
+
return definitions[name];
|
|
208
|
+
}
|
|
209
|
+
resolveReference(ref) {
|
|
210
|
+
const parts = ref.split("/");
|
|
211
|
+
const definitionName = parts[parts.length - 1];
|
|
212
|
+
return this.getDefinition(definitionName);
|
|
213
|
+
}
|
|
214
|
+
getAllDefinitionNames() {
|
|
215
|
+
return Object.keys(this.getDefinitions());
|
|
216
|
+
}
|
|
217
|
+
getSpec() {
|
|
218
|
+
return this.spec;
|
|
219
|
+
}
|
|
220
|
+
getPaths() {
|
|
221
|
+
return this.spec.paths || {};
|
|
222
|
+
}
|
|
223
|
+
isValidSpec() {
|
|
224
|
+
return !!(this.spec.swagger && this.spec.swagger.startsWith("2.") || this.spec.openapi && this.spec.openapi.startsWith("3."));
|
|
225
|
+
}
|
|
226
|
+
getSpecVersion() {
|
|
227
|
+
if (this.spec.swagger) {
|
|
228
|
+
return {
|
|
229
|
+
type: "swagger",
|
|
230
|
+
version: this.spec.swagger
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
if (this.spec.openapi) {
|
|
234
|
+
return {
|
|
235
|
+
type: "openapi",
|
|
236
|
+
version: this.spec.openapi
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
return null;
|
|
240
|
+
}
|
|
236
241
|
};
|
|
237
242
|
__name(_SwaggerParser, "SwaggerParser");
|
|
238
243
|
var SwaggerParser = _SwaggerParser;
|
|
@@ -303,7 +308,7 @@ var _TypeGenerator = class _TypeGenerator {
|
|
|
303
308
|
}
|
|
304
309
|
static create(swaggerPathOrUrl, outputRoot, config) {
|
|
305
310
|
return __async(this, null, function* () {
|
|
306
|
-
const parser = yield SwaggerParser.create(swaggerPathOrUrl);
|
|
311
|
+
const parser = yield SwaggerParser.create(swaggerPathOrUrl, config);
|
|
307
312
|
return new _TypeGenerator(parser, outputRoot, config);
|
|
308
313
|
});
|
|
309
314
|
}
|
|
@@ -2175,7 +2180,7 @@ var _ServiceGenerator = class _ServiceGenerator {
|
|
|
2175
2180
|
}
|
|
2176
2181
|
static create(swaggerPathOrUrl, project, config) {
|
|
2177
2182
|
return __async(this, null, function* () {
|
|
2178
|
-
const parser = yield SwaggerParser.create(swaggerPathOrUrl);
|
|
2183
|
+
const parser = yield SwaggerParser.create(swaggerPathOrUrl, config);
|
|
2179
2184
|
return new _ServiceGenerator(parser, project, config);
|
|
2180
2185
|
});
|
|
2181
2186
|
}
|
package/package.json
CHANGED