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