@rxap/open-api 15.0.0 → 16.0.0-dev.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/esm2022/lib/open-api-config.service.mjs +161 -0
- package/esm2022/lib/open-api-http-response.error.mjs +18 -0
- package/esm2022/lib/schema-validation.mixin.mjs +257 -0
- package/esm2022/remote-method/lib/open-api-remote-method.loader.mjs +38 -0
- package/esm2022/remote-method/lib/open-api.remote-method.mjs +165 -0
- package/{fesm2020 → fesm2022}/rxap-open-api-remote-method.mjs +10 -12
- package/fesm2022/rxap-open-api-remote-method.mjs.map +1 -0
- package/{fesm2020 → fesm2022}/rxap-open-api.mjs +24 -25
- package/fesm2022/rxap-open-api.mjs.map +1 -0
- package/lib/open-api-config.service.d.ts +1 -1
- package/package.json +21 -29
- package/src/schematics/open-api/coerce-open-api-project.js +6 -4
- package/src/schematics/open-api/coerce-open-api-project.js.map +1 -1
- package/esm2020/lib/open-api-config.service.mjs +0 -160
- package/esm2020/lib/open-api-http-response.error.mjs +0 -18
- package/esm2020/lib/schema-validation.mixin.mjs +0 -256
- package/esm2020/remote-method/lib/open-api-remote-method.loader.mjs +0 -37
- package/esm2020/remote-method/lib/open-api.remote-method.mjs +0 -166
- package/fesm2015/rxap-open-api-remote-method.mjs +0 -223
- package/fesm2015/rxap-open-api-remote-method.mjs.map +0 -1
- package/fesm2015/rxap-open-api.mjs +0 -468
- package/fesm2015/rxap-open-api.mjs.map +0 -1
- package/fesm2020/rxap-open-api-remote-method.mjs.map +0 -1
- package/fesm2020/rxap-open-api.mjs.map +0 -1
- /package/{esm2020 → esm2022}/index.mjs +0 -0
- /package/{esm2020 → esm2022}/lib/error.mjs +0 -0
- /package/{esm2020 → esm2022}/lib/open-api.meta-data.mjs +0 -0
- /package/{esm2020 → esm2022}/lib/open-api.mjs +0 -0
- /package/{esm2020 → esm2022}/lib/tokens.mjs +0 -0
- /package/{esm2020 → esm2022}/lib/utilities.mjs +0 -0
- /package/{esm2020 → esm2022}/remote-method/lib/error.mjs +0 -0
- /package/{esm2020 → esm2022}/remote-method/public_api.mjs +0 -0
- /package/{esm2020 → esm2022}/remote-method/rxap-open-api-remote-method.mjs +0 -0
- /package/{esm2020 → esm2022}/rxap-open-api.mjs +0 -0
|
@@ -1,468 +0,0 @@
|
|
|
1
|
-
import { __awaiter } from 'tslib';
|
|
2
|
-
import * as i0 from '@angular/core';
|
|
3
|
-
import { InjectionToken, Injectable, Optional, Inject, isDevMode } from '@angular/core';
|
|
4
|
-
import { RxapError, coerceArray, IsRecord, clone, isPromiseLike } from '@rxap/utilities';
|
|
5
|
-
import * as Ajv from 'ajv-oai';
|
|
6
|
-
import { HttpParams, HttpHeaders } from '@angular/common/http';
|
|
7
|
-
|
|
8
|
-
const RXAP_OPEN_API_CONFIG = new InjectionToken('rxap/open-api/config');
|
|
9
|
-
const RXAP_OPEN_API_STRICT_VALIDATOR = new InjectionToken('rxap/open-api/strict-validator');
|
|
10
|
-
const DEFAULT_OPEN_API_REMOTE_METHOD_META_DATA = new InjectionToken('rxap/open-api/default-remote-method-meta-data');
|
|
11
|
-
const DEFAULT_OPEN_API_DATA_SOURCE_META_DATA = new InjectionToken('rxap/open-api/default-data-source-meta-data');
|
|
12
|
-
const DISABLE_SCHEMA_VALIDATION = new InjectionToken('rxap/open-api/disable-schema-validation');
|
|
13
|
-
const DISABLE_VALIDATION = new InjectionToken('rxap/open-api/disable-validation');
|
|
14
|
-
|
|
15
|
-
class RxapOpenApiError extends RxapError {
|
|
16
|
-
constructor(message, code, scope) {
|
|
17
|
-
super('@rxap/open-api', message, code !== null && code !== void 0 ? code : '', scope);
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
function IsReferenceObject(obj) {
|
|
22
|
-
return !!obj && obj.hasOwnProperty('$ref');
|
|
23
|
-
}
|
|
24
|
-
function NotContainsReferenceObjects(array) {
|
|
25
|
-
return !!array && array.every(item => !IsReferenceObject(item) && !!item);
|
|
26
|
-
}
|
|
27
|
-
function IsOpenApiV3(obj) {
|
|
28
|
-
return !!obj && obj.hasOwnProperty('openapi') && obj.openapi.match(/^3\./);
|
|
29
|
-
}
|
|
30
|
-
function AssertOpenApiV3(obj) {
|
|
31
|
-
if (!IsOpenApiV3(obj)) {
|
|
32
|
-
throw new RxapOpenApiError('Only openapi version 3.x.x is supported');
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
class OpenApiConfigService {
|
|
37
|
-
constructor(config = null) {
|
|
38
|
-
this.defaultServerIndex = OpenApiConfigService.DefaultServerIndex;
|
|
39
|
-
this._operations = null;
|
|
40
|
-
this.serverConfigMap = new Map();
|
|
41
|
-
this._config = null;
|
|
42
|
-
config = config !== null && config !== void 0 ? config : OpenApiConfigService.Config;
|
|
43
|
-
if (config) {
|
|
44
|
-
this._config = config;
|
|
45
|
-
this._operations = OpenApiConfigService.LoadOperations(config);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* Used to load the app open api config from a remote resource.
|
|
50
|
-
*
|
|
51
|
-
* Promise.all([ OpenApiDataSourceLoader.Load() ])
|
|
52
|
-
* .then(() => platformBrowserDynamic().bootstrapModule(AppModule))
|
|
53
|
-
* .catch(err => console.error(err))
|
|
54
|
-
*
|
|
55
|
-
*/
|
|
56
|
-
static Load(openApiUrl = 'openapi.json') {
|
|
57
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
58
|
-
if (!openApiUrl) {
|
|
59
|
-
throw new Error('The open api url is not defined!');
|
|
60
|
-
}
|
|
61
|
-
let config = null;
|
|
62
|
-
try {
|
|
63
|
-
const response = yield fetch(openApiUrl);
|
|
64
|
-
config = yield response.json();
|
|
65
|
-
}
|
|
66
|
-
catch (error) {
|
|
67
|
-
console.debug(`Could not load the open api config from '${openApiUrl}'!`, error);
|
|
68
|
-
console.error(`Could not load the open api config from '${openApiUrl}'!`, error.message);
|
|
69
|
-
}
|
|
70
|
-
if (config) {
|
|
71
|
-
const expandedConfig = yield this.ExpandOpenApi(config);
|
|
72
|
-
AssertOpenApiV3(expandedConfig);
|
|
73
|
-
this.Config = expandedConfig;
|
|
74
|
-
}
|
|
75
|
-
else {
|
|
76
|
-
this.Config = null;
|
|
77
|
-
}
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
static GetOperation(operationId) {
|
|
81
|
-
if (!this.Config) {
|
|
82
|
-
throw new Error('Could not load open api config');
|
|
83
|
-
}
|
|
84
|
-
if (!this._operations) {
|
|
85
|
-
this._operations = this.LoadOperations(this.Config);
|
|
86
|
-
}
|
|
87
|
-
if (!this._operations.has(operationId)) {
|
|
88
|
-
throw new Error(`The operation '${operationId}' is not defined in the openapi-json`);
|
|
89
|
-
}
|
|
90
|
-
return this._operations.get(operationId);
|
|
91
|
-
}
|
|
92
|
-
static LoadOperations(config) {
|
|
93
|
-
const operations = new Map();
|
|
94
|
-
Object.entries(config.paths)
|
|
95
|
-
.filter((item) => item[0] !== undefined)
|
|
96
|
-
.filter(([_, methods]) => methods &&
|
|
97
|
-
Object.keys(methods).some((method) => ['get', 'put', 'post', 'delete', 'patch'].includes(method)))
|
|
98
|
-
.forEach(([path, methods]) => Object.entries(methods)
|
|
99
|
-
.filter((item) => item[0] !== undefined)
|
|
100
|
-
.forEach(([method, operation]) => {
|
|
101
|
-
if (!operation.operationId) {
|
|
102
|
-
throw new Error('The OpenApu OperationId is not defined');
|
|
103
|
-
}
|
|
104
|
-
if (operations.has(operation.operationId)) {
|
|
105
|
-
throw new Error(`The OpenApi Operation '${operation.operationId}' is already defined.`);
|
|
106
|
-
}
|
|
107
|
-
operations.set(operation.operationId, Object.assign(Object.assign({}, operation), { path: path, method: method.toUpperCase() }));
|
|
108
|
-
}));
|
|
109
|
-
return operations;
|
|
110
|
-
}
|
|
111
|
-
static GetBaseUrl(config, serverIndex = this.DefaultServerIndex) {
|
|
112
|
-
const server = config.servers ? config.servers[serverIndex] : null;
|
|
113
|
-
if (!server) {
|
|
114
|
-
console.debug(`Could not extract the server config with the index '${serverIndex}' from the open api config`, config);
|
|
115
|
-
throw new Error(`Could not extract the server config with the index '${serverIndex}' from the open api config`);
|
|
116
|
-
}
|
|
117
|
-
return server.url;
|
|
118
|
-
}
|
|
119
|
-
/**
|
|
120
|
-
* Replaces all $ref with the concrete definition
|
|
121
|
-
*
|
|
122
|
-
* @param config
|
|
123
|
-
* @private
|
|
124
|
-
*/
|
|
125
|
-
static ExpandOpenApi(config) {
|
|
126
|
-
return Promise.resolve(config);
|
|
127
|
-
}
|
|
128
|
-
get config() {
|
|
129
|
-
if (!this._config) {
|
|
130
|
-
throw new Error('Could not load open api config');
|
|
131
|
-
}
|
|
132
|
-
return this._config;
|
|
133
|
-
}
|
|
134
|
-
getOperation(operationId) {
|
|
135
|
-
if (!this._operations) {
|
|
136
|
-
if (!this._config) {
|
|
137
|
-
throw new Error('The operations map is not loaded and the config object is not loaded');
|
|
138
|
-
}
|
|
139
|
-
this._operations = OpenApiConfigService.LoadOperations(this._config);
|
|
140
|
-
}
|
|
141
|
-
if (!this._operations.has(operationId)) {
|
|
142
|
-
console.debug(`The operation '${operationId}' is not defined in the openapi-json`, this.config);
|
|
143
|
-
throw new Error(`The operation '${operationId}' is not defined in the openapi-json`);
|
|
144
|
-
}
|
|
145
|
-
return this._operations.get(operationId);
|
|
146
|
-
}
|
|
147
|
-
getBaseUrl(serverIndex = this.defaultServerIndex, serverId) {
|
|
148
|
-
var _a;
|
|
149
|
-
let serverConfig;
|
|
150
|
-
if (!serverId && ((_a = this._config) === null || _a === void 0 ? void 0 : _a.servers)) {
|
|
151
|
-
serverConfig = this._config.servers[serverIndex];
|
|
152
|
-
}
|
|
153
|
-
if (this.serverConfigMap.has(serverId)) {
|
|
154
|
-
serverConfig = this.serverConfigMap.get(serverId)[serverIndex];
|
|
155
|
-
}
|
|
156
|
-
if (!serverConfig) {
|
|
157
|
-
throw new Error(`Could not determine the base url with the index: ${serverIndex} and the serverId: ${serverId}`);
|
|
158
|
-
}
|
|
159
|
-
return serverConfig.url;
|
|
160
|
-
}
|
|
161
|
-
insertServer(serverConfig, index = this.defaultServerIndex, serverId) {
|
|
162
|
-
if (!serverId && this._config) {
|
|
163
|
-
if (!this.config.servers) {
|
|
164
|
-
this.config.servers = [];
|
|
165
|
-
}
|
|
166
|
-
this.config.servers.splice(index, 1, serverConfig);
|
|
167
|
-
}
|
|
168
|
-
if (!this.serverConfigMap.has(serverId)) {
|
|
169
|
-
this.serverConfigMap.set(serverId, []);
|
|
170
|
-
}
|
|
171
|
-
const list = this.serverConfigMap.get(serverId);
|
|
172
|
-
list[index] = serverConfig;
|
|
173
|
-
this.serverConfigMap.set(serverId, list);
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
OpenApiConfigService.Config = null;
|
|
177
|
-
OpenApiConfigService.DefaultServerIndex = 0;
|
|
178
|
-
OpenApiConfigService._operations = null;
|
|
179
|
-
OpenApiConfigService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.0.3", ngImport: i0, type: OpenApiConfigService, deps: [{ token: RXAP_OPEN_API_CONFIG, optional: true }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
180
|
-
OpenApiConfigService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.0.3", ngImport: i0, type: OpenApiConfigService, providedIn: 'root' });
|
|
181
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.0.3", ngImport: i0, type: OpenApiConfigService, decorators: [{
|
|
182
|
-
type: Injectable,
|
|
183
|
-
args: [{ providedIn: 'root' }]
|
|
184
|
-
}], ctorParameters: function () {
|
|
185
|
-
return [{ type: undefined, decorators: [{
|
|
186
|
-
type: Optional
|
|
187
|
-
}, {
|
|
188
|
-
type: Inject,
|
|
189
|
-
args: [RXAP_OPEN_API_CONFIG]
|
|
190
|
-
}] }];
|
|
191
|
-
} });
|
|
192
|
-
|
|
193
|
-
class SchemaValidationMixin {
|
|
194
|
-
/**
|
|
195
|
-
* Validates the parameters against the schema specified in the operation object
|
|
196
|
-
*
|
|
197
|
-
* @param operation
|
|
198
|
-
* @param parameters
|
|
199
|
-
* @param strict
|
|
200
|
-
* @protected
|
|
201
|
-
*/
|
|
202
|
-
validateParameters(operation, parameters, strict = false) {
|
|
203
|
-
const operationParameters = coerceArray(operation.parameters);
|
|
204
|
-
if (!NotContainsReferenceObjects(operationParameters)) {
|
|
205
|
-
throw new RxapOpenApiError('The operation parameters contains ReferenceObject!');
|
|
206
|
-
}
|
|
207
|
-
if (parameters === undefined) {
|
|
208
|
-
// TODO : find concept to definition witch parameter should not be checked if required
|
|
209
|
-
// header parameters are never required if changes the semantic release manager breaks
|
|
210
|
-
const requiredParameters = operationParameters.filter(parameter => parameter.required && parameter.in !== 'header');
|
|
211
|
-
if (requiredParameters.length) {
|
|
212
|
-
if (isDevMode()) {
|
|
213
|
-
console.debug('Some operation parameters are required!', requiredParameters.map(p => p.name));
|
|
214
|
-
}
|
|
215
|
-
this.validationError('Some operation parameters are required!', strict);
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
else if (IsRecord(parameters)) {
|
|
219
|
-
for (const parameter of operationParameters) {
|
|
220
|
-
if (parameter.required) {
|
|
221
|
-
// header parameters are never required if changes the semantic release manager breaks
|
|
222
|
-
if (parameter.in !== 'header') {
|
|
223
|
-
if (!parameters.hasOwnProperty(parameter.name)) {
|
|
224
|
-
this.validationError(`The operation parameter '${parameter.name}' is required!`, strict);
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
if (parameter.schema) {
|
|
229
|
-
if (parameters.hasOwnProperty(parameter.name)) {
|
|
230
|
-
const value = parameters[parameter.name];
|
|
231
|
-
if (!this.validate(parameter.schema, value)) {
|
|
232
|
-
this.validationError(`The parameter '${parameter.name}' is not valid against the schema!`, strict, parameter.schema, value);
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
else {
|
|
239
|
-
if (operationParameters.length === 0 || operationParameters.every(op => !op.required)) {
|
|
240
|
-
if (isDevMode()) {
|
|
241
|
-
console.warn(`The operation ${operation.operationId} does not expect any parameters. But a parameter is provided.`, parameters);
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
else {
|
|
245
|
-
throw new Error('The parameters object is not a record');
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
/**
|
|
250
|
-
* Validates the http response against the schema specified in the operation object
|
|
251
|
-
*
|
|
252
|
-
* @param operation
|
|
253
|
-
* @param response
|
|
254
|
-
* @param strict
|
|
255
|
-
* @protected
|
|
256
|
-
*/
|
|
257
|
-
validateResponse(operation, response, strict = false) {
|
|
258
|
-
var _a;
|
|
259
|
-
// region only validate the response if the content type is undefined or application/json
|
|
260
|
-
const contentType = response.headers.get('Content-Type');
|
|
261
|
-
if (contentType && contentType !== 'application/json') {
|
|
262
|
-
if (isDevMode()) {
|
|
263
|
-
console.warn('Response validation is only supported for content type application/json');
|
|
264
|
-
}
|
|
265
|
-
return;
|
|
266
|
-
}
|
|
267
|
-
// endregion
|
|
268
|
-
if (operation.responses) {
|
|
269
|
-
const status = response.status;
|
|
270
|
-
// region extract the response object based on the response status
|
|
271
|
-
let responseObject;
|
|
272
|
-
if (operation.responses[status]) {
|
|
273
|
-
responseObject = operation.responses[status];
|
|
274
|
-
}
|
|
275
|
-
else {
|
|
276
|
-
// use the default response object if no matching was found.
|
|
277
|
-
responseObject = operation.responses.default;
|
|
278
|
-
}
|
|
279
|
-
// endregion
|
|
280
|
-
if (responseObject) {
|
|
281
|
-
if (IsReferenceObject(responseObject)) {
|
|
282
|
-
throw new RxapOpenApiError('Found a reference object. The operation config is not expand!');
|
|
283
|
-
}
|
|
284
|
-
// region validate the response against the schema if defined
|
|
285
|
-
// TODO : create schema that validates all parameters at once
|
|
286
|
-
if (responseObject.content && responseObject.content['application/json'] && responseObject.content['application/json'].schema) {
|
|
287
|
-
const schema = responseObject.content['application/json'].schema;
|
|
288
|
-
const data = (_a = response.body) !== null && _a !== void 0 ? _a : response.data;
|
|
289
|
-
if (!this.validate(schema, data)) {
|
|
290
|
-
this.validationError('The response is not valid ageist the operation schema!', strict, schema, data);
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
// endregion
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
validateRequestBody(operation, body, strict = false) {
|
|
298
|
-
// only validate body if type of object
|
|
299
|
-
if (typeof body !== 'object') {
|
|
300
|
-
return;
|
|
301
|
-
}
|
|
302
|
-
if (operation.requestBody) {
|
|
303
|
-
if (IsReferenceObject(operation.requestBody)) {
|
|
304
|
-
throw new RxapOpenApiError('Found a reference object. The operation config is not expand!');
|
|
305
|
-
}
|
|
306
|
-
if (body === undefined && operation.requestBody.required) {
|
|
307
|
-
this.validationError('The request body is required!', strict);
|
|
308
|
-
}
|
|
309
|
-
if (operation.requestBody.content && operation.requestBody.content['application/json']) {
|
|
310
|
-
const schema = operation.requestBody.content['application/json'].schema;
|
|
311
|
-
if (schema) {
|
|
312
|
-
if (!this.validate(schema, body)) {
|
|
313
|
-
this.validationError('The request body is not valid!', strict, schema, body);
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
validationError(message, strict, schema, value) {
|
|
320
|
-
if (isDevMode() && schema !== undefined) {
|
|
321
|
-
// tslint:disable-next-line:no-console
|
|
322
|
-
console.debug(message, { schema, value });
|
|
323
|
-
}
|
|
324
|
-
if (strict || SchemaValidationMixin.STRICT) {
|
|
325
|
-
throw new RxapOpenApiError(message, '', 'SchemaValidationMixin');
|
|
326
|
-
}
|
|
327
|
-
else {
|
|
328
|
-
console.warn(message);
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
buildHttpParams(operationParameters, parameters, ignoreUndefined = true) {
|
|
332
|
-
let params = new HttpParams();
|
|
333
|
-
if (IsRecord(parameters)) {
|
|
334
|
-
for (const parameter of operationParameters.filter(p => p.in === 'query')) {
|
|
335
|
-
const parameterName = parameter.name;
|
|
336
|
-
if (parameters.hasOwnProperty(parameter.name)) {
|
|
337
|
-
const value = parameters[parameter.name];
|
|
338
|
-
if (value === undefined && ignoreUndefined) {
|
|
339
|
-
continue;
|
|
340
|
-
}
|
|
341
|
-
if (Array.isArray(value)) {
|
|
342
|
-
if (value.length) {
|
|
343
|
-
const first = value.shift();
|
|
344
|
-
params = params.set(parameterName, first);
|
|
345
|
-
for (const item of value) {
|
|
346
|
-
params = params.append(parameterName, item);
|
|
347
|
-
}
|
|
348
|
-
}
|
|
349
|
-
}
|
|
350
|
-
else {
|
|
351
|
-
params = params.set(parameter.name, value);
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
}
|
|
355
|
-
}
|
|
356
|
-
return params;
|
|
357
|
-
}
|
|
358
|
-
buildHttpHeaders(operationParameters, parameters) {
|
|
359
|
-
let headers = new HttpHeaders();
|
|
360
|
-
if (IsRecord(parameters)) {
|
|
361
|
-
for (const parameter of operationParameters.filter(p => p.in === 'header')) {
|
|
362
|
-
if (parameters.hasOwnProperty(parameter.name)) {
|
|
363
|
-
const value = parameters[parameter.name];
|
|
364
|
-
if (Array.isArray(value)) {
|
|
365
|
-
if (value.length) {
|
|
366
|
-
const first = value.shift();
|
|
367
|
-
headers = headers.set(parameters.name, first);
|
|
368
|
-
for (const item of value) {
|
|
369
|
-
headers = headers.append(parameters.name, item);
|
|
370
|
-
}
|
|
371
|
-
}
|
|
372
|
-
}
|
|
373
|
-
else {
|
|
374
|
-
headers = headers.set(parameter.name, value);
|
|
375
|
-
}
|
|
376
|
-
}
|
|
377
|
-
}
|
|
378
|
-
}
|
|
379
|
-
return headers;
|
|
380
|
-
}
|
|
381
|
-
buildHttpPathParams(operationParameters, parameters) {
|
|
382
|
-
const pathParams = {};
|
|
383
|
-
if (IsRecord(parameters)) {
|
|
384
|
-
for (const parameter of operationParameters.filter(p => p.in === 'path')) {
|
|
385
|
-
if (parameters.hasOwnProperty(parameter.name)) {
|
|
386
|
-
pathParams[parameter.name] = encodeURIComponent(parameters[parameter.name]);
|
|
387
|
-
}
|
|
388
|
-
}
|
|
389
|
-
}
|
|
390
|
-
return pathParams;
|
|
391
|
-
}
|
|
392
|
-
/**
|
|
393
|
-
* Converts open api parameters into the corresponding http options to
|
|
394
|
-
* create a http request. The transformation is guided by the openapi definition
|
|
395
|
-
*
|
|
396
|
-
* @param operation
|
|
397
|
-
* @param parameters
|
|
398
|
-
* @param requestBody
|
|
399
|
-
* @param ignoreUndefined
|
|
400
|
-
*/
|
|
401
|
-
buildHttpOptions(operation, parameters, requestBody, ignoreUndefined = true) {
|
|
402
|
-
const options = {};
|
|
403
|
-
const operationParameters = coerceArray(operation.parameters);
|
|
404
|
-
if (!NotContainsReferenceObjects(operationParameters)) {
|
|
405
|
-
throw new RxapOpenApiError('The operation parameters contains ReferenceObject!');
|
|
406
|
-
}
|
|
407
|
-
const params = this.buildHttpParams(operationParameters, parameters, ignoreUndefined);
|
|
408
|
-
const headers = this.buildHttpHeaders(operationParameters, parameters);
|
|
409
|
-
const pathParams = this.buildHttpPathParams(operationParameters, parameters);
|
|
410
|
-
if (params.keys().length) {
|
|
411
|
-
options.params = params;
|
|
412
|
-
}
|
|
413
|
-
if (headers.keys().length) {
|
|
414
|
-
options.headers = headers;
|
|
415
|
-
}
|
|
416
|
-
if (Object.keys(pathParams).length) {
|
|
417
|
-
options.pathParams = pathParams;
|
|
418
|
-
}
|
|
419
|
-
if (requestBody !== undefined) {
|
|
420
|
-
options.body = requestBody;
|
|
421
|
-
}
|
|
422
|
-
return options;
|
|
423
|
-
}
|
|
424
|
-
validate(schema, value) {
|
|
425
|
-
if (this.disableSchemaValidation) {
|
|
426
|
-
return true;
|
|
427
|
-
}
|
|
428
|
-
let result;
|
|
429
|
-
try {
|
|
430
|
-
result = new Ajv().validate(schema, clone(value));
|
|
431
|
-
}
|
|
432
|
-
catch (e) {
|
|
433
|
-
console.error(e.message);
|
|
434
|
-
return false;
|
|
435
|
-
}
|
|
436
|
-
if (isPromiseLike(result)) {
|
|
437
|
-
throw new Error('Async schema validation is not yet supported. Ensure the all refs in the openapi schema are internal!');
|
|
438
|
-
}
|
|
439
|
-
return result;
|
|
440
|
-
}
|
|
441
|
-
}
|
|
442
|
-
SchemaValidationMixin.STRICT = false;
|
|
443
|
-
|
|
444
|
-
class OpenApiHttpResponseError extends Error {
|
|
445
|
-
constructor(httpErrorResponse, metadata) {
|
|
446
|
-
super(httpErrorResponse.message);
|
|
447
|
-
this.httpErrorResponse = httpErrorResponse;
|
|
448
|
-
this.metadata = metadata;
|
|
449
|
-
if (Error['captureStackTrace']) {
|
|
450
|
-
Error['captureStackTrace'](this, OpenApiHttpResponseError);
|
|
451
|
-
}
|
|
452
|
-
this.name = 'OpenApiHttpResponseError';
|
|
453
|
-
}
|
|
454
|
-
get status() {
|
|
455
|
-
return this.httpErrorResponse.status;
|
|
456
|
-
}
|
|
457
|
-
get operationId() {
|
|
458
|
-
return this.metadata.id;
|
|
459
|
-
}
|
|
460
|
-
}
|
|
461
|
-
|
|
462
|
-
/**
|
|
463
|
-
* Generated bundle index. Do not edit.
|
|
464
|
-
*/
|
|
465
|
-
|
|
466
|
-
export { AssertOpenApiV3, DEFAULT_OPEN_API_DATA_SOURCE_META_DATA, DEFAULT_OPEN_API_REMOTE_METHOD_META_DATA, DISABLE_SCHEMA_VALIDATION, DISABLE_VALIDATION, IsOpenApiV3, IsReferenceObject, NotContainsReferenceObjects, OpenApiConfigService, OpenApiHttpResponseError, RXAP_OPEN_API_CONFIG, RXAP_OPEN_API_STRICT_VALIDATOR, RxapOpenApiError, SchemaValidationMixin };
|
|
467
|
-
//# sourceMappingURL=rxap-open-api.mjs.map
|
|
468
|
-
//# sourceMappingURL=rxap-open-api.mjs.map
|