@trayio/tray-openapi 5.35.0-unstable.fd7158a → 6.0.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/dist/OpenApiCodecs.d.ts +4 -207
- package/dist/OpenApiCodecs.d.ts.map +1 -1
- package/dist/OpenApiCodecs.js +3 -3
- package/dist/OpenApiSchemaImporter.d.ts +2 -2
- package/dist/OpenApiSchemaImporter.d.ts.map +1 -1
- package/dist/OpenApiSchemaImporter.js +55 -33
- package/dist/OpenApiSchemaImporter.unit.test.js +13 -24
- package/dist/OpenApiSchemaTransformer.d.ts +2 -2
- package/dist/OpenApiSchemaTransformer.d.ts.map +1 -1
- package/dist/OpenApiSchemaTransformer.js +25 -2
- package/dist/OpenApiSchemaTransformer.unit.test.js +44 -30
- package/dist/OpenApiTypeDescriptors.d.ts +32 -389
- package/dist/OpenApiTypeDescriptors.d.ts.map +1 -1
- package/dist/OpenApiTypeDescriptors.js +109 -80
- package/dist/file-generators/GenerateHandler.d.ts +2 -2
- package/dist/file-generators/GenerateHandler.d.ts.map +1 -1
- package/dist/file-generators/GenerateHandler.js +78 -75
- package/dist/file-generators/GenerateHandler.unit.test.js +97 -73
- package/dist/file-generators/GenerateHandlerTest.d.ts +2 -2
- package/dist/file-generators/GenerateHandlerTest.d.ts.map +1 -1
- package/dist/file-generators/GenerateHandlerTest.js +76 -69
- package/dist/file-generators/GenerateHandlerTest.unit.test.js +230 -206
- package/dist/file-generators/GenerateOperationJson.d.ts +2 -2
- package/dist/file-generators/GenerateOperationJson.d.ts.map +1 -1
- package/dist/file-generators/GenerateOperationJson.js +29 -4
- package/dist/file-generators/GenerateOperationJson.unit.test.js +49 -25
- package/dist/file-generators/SchemaGenerator.d.ts.map +1 -1
- package/dist/file-generators/SchemaGenerator.js +37 -14
- package/dist/file-generators/types/GenerateInputSchema.d.ts +2 -2
- package/dist/file-generators/types/GenerateInputSchema.d.ts.map +1 -1
- package/dist/file-generators/types/GenerateInputSchema.js +95 -88
- package/dist/file-generators/types/GenerateInputSchema.test.js +91 -60
- package/dist/file-generators/types/GenerateInputType.test.js +169 -143
- package/dist/file-generators/types/GenerateInputTypes.d.ts +2 -2
- package/dist/file-generators/types/GenerateInputTypes.d.ts.map +1 -1
- package/dist/file-generators/types/GenerateInputTypes.js +28 -7
- package/dist/file-generators/types/GenerateOutput.d.ts +6 -4
- package/dist/file-generators/types/GenerateOutput.d.ts.map +1 -1
- package/dist/file-generators/types/GenerateOutput.js +57 -46
- package/dist/file-generators/types/GenerateOutput.test.js +62 -35
- package/package.json +8 -6
|
@@ -1,16 +1,41 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
26
|
exports.generateOperationJson = void 0;
|
|
4
|
-
const
|
|
27
|
+
const TE = __importStar(require("fp-ts/TaskEither"));
|
|
28
|
+
const O = __importStar(require("fp-ts/Option"));
|
|
29
|
+
const function_1 = require("fp-ts/function");
|
|
5
30
|
const lodash_1 = require("lodash");
|
|
6
31
|
const generateOperationJson = (operationName, path) => {
|
|
7
|
-
const operationDescription =
|
|
32
|
+
const operationDescription = O.getOrElse(() => O.getOrElse(() => '')(path.summary))(path.description);
|
|
8
33
|
const operationNameSnakeCase = (0, lodash_1.snakeCase)(operationName);
|
|
9
34
|
const operationNameTitleCase = (0, lodash_1.startCase)((0, lodash_1.camelCase)(operationName));
|
|
10
|
-
return (0,
|
|
35
|
+
return (0, function_1.pipe)(operationDescription, TE.fromPredicate((description) => description.length > 0, () => new Error('Operation description is empty')), TE.map((description) => ({
|
|
11
36
|
name: operationNameSnakeCase,
|
|
12
37
|
title: operationNameTitleCase,
|
|
13
38
|
description,
|
|
14
|
-
})),
|
|
39
|
+
})), TE.map((operationJson) => JSON.stringify(operationJson, null, 2)), TE.mapLeft((error) => new Error(`Failed to generate operation.json for operation: ${error}`)));
|
|
15
40
|
};
|
|
16
41
|
exports.generateOperationJson = generateOperationJson;
|
|
@@ -1,21 +1,45 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const
|
|
26
|
+
const E = __importStar(require("fp-ts/Either"));
|
|
27
|
+
const O = __importStar(require("fp-ts/Option"));
|
|
4
28
|
const GenerateOperationJson_1 = require("./GenerateOperationJson");
|
|
5
29
|
describe('generateOperationJson', () => {
|
|
6
30
|
it('should generate correct data for operation.json', async () => {
|
|
7
31
|
const operationName = 'getPhoto';
|
|
8
32
|
const path = {
|
|
9
33
|
operationId: 'get_photo',
|
|
10
|
-
description:
|
|
11
|
-
summary:
|
|
12
|
-
tags:
|
|
13
|
-
parameters:
|
|
14
|
-
requestBody:
|
|
15
|
-
responses:
|
|
34
|
+
description: O.some('Get a photo'),
|
|
35
|
+
summary: O.none,
|
|
36
|
+
tags: O.some([]),
|
|
37
|
+
parameters: O.none,
|
|
38
|
+
requestBody: O.none,
|
|
39
|
+
responses: O.none,
|
|
16
40
|
};
|
|
17
|
-
const result = await
|
|
18
|
-
if (
|
|
41
|
+
const result = await (0, GenerateOperationJson_1.generateOperationJson)(operationName, path)();
|
|
42
|
+
if (E.isLeft(result)) {
|
|
19
43
|
throw new Error('expected result to be right');
|
|
20
44
|
}
|
|
21
45
|
expect(result.right).toEqual(JSON.stringify({
|
|
@@ -28,15 +52,15 @@ describe('generateOperationJson', () => {
|
|
|
28
52
|
const operationName = 'getPhoto';
|
|
29
53
|
const path = {
|
|
30
54
|
operationId: 'get_photo',
|
|
31
|
-
description:
|
|
32
|
-
summary:
|
|
33
|
-
tags:
|
|
34
|
-
parameters:
|
|
35
|
-
requestBody:
|
|
36
|
-
responses:
|
|
55
|
+
description: O.none,
|
|
56
|
+
summary: O.some('Get a photo'),
|
|
57
|
+
tags: O.some([]),
|
|
58
|
+
parameters: O.none,
|
|
59
|
+
requestBody: O.none,
|
|
60
|
+
responses: O.none,
|
|
37
61
|
};
|
|
38
|
-
const result = await
|
|
39
|
-
if (
|
|
62
|
+
const result = await (0, GenerateOperationJson_1.generateOperationJson)(operationName, path)();
|
|
63
|
+
if (E.isLeft(result)) {
|
|
40
64
|
throw new Error('expected result to be right');
|
|
41
65
|
}
|
|
42
66
|
expect(result.right).toEqual(JSON.stringify({
|
|
@@ -49,15 +73,15 @@ describe('generateOperationJson', () => {
|
|
|
49
73
|
const operationName = 'getPhoto';
|
|
50
74
|
const path = {
|
|
51
75
|
operationId: 'Get Photo',
|
|
52
|
-
description:
|
|
53
|
-
summary:
|
|
54
|
-
tags:
|
|
55
|
-
parameters:
|
|
56
|
-
requestBody:
|
|
57
|
-
responses:
|
|
76
|
+
description: O.none,
|
|
77
|
+
summary: O.some('Get a photo'),
|
|
78
|
+
tags: O.some([]),
|
|
79
|
+
parameters: O.none,
|
|
80
|
+
requestBody: O.none,
|
|
81
|
+
responses: O.none,
|
|
58
82
|
};
|
|
59
|
-
const result = await
|
|
60
|
-
if (
|
|
83
|
+
const result = await (0, GenerateOperationJson_1.generateOperationJson)(operationName, path)();
|
|
84
|
+
if (E.isLeft(result)) {
|
|
61
85
|
throw new Error('expected result to be right');
|
|
62
86
|
}
|
|
63
87
|
expect(result.right).toEqual(JSON.stringify({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SchemaGenerator.d.ts","sourceRoot":"","sources":["../../src/file-generators/SchemaGenerator.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAE/E,eAAO,MAAM,4BAA4B,
|
|
1
|
+
{"version":3,"file":"SchemaGenerator.d.ts","sourceRoot":"","sources":["../../src/file-generators/SchemaGenerator.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAE/E,eAAO,MAAM,4BAA4B,iBAC1B,QAAQ,oBAAoB,CAAC,KACzC,YAeD,CAAC"}
|
|
@@ -1,21 +1,44 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
26
|
exports.generateNonArraySchemaObject = void 0;
|
|
4
|
-
const
|
|
27
|
+
const O = __importStar(require("fp-ts/Option"));
|
|
5
28
|
const generateNonArraySchemaObject = (schemaObject) => ({
|
|
6
|
-
title:
|
|
7
|
-
type:
|
|
8
|
-
properties:
|
|
9
|
-
required:
|
|
10
|
-
additionalProperties:
|
|
11
|
-
allOf:
|
|
12
|
-
anyOf:
|
|
13
|
-
oneOf:
|
|
14
|
-
not:
|
|
15
|
-
in:
|
|
16
|
-
default:
|
|
17
|
-
nullable:
|
|
18
|
-
enum:
|
|
29
|
+
title: O.none,
|
|
30
|
+
type: O.none,
|
|
31
|
+
properties: O.none,
|
|
32
|
+
required: O.none,
|
|
33
|
+
additionalProperties: O.some(false),
|
|
34
|
+
allOf: O.none,
|
|
35
|
+
anyOf: O.none,
|
|
36
|
+
oneOf: O.none,
|
|
37
|
+
not: O.none,
|
|
38
|
+
in: O.none,
|
|
39
|
+
default: O.none,
|
|
40
|
+
nullable: O.none,
|
|
41
|
+
enum: O.none,
|
|
19
42
|
...schemaObject,
|
|
20
43
|
});
|
|
21
44
|
exports.generateNonArraySchemaObject = generateNonArraySchemaObject;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as E from 'fp-ts/Either';
|
|
2
2
|
import { Path, SchemaObject } from '../../OpenApiTypeDescriptors';
|
|
3
|
-
export declare const generateInputSchema: (endpoint: Path) =>
|
|
3
|
+
export declare const generateInputSchema: (endpoint: Path) => E.Either<Error, SchemaObject>;
|
|
4
4
|
//# sourceMappingURL=GenerateInputSchema.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GenerateInputSchema.d.ts","sourceRoot":"","sources":["../../../src/file-generators/types/GenerateInputSchema.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"GenerateInputSchema.d.ts","sourceRoot":"","sources":["../../../src/file-generators/types/GenerateInputSchema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,cAAc,CAAC;AAQlC,OAAO,EACN,IAAI,EAGJ,YAAY,EAEZ,MAAM,8BAA8B,CAAC;AAuJtC,eAAO,MAAM,mBAAmB,aACrB,IAAI,KACZ,EAAE,MAAM,CAAC,KAAK,EAAE,YAAY,CAiC9B,CAAC"}
|
|
@@ -1,44 +1,63 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
26
|
exports.generateInputSchema = void 0;
|
|
4
|
-
const
|
|
27
|
+
const E = __importStar(require("fp-ts/Either"));
|
|
28
|
+
const function_1 = require("fp-ts/function");
|
|
5
29
|
const lodash_1 = require("lodash");
|
|
30
|
+
const O = __importStar(require("fp-ts/Option"));
|
|
6
31
|
const openapi_schema_to_json_schema_1 = require("@openapi-contrib/openapi-schema-to-json-schema");
|
|
7
32
|
const CompositeCodec_1 = require("@trayio/commons/codec/CompositeCodec");
|
|
8
33
|
const RemoveNullValuesCodec_1 = require("@trayio/commons/codec/RemoveNullValuesCodec");
|
|
9
34
|
const OpenApiCodecs_1 = require("../../OpenApiCodecs");
|
|
10
35
|
const OpenApiTypeDescriptors_1 = require("../../OpenApiTypeDescriptors");
|
|
11
36
|
const mergeRequired = (params, body) => {
|
|
12
|
-
const requiredBody =
|
|
13
|
-
|
|
14
|
-
onSome: (required) => required,
|
|
15
|
-
});
|
|
16
|
-
const requiredParams = effect_1.Option.match(params.required, {
|
|
17
|
-
onNone: () => [],
|
|
18
|
-
onSome: (required) => required,
|
|
19
|
-
});
|
|
37
|
+
const requiredBody = O.fold(() => [], (required) => required)(body.required);
|
|
38
|
+
const requiredParams = O.fold(() => [], (required) => required)(params.required);
|
|
20
39
|
if ((0, lodash_1.isArray)(requiredBody) && (0, lodash_1.isArray)(requiredParams)) {
|
|
21
40
|
return [...requiredBody, ...requiredParams];
|
|
22
41
|
}
|
|
23
42
|
return [];
|
|
24
43
|
};
|
|
25
44
|
const mergeParamsAndBody = (params, body) => ({
|
|
26
|
-
title:
|
|
27
|
-
type:
|
|
28
|
-
properties:
|
|
29
|
-
...(
|
|
30
|
-
...(
|
|
45
|
+
title: O.none,
|
|
46
|
+
type: O.some('object'),
|
|
47
|
+
properties: O.some({
|
|
48
|
+
...(O.isSome(body.properties) && body.properties.value),
|
|
49
|
+
...(O.isSome(params.properties) && params.properties.value),
|
|
31
50
|
}),
|
|
32
|
-
required:
|
|
33
|
-
additionalProperties:
|
|
34
|
-
allOf:
|
|
35
|
-
anyOf:
|
|
36
|
-
oneOf:
|
|
37
|
-
not:
|
|
38
|
-
in:
|
|
39
|
-
default:
|
|
40
|
-
nullable:
|
|
41
|
-
enum:
|
|
51
|
+
required: O.some(mergeRequired(params, body)),
|
|
52
|
+
additionalProperties: O.some(false),
|
|
53
|
+
allOf: O.none,
|
|
54
|
+
anyOf: O.none,
|
|
55
|
+
oneOf: O.none,
|
|
56
|
+
not: O.none,
|
|
57
|
+
in: O.none,
|
|
58
|
+
default: O.none,
|
|
59
|
+
nullable: O.none,
|
|
60
|
+
enum: O.none,
|
|
42
61
|
});
|
|
43
62
|
const transformInput = (parameters) => {
|
|
44
63
|
const transformedParameters = {};
|
|
@@ -48,10 +67,9 @@ const transformInput = (parameters) => {
|
|
|
48
67
|
const parameterWithNoOptions = codecWithNullValueRemoval.encode(parameter);
|
|
49
68
|
const parameterWithJsdocAnnotation = {
|
|
50
69
|
...parameterWithNoOptions,
|
|
51
|
-
description: `@description ${
|
|
70
|
+
description: `@description ${O.getOrElse(() => '<Replace Description>')(parameter.description)}`,
|
|
52
71
|
};
|
|
53
|
-
|
|
54
|
-
const decodedParam = OpenApiTypeDescriptors_1.schemaObjectTypeCodec.decode({
|
|
72
|
+
const decodedParam = OpenApiTypeDescriptors_1.schemaObjectTypeDescriptor.decode({
|
|
55
73
|
...(0, openapi_schema_to_json_schema_1.fromParameter)(parameterWithJsdocAnnotation),
|
|
56
74
|
in: parameter.in,
|
|
57
75
|
});
|
|
@@ -59,93 +77,82 @@ const transformInput = (parameters) => {
|
|
|
59
77
|
throw new Error('Failed to decode params');
|
|
60
78
|
}
|
|
61
79
|
transformedParameters[parameter.name] = decodedParam.right;
|
|
62
|
-
if (
|
|
63
|
-
parameter.required.value === true) {
|
|
80
|
+
if (O.isSome(parameter.required) && parameter.required.value === true) {
|
|
64
81
|
requiredParameters.push(parameter.name);
|
|
65
82
|
}
|
|
66
83
|
});
|
|
67
84
|
return {
|
|
68
|
-
title:
|
|
69
|
-
type:
|
|
70
|
-
properties:
|
|
71
|
-
required:
|
|
72
|
-
additionalProperties:
|
|
73
|
-
allOf:
|
|
74
|
-
anyOf:
|
|
75
|
-
oneOf:
|
|
76
|
-
not:
|
|
77
|
-
in:
|
|
78
|
-
default:
|
|
79
|
-
nullable:
|
|
80
|
-
enum:
|
|
85
|
+
title: O.none,
|
|
86
|
+
type: O.some('object'),
|
|
87
|
+
properties: O.some(transformedParameters),
|
|
88
|
+
required: O.some([...requiredParameters]),
|
|
89
|
+
additionalProperties: O.some(false),
|
|
90
|
+
allOf: O.none,
|
|
91
|
+
anyOf: O.none,
|
|
92
|
+
oneOf: O.none,
|
|
93
|
+
not: O.none,
|
|
94
|
+
in: O.none,
|
|
95
|
+
default: O.none,
|
|
96
|
+
nullable: O.none,
|
|
97
|
+
enum: O.none,
|
|
81
98
|
};
|
|
82
99
|
};
|
|
83
100
|
/**
|
|
84
101
|
* OpenAPI spec's body params don't have an .in property, we add one in here since query, path, and header params do
|
|
85
102
|
*/
|
|
86
|
-
const appendInPropertyToBody = (body) =>
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
...
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
};
|
|
100
|
-
},
|
|
101
|
-
});
|
|
103
|
+
const appendInPropertyToBody = (body) => O.fold(() => body, (properties) => {
|
|
104
|
+
const propsWithInBody = Object.keys(properties).reduce((acc, name) => ({
|
|
105
|
+
...acc,
|
|
106
|
+
[name]: {
|
|
107
|
+
...properties[name],
|
|
108
|
+
in: O.some('body'),
|
|
109
|
+
},
|
|
110
|
+
}), {});
|
|
111
|
+
return {
|
|
112
|
+
...body,
|
|
113
|
+
properties: O.some(propsWithInBody),
|
|
114
|
+
};
|
|
115
|
+
})(body.properties);
|
|
102
116
|
const blankOutputSchema = () => ({
|
|
103
|
-
title:
|
|
104
|
-
type:
|
|
105
|
-
properties:
|
|
106
|
-
required:
|
|
107
|
-
additionalProperties:
|
|
108
|
-
allOf:
|
|
109
|
-
anyOf:
|
|
110
|
-
oneOf:
|
|
111
|
-
not:
|
|
112
|
-
in:
|
|
113
|
-
default:
|
|
114
|
-
nullable:
|
|
115
|
-
enum:
|
|
117
|
+
title: O.none,
|
|
118
|
+
type: O.none,
|
|
119
|
+
properties: O.none,
|
|
120
|
+
required: O.none,
|
|
121
|
+
additionalProperties: O.some(false),
|
|
122
|
+
allOf: O.none,
|
|
123
|
+
anyOf: O.none,
|
|
124
|
+
oneOf: O.none,
|
|
125
|
+
not: O.none,
|
|
126
|
+
in: O.none,
|
|
127
|
+
default: O.none,
|
|
128
|
+
nullable: O.none,
|
|
129
|
+
enum: O.none,
|
|
116
130
|
});
|
|
117
131
|
const getApplicationJsonMediaType = (content) => {
|
|
118
|
-
if (!Object.keys(content).length)
|
|
119
|
-
return
|
|
120
|
-
}
|
|
132
|
+
if (!Object.keys(content).length)
|
|
133
|
+
return E.right({ schema: O.none });
|
|
121
134
|
// TODO: we should support any value here, but there may also be more than 1 media type so we need to iterate through
|
|
122
135
|
// and combine all the schemas within into a single set of inputs
|
|
123
136
|
const mediaTypeApplicationJson = Object.keys(content).find((mediaType) => /^application\/.*json$/.test(mediaType));
|
|
124
137
|
if (mediaTypeApplicationJson) {
|
|
125
|
-
return
|
|
138
|
+
return E.right(content[mediaTypeApplicationJson]);
|
|
126
139
|
}
|
|
127
140
|
const mediaTypes = Object.keys(content);
|
|
128
|
-
return
|
|
141
|
+
return E.left(new Error(`Unsupported media type: ${mediaTypes}`));
|
|
129
142
|
};
|
|
130
143
|
const generateInputSchema = (endpoint) => {
|
|
131
|
-
const parameters =
|
|
132
|
-
const requestBody =
|
|
144
|
+
const parameters = O.toNullable(endpoint.parameters);
|
|
145
|
+
const requestBody = O.toNullable(endpoint.requestBody);
|
|
133
146
|
if (parameters && !requestBody) {
|
|
134
|
-
return
|
|
147
|
+
return E.right(transformInput(parameters));
|
|
135
148
|
}
|
|
136
149
|
if (requestBody && !parameters) {
|
|
137
|
-
return (0,
|
|
138
|
-
onNone: () => blankOutputSchema(),
|
|
139
|
-
onSome: (schema) => appendInPropertyToBody(schema),
|
|
140
|
-
})));
|
|
150
|
+
return (0, function_1.pipe)(getApplicationJsonMediaType(requestBody.content), E.map((mediaTypeObject) => O.fold(() => blankOutputSchema(), (schema) => appendInPropertyToBody(schema))(mediaTypeObject.schema)));
|
|
141
151
|
}
|
|
142
152
|
if (requestBody && parameters) {
|
|
143
153
|
const params = transformInput(parameters);
|
|
144
|
-
return (0,
|
|
145
|
-
onNone: () => blankOutputSchema(),
|
|
146
|
-
onSome: (schema) => appendInPropertyToBody(schema),
|
|
147
|
-
})), effect_1.Either.flatMap((schema) => effect_1.Either.right(mergeParamsAndBody(params, schema))));
|
|
154
|
+
return (0, function_1.pipe)(getApplicationJsonMediaType(requestBody.content), E.map((mediaTypeObject) => O.fold(() => blankOutputSchema(), (schema) => appendInPropertyToBody(schema))(mediaTypeObject.schema)), E.chain((schema) => E.right(mergeParamsAndBody(params, schema))));
|
|
148
155
|
}
|
|
149
|
-
return
|
|
156
|
+
return E.right(blankOutputSchema());
|
|
150
157
|
};
|
|
151
158
|
exports.generateInputSchema = generateInputSchema;
|