@omnigraph/openapi 1.0.0-alpha-20230523155104-df277a22b → 1.0.0-alpha-20230523160518-5443a1139
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.
|
@@ -8,12 +8,13 @@ const string_interpolation_1 = require("@graphql-mesh/string-interpolation");
|
|
|
8
8
|
const utils_1 = require("@graphql-mesh/utils");
|
|
9
9
|
const utils_js_1 = require("./utils.js");
|
|
10
10
|
async function getJSONSchemaOptionsFromOpenAPIOptions(name, { source, fallbackFormat, cwd, fetch: fetchFn, endpoint, schemaHeaders, operationHeaders, queryParams = {}, selectQueryOrMutationField = [], logger = new utils_1.DefaultLogger('getJSONSchemaOptionsFromOpenAPIOptions'), }) {
|
|
11
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
|
11
12
|
const fieldTypeMap = {};
|
|
12
13
|
for (const { fieldName, type } of selectQueryOrMutationField) {
|
|
13
14
|
fieldTypeMap[fieldName] = type;
|
|
14
15
|
}
|
|
15
16
|
const schemaHeadersFactory = (0, string_interpolation_1.getInterpolatedHeadersFactory)(schemaHeaders);
|
|
16
|
-
logger
|
|
17
|
+
logger === null || logger === void 0 ? void 0 : logger.debug(`Fetching OpenAPI Document from ${source}`);
|
|
17
18
|
let oasOrSwagger = typeof source === 'string'
|
|
18
19
|
? await (0, utils_1.readFileOrUrl)(source, {
|
|
19
20
|
cwd,
|
|
@@ -106,7 +107,7 @@ async function getJSONSchemaOptionsFromOpenAPIOptions(name, { source, fallbackFo
|
|
|
106
107
|
operationConfig.queryParamArgMap[paramObj.name] = argName;
|
|
107
108
|
if (paramObj.name in queryParams) {
|
|
108
109
|
paramObj.required = false;
|
|
109
|
-
if (!paramObj.schema
|
|
110
|
+
if (!((_a = paramObj.schema) === null || _a === void 0 ? void 0 : _a.default)) {
|
|
110
111
|
paramObj.schema = paramObj.schema || {
|
|
111
112
|
type: 'string',
|
|
112
113
|
};
|
|
@@ -157,19 +158,19 @@ async function getJSONSchemaOptionsFromOpenAPIOptions(name, { source, fallbackFo
|
|
|
157
158
|
}
|
|
158
159
|
}
|
|
159
160
|
else {
|
|
160
|
-
if (paramObj.schema
|
|
161
|
+
if ((_b = paramObj.schema) === null || _b === void 0 ? void 0 : _b.default) {
|
|
161
162
|
delete paramObj.schema.default;
|
|
162
163
|
}
|
|
163
164
|
}
|
|
164
165
|
}
|
|
165
166
|
if (typeof operationHeaders === 'function') {
|
|
166
167
|
paramObj.required = false;
|
|
167
|
-
if (paramObj.schema
|
|
168
|
+
if ((_c = paramObj.schema) === null || _c === void 0 ? void 0 : _c.default) {
|
|
168
169
|
delete paramObj.schema.default;
|
|
169
170
|
}
|
|
170
171
|
}
|
|
171
172
|
let defaultValueSuffix = '';
|
|
172
|
-
if (paramObj.schema
|
|
173
|
+
if ((_d = paramObj.schema) === null || _d === void 0 ? void 0 : _d.default) {
|
|
173
174
|
defaultValueSuffix = `:${paramObj.schema.default}`;
|
|
174
175
|
}
|
|
175
176
|
operationConfig.headers[paramObj.name] = `{args.${argName}${defaultValueSuffix}}`;
|
|
@@ -196,7 +197,7 @@ async function getJSONSchemaOptionsFromOpenAPIOptions(name, { source, fallbackFo
|
|
|
196
197
|
break;
|
|
197
198
|
}
|
|
198
199
|
operationArgTypeMap[argName] =
|
|
199
|
-
paramObj.schema || paramObj.content
|
|
200
|
+
paramObj.schema || ((_f = (_e = paramObj.content) === null || _e === void 0 ? void 0 : _e['application/json']) === null || _f === void 0 ? void 0 : _f.schema) || paramObj;
|
|
200
201
|
if (!operationArgTypeMap[argName].title) {
|
|
201
202
|
operationArgTypeMap[argName].name = paramObj.name;
|
|
202
203
|
}
|
|
@@ -218,15 +219,15 @@ async function getJSONSchemaOptionsFromOpenAPIOptions(name, { source, fallbackFo
|
|
|
218
219
|
const requestBodyObj = methodObj.requestBody;
|
|
219
220
|
if ('content' in requestBodyObj) {
|
|
220
221
|
const contentKey = Object.keys(requestBodyObj.content)[0];
|
|
221
|
-
const contentSchema = requestBodyObj.content[contentKey]
|
|
222
|
+
const contentSchema = (_g = requestBodyObj.content[contentKey]) === null || _g === void 0 ? void 0 : _g.schema;
|
|
222
223
|
if (contentSchema && Object.keys(contentSchema).length > 0) {
|
|
223
224
|
operationConfig.requestSchema = contentSchema;
|
|
224
225
|
}
|
|
225
|
-
const examplesObj = requestBodyObj.content[contentKey]
|
|
226
|
+
const examplesObj = (_h = requestBodyObj.content[contentKey]) === null || _h === void 0 ? void 0 : _h.examples;
|
|
226
227
|
if (examplesObj) {
|
|
227
228
|
operationConfig.requestSample = Object.values(examplesObj)[0];
|
|
228
229
|
}
|
|
229
|
-
if (!operationConfig.headers
|
|
230
|
+
if (!((_j = operationConfig.headers) === null || _j === void 0 ? void 0 : _j['Content-Type']) && typeof contentKey === 'string') {
|
|
230
231
|
operationConfig.headers = operationConfig.headers || {};
|
|
231
232
|
operationConfig.headers['Content-Type'] = contentKey;
|
|
232
233
|
}
|
|
@@ -262,7 +263,7 @@ async function getJSONSchemaOptionsFromOpenAPIOptions(name, { source, fallbackFo
|
|
|
262
263
|
const jsonLikeMimeTypes = allMimeTypes.filter(c => c !== '*/*' && c.toString().includes('json'));
|
|
263
264
|
const mimeTypes = jsonLikeMimeTypes.length > 0 ? jsonLikeMimeTypes : allMimeTypes;
|
|
264
265
|
// If we have a better accept header, overwrite User's choice
|
|
265
|
-
if ((!operationConfig.headers
|
|
266
|
+
if ((!((_k = operationConfig.headers) === null || _k === void 0 ? void 0 : _k.accept) && !((_l = operationConfig.headers) === null || _l === void 0 ? void 0 : _l.Accept)) ||
|
|
266
267
|
mimeTypes.length === 1) {
|
|
267
268
|
operationConfig.headers = operationConfig.headers || {};
|
|
268
269
|
if (operationConfig.headers.Accept) {
|
|
@@ -406,7 +407,7 @@ async function getJSONSchemaOptionsFromOpenAPIOptions(name, { source, fallbackFo
|
|
|
406
407
|
}
|
|
407
408
|
}
|
|
408
409
|
if (!operationConfig.field) {
|
|
409
|
-
methodObj.operationId = (0, utils_js_1.getFieldNameFromPath)(relativePath, method, schemaObj
|
|
410
|
+
methodObj.operationId = (0, utils_js_1.getFieldNameFromPath)(relativePath, method, schemaObj === null || schemaObj === void 0 ? void 0 : schemaObj.$resolvedRef);
|
|
410
411
|
// Operation ID might not be avaiable so let's generate field name from path and response type schema
|
|
411
412
|
operationConfig.field = (0, utils_1.sanitizeNameForGraphQL)(methodObj.operationId);
|
|
412
413
|
}
|
|
@@ -442,7 +443,7 @@ async function getJSONSchemaOptionsFromOpenAPIOptions(name, { source, fallbackFo
|
|
|
442
443
|
callbackOperationConfig.field = callbackOperation.operationId;
|
|
443
444
|
callbackOperationConfig.description =
|
|
444
445
|
callbackOperation.description || callbackOperation.summary;
|
|
445
|
-
const requestBodyContents = callbackOperation.requestBody
|
|
446
|
+
const requestBodyContents = (_m = callbackOperation.requestBody) === null || _m === void 0 ? void 0 : _m.content;
|
|
446
447
|
if (requestBodyContents) {
|
|
447
448
|
callbackOperationConfig.responseSchema = requestBodyContents[Object.keys(requestBodyContents)[0]].schema;
|
|
448
449
|
}
|
|
@@ -5,12 +5,13 @@ import { getInterpolatedHeadersFactory } from '@graphql-mesh/string-interpolatio
|
|
|
5
5
|
import { defaultImportFn, DefaultLogger, readFileOrUrl, sanitizeNameForGraphQL, } from '@graphql-mesh/utils';
|
|
6
6
|
import { getFieldNameFromPath } from './utils.js';
|
|
7
7
|
export async function getJSONSchemaOptionsFromOpenAPIOptions(name, { source, fallbackFormat, cwd, fetch: fetchFn, endpoint, schemaHeaders, operationHeaders, queryParams = {}, selectQueryOrMutationField = [], logger = new DefaultLogger('getJSONSchemaOptionsFromOpenAPIOptions'), }) {
|
|
8
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
|
8
9
|
const fieldTypeMap = {};
|
|
9
10
|
for (const { fieldName, type } of selectQueryOrMutationField) {
|
|
10
11
|
fieldTypeMap[fieldName] = type;
|
|
11
12
|
}
|
|
12
13
|
const schemaHeadersFactory = getInterpolatedHeadersFactory(schemaHeaders);
|
|
13
|
-
logger
|
|
14
|
+
logger === null || logger === void 0 ? void 0 : logger.debug(`Fetching OpenAPI Document from ${source}`);
|
|
14
15
|
let oasOrSwagger = typeof source === 'string'
|
|
15
16
|
? await readFileOrUrl(source, {
|
|
16
17
|
cwd,
|
|
@@ -103,7 +104,7 @@ export async function getJSONSchemaOptionsFromOpenAPIOptions(name, { source, fal
|
|
|
103
104
|
operationConfig.queryParamArgMap[paramObj.name] = argName;
|
|
104
105
|
if (paramObj.name in queryParams) {
|
|
105
106
|
paramObj.required = false;
|
|
106
|
-
if (!paramObj.schema
|
|
107
|
+
if (!((_a = paramObj.schema) === null || _a === void 0 ? void 0 : _a.default)) {
|
|
107
108
|
paramObj.schema = paramObj.schema || {
|
|
108
109
|
type: 'string',
|
|
109
110
|
};
|
|
@@ -154,19 +155,19 @@ export async function getJSONSchemaOptionsFromOpenAPIOptions(name, { source, fal
|
|
|
154
155
|
}
|
|
155
156
|
}
|
|
156
157
|
else {
|
|
157
|
-
if (paramObj.schema
|
|
158
|
+
if ((_b = paramObj.schema) === null || _b === void 0 ? void 0 : _b.default) {
|
|
158
159
|
delete paramObj.schema.default;
|
|
159
160
|
}
|
|
160
161
|
}
|
|
161
162
|
}
|
|
162
163
|
if (typeof operationHeaders === 'function') {
|
|
163
164
|
paramObj.required = false;
|
|
164
|
-
if (paramObj.schema
|
|
165
|
+
if ((_c = paramObj.schema) === null || _c === void 0 ? void 0 : _c.default) {
|
|
165
166
|
delete paramObj.schema.default;
|
|
166
167
|
}
|
|
167
168
|
}
|
|
168
169
|
let defaultValueSuffix = '';
|
|
169
|
-
if (paramObj.schema
|
|
170
|
+
if ((_d = paramObj.schema) === null || _d === void 0 ? void 0 : _d.default) {
|
|
170
171
|
defaultValueSuffix = `:${paramObj.schema.default}`;
|
|
171
172
|
}
|
|
172
173
|
operationConfig.headers[paramObj.name] = `{args.${argName}${defaultValueSuffix}}`;
|
|
@@ -193,7 +194,7 @@ export async function getJSONSchemaOptionsFromOpenAPIOptions(name, { source, fal
|
|
|
193
194
|
break;
|
|
194
195
|
}
|
|
195
196
|
operationArgTypeMap[argName] =
|
|
196
|
-
paramObj.schema || paramObj.content
|
|
197
|
+
paramObj.schema || ((_f = (_e = paramObj.content) === null || _e === void 0 ? void 0 : _e['application/json']) === null || _f === void 0 ? void 0 : _f.schema) || paramObj;
|
|
197
198
|
if (!operationArgTypeMap[argName].title) {
|
|
198
199
|
operationArgTypeMap[argName].name = paramObj.name;
|
|
199
200
|
}
|
|
@@ -215,15 +216,15 @@ export async function getJSONSchemaOptionsFromOpenAPIOptions(name, { source, fal
|
|
|
215
216
|
const requestBodyObj = methodObj.requestBody;
|
|
216
217
|
if ('content' in requestBodyObj) {
|
|
217
218
|
const contentKey = Object.keys(requestBodyObj.content)[0];
|
|
218
|
-
const contentSchema = requestBodyObj.content[contentKey]
|
|
219
|
+
const contentSchema = (_g = requestBodyObj.content[contentKey]) === null || _g === void 0 ? void 0 : _g.schema;
|
|
219
220
|
if (contentSchema && Object.keys(contentSchema).length > 0) {
|
|
220
221
|
operationConfig.requestSchema = contentSchema;
|
|
221
222
|
}
|
|
222
|
-
const examplesObj = requestBodyObj.content[contentKey]
|
|
223
|
+
const examplesObj = (_h = requestBodyObj.content[contentKey]) === null || _h === void 0 ? void 0 : _h.examples;
|
|
223
224
|
if (examplesObj) {
|
|
224
225
|
operationConfig.requestSample = Object.values(examplesObj)[0];
|
|
225
226
|
}
|
|
226
|
-
if (!operationConfig.headers
|
|
227
|
+
if (!((_j = operationConfig.headers) === null || _j === void 0 ? void 0 : _j['Content-Type']) && typeof contentKey === 'string') {
|
|
227
228
|
operationConfig.headers = operationConfig.headers || {};
|
|
228
229
|
operationConfig.headers['Content-Type'] = contentKey;
|
|
229
230
|
}
|
|
@@ -259,7 +260,7 @@ export async function getJSONSchemaOptionsFromOpenAPIOptions(name, { source, fal
|
|
|
259
260
|
const jsonLikeMimeTypes = allMimeTypes.filter(c => c !== '*/*' && c.toString().includes('json'));
|
|
260
261
|
const mimeTypes = jsonLikeMimeTypes.length > 0 ? jsonLikeMimeTypes : allMimeTypes;
|
|
261
262
|
// If we have a better accept header, overwrite User's choice
|
|
262
|
-
if ((!operationConfig.headers
|
|
263
|
+
if ((!((_k = operationConfig.headers) === null || _k === void 0 ? void 0 : _k.accept) && !((_l = operationConfig.headers) === null || _l === void 0 ? void 0 : _l.Accept)) ||
|
|
263
264
|
mimeTypes.length === 1) {
|
|
264
265
|
operationConfig.headers = operationConfig.headers || {};
|
|
265
266
|
if (operationConfig.headers.Accept) {
|
|
@@ -403,7 +404,7 @@ export async function getJSONSchemaOptionsFromOpenAPIOptions(name, { source, fal
|
|
|
403
404
|
}
|
|
404
405
|
}
|
|
405
406
|
if (!operationConfig.field) {
|
|
406
|
-
methodObj.operationId = getFieldNameFromPath(relativePath, method, schemaObj
|
|
407
|
+
methodObj.operationId = getFieldNameFromPath(relativePath, method, schemaObj === null || schemaObj === void 0 ? void 0 : schemaObj.$resolvedRef);
|
|
407
408
|
// Operation ID might not be avaiable so let's generate field name from path and response type schema
|
|
408
409
|
operationConfig.field = sanitizeNameForGraphQL(methodObj.operationId);
|
|
409
410
|
}
|
|
@@ -439,7 +440,7 @@ export async function getJSONSchemaOptionsFromOpenAPIOptions(name, { source, fal
|
|
|
439
440
|
callbackOperationConfig.field = callbackOperation.operationId;
|
|
440
441
|
callbackOperationConfig.description =
|
|
441
442
|
callbackOperation.description || callbackOperation.summary;
|
|
442
|
-
const requestBodyContents = callbackOperation.requestBody
|
|
443
|
+
const requestBodyContents = (_m = callbackOperation.requestBody) === null || _m === void 0 ? void 0 : _m.content;
|
|
443
444
|
if (requestBodyContents) {
|
|
444
445
|
callbackOperationConfig.responseSchema = requestBodyContents[Object.keys(requestBodyContents)[0]].schema;
|
|
445
446
|
}
|
package/package.json
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@omnigraph/openapi",
|
|
3
|
-
"version": "1.0.0-alpha-
|
|
3
|
+
"version": "1.0.0-alpha-20230523160518-5443a1139",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"peerDependencies": {
|
|
6
|
-
"@graphql-mesh/cross-helpers": "0.4.0-alpha-
|
|
7
|
-
"@graphql-mesh/types": "1.0.0-alpha-
|
|
8
|
-
"@graphql-mesh/utils": "1.0.0-alpha-
|
|
6
|
+
"@graphql-mesh/cross-helpers": "0.4.0-alpha-20230523160518-5443a1139",
|
|
7
|
+
"@graphql-mesh/types": "1.0.0-alpha-20230523160518-5443a1139",
|
|
8
|
+
"@graphql-mesh/utils": "1.0.0-alpha-20230523160518-5443a1139",
|
|
9
9
|
"graphql": "*",
|
|
10
10
|
"tslib": "^2.4.0"
|
|
11
11
|
},
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@graphql-mesh/string-interpolation": "0.5.0-alpha-
|
|
14
|
-
"@omnigraph/json-schema": "1.0.0-alpha-
|
|
13
|
+
"@graphql-mesh/string-interpolation": "0.5.0-alpha-20230523160518-5443a1139",
|
|
14
|
+
"@omnigraph/json-schema": "1.0.0-alpha-20230523160518-5443a1139",
|
|
15
15
|
"change-case": "^4.1.2",
|
|
16
|
-
"json-machete": "1.0.0-alpha-
|
|
16
|
+
"json-machete": "1.0.0-alpha-20230523160518-5443a1139",
|
|
17
17
|
"openapi-types": "^12.1.0"
|
|
18
18
|
},
|
|
19
19
|
"repository": {
|
|
@@ -22,9 +22,6 @@
|
|
|
22
22
|
"directory": "packages/loaders/openapi"
|
|
23
23
|
},
|
|
24
24
|
"license": "MIT",
|
|
25
|
-
"engines": {
|
|
26
|
-
"node": ">=16.0.0"
|
|
27
|
-
},
|
|
28
25
|
"main": "cjs/index.js",
|
|
29
26
|
"module": "esm/index.js",
|
|
30
27
|
"typings": "typings/index.d.ts",
|