@sapporta/rest-open-api 3.52.1 → 3.52.2
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/CHANGELOG.md +6 -0
- package/README.md +76 -9
- package/index.cjs.d.ts +1 -0
- package/index.cjs.default.js +1 -0
- package/index.cjs.js +673 -0
- package/index.cjs.mjs +2 -0
- package/index.esm.js +668 -0
- package/package.json +15 -5
- package/src/index.d.ts +2 -0
- package/src/lib/contract-traversal.d.ts +14 -0
- package/src/lib/parsers/body.d.ts +14 -0
- package/src/lib/parsers/headers.d.ts +14 -0
- package/src/lib/parsers/path-params.d.ts +20 -0
- package/src/lib/parsers/query-params.d.ts +15 -0
- package/src/lib/parsers/test-helpers.d.ts +4 -0
- package/src/lib/parsers/utils.d.ts +11 -0
- package/src/lib/ts-rest-open-api.d.ts +46 -0
- package/src/lib/types.d.ts +83 -0
- package/src/lib/utils.d.ts +5 -0
- package/.babelrc +0 -10
- package/.eslintrc.json +0 -21
- package/jest.config.ts +0 -16
- package/project.json +0 -51
- package/src/index.ts +0 -6
- package/src/lib/contract-traversal.ts +0 -217
- package/src/lib/parsers/body.ts +0 -71
- package/src/lib/parsers/headers.ts +0 -163
- package/src/lib/parsers/path-params.spec.ts +0 -235
- package/src/lib/parsers/path-params.ts +0 -140
- package/src/lib/parsers/query-params.spec.ts +0 -129
- package/src/lib/parsers/query-params.ts +0 -89
- package/src/lib/parsers/test-helpers.ts +0 -26
- package/src/lib/parsers/utils.spec.ts +0 -117
- package/src/lib/parsers/utils.ts +0 -82
- package/src/lib/ts-rest-open-api.ts +0 -245
- package/src/lib/types.ts +0 -109
- package/src/lib/utils.ts +0 -92
- package/tsconfig.json +0 -22
- package/tsconfig.lib.json +0 -10
- package/tsconfig.spec.json +0 -9
- package/typedoc.json +0 -5
- /package/src/lib/parsers/{index.ts → index.d.ts} +0 -0
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { AppRouter } from '@sapporta/rest-core';
|
|
2
|
+
import { AsyncAndSyncHelper, PathSchemaResults, RouterPath, SchemaTransformerAsync, SchemaTransformerSync } from './types';
|
|
3
|
+
type PerformContractTraversalHelper = AsyncAndSyncHelper<{
|
|
4
|
+
contract: AppRouter;
|
|
5
|
+
jsonQuery: boolean;
|
|
6
|
+
}, {
|
|
7
|
+
transformSchema: SchemaTransformerSync;
|
|
8
|
+
}, {
|
|
9
|
+
transformSchema: SchemaTransformerAsync;
|
|
10
|
+
}, Array<RouterPath & {
|
|
11
|
+
schemaResults: PathSchemaResults;
|
|
12
|
+
}>>;
|
|
13
|
+
export declare const performContractTraversal: PerformContractTraversalHelper;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { AppRoute } from '@sapporta/rest-core';
|
|
2
|
+
import { AsyncAndSyncHelper, SchemaTransformerAsync, SchemaTransformerSync } from '../types';
|
|
3
|
+
import { SchemaObject } from 'openapi3-ts';
|
|
4
|
+
type GetBodySchemaHelper = AsyncAndSyncHelper<{
|
|
5
|
+
appRoute: AppRoute;
|
|
6
|
+
id: string;
|
|
7
|
+
concatenatedPath: string;
|
|
8
|
+
}, {
|
|
9
|
+
transformSchema: SchemaTransformerSync;
|
|
10
|
+
}, {
|
|
11
|
+
transformSchema: SchemaTransformerAsync;
|
|
12
|
+
}, SchemaObject | null>;
|
|
13
|
+
export declare const getBodySchema: GetBodySchemaHelper;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { AppRoute } from '@sapporta/rest-core';
|
|
2
|
+
import { AsyncAndSyncHelper, SchemaTransformerAsync, SchemaTransformerSync } from '../types';
|
|
3
|
+
import { ParameterObject } from 'openapi3-ts';
|
|
4
|
+
type GetHeaderParameterHelper = AsyncAndSyncHelper<{
|
|
5
|
+
appRoute: AppRoute;
|
|
6
|
+
id: string;
|
|
7
|
+
concatenatedPath: string;
|
|
8
|
+
}, {
|
|
9
|
+
transformSchema: SchemaTransformerSync;
|
|
10
|
+
}, {
|
|
11
|
+
transformSchema: SchemaTransformerAsync;
|
|
12
|
+
}, Array<ParameterObject>>;
|
|
13
|
+
export declare const getHeaderParameterSchema: GetHeaderParameterHelper;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { AppRoute } from '@sapporta/rest-core';
|
|
2
|
+
import { AsyncAndSyncHelper, SchemaTransformerAsync, SchemaTransformerSync } from '../types';
|
|
3
|
+
import { ParameterObject } from 'openapi3-ts';
|
|
4
|
+
type GetPathParameterHelper = AsyncAndSyncHelper<{
|
|
5
|
+
appRoute: AppRoute;
|
|
6
|
+
id: string;
|
|
7
|
+
concatenatedPath: string;
|
|
8
|
+
}, {
|
|
9
|
+
transformSchema: SchemaTransformerSync;
|
|
10
|
+
}, {
|
|
11
|
+
transformSchema: SchemaTransformerAsync;
|
|
12
|
+
}, Array<ParameterObject>>;
|
|
13
|
+
/**
|
|
14
|
+
* We build up the params from both the path and the schema.
|
|
15
|
+
*
|
|
16
|
+
* This builds up the record of name -> parameter object.
|
|
17
|
+
*/
|
|
18
|
+
export declare const getParamsFromPathOnly: (path: string) => Map<string, ParameterObject>;
|
|
19
|
+
export declare const getPathParameterSchema: GetPathParameterHelper;
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { AppRoute } from '@sapporta/rest-core';
|
|
2
|
+
import { AsyncAndSyncHelper, SchemaTransformerAsync, SchemaTransformerSync } from '../types';
|
|
3
|
+
import { ParameterObject } from 'openapi3-ts';
|
|
4
|
+
type GetQueryParameterHelper = AsyncAndSyncHelper<{
|
|
5
|
+
appRoute: AppRoute;
|
|
6
|
+
id: string;
|
|
7
|
+
concatenatedPath: string;
|
|
8
|
+
jsonQuery?: boolean;
|
|
9
|
+
}, {
|
|
10
|
+
transformSchema: SchemaTransformerSync;
|
|
11
|
+
}, {
|
|
12
|
+
transformSchema: SchemaTransformerAsync;
|
|
13
|
+
}, Array<ParameterObject>>;
|
|
14
|
+
export declare const getQueryParameterSchema: GetQueryParameterHelper;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ParameterObject, SchemaObject } from 'openapi3-ts';
|
|
2
|
+
export declare const schemaToParameter: (schema: SchemaObject, where: 'query' | 'header' | 'path', required: boolean, key: string, jsonQuery: boolean) => ParameterObject;
|
|
3
|
+
/**
|
|
4
|
+
* Convert a @type {SchemaObject} to an array of @type {ParameterObject}
|
|
5
|
+
*
|
|
6
|
+
* @param schema - Zod 4 JSON schema output
|
|
7
|
+
* @param where - The location of the parameters
|
|
8
|
+
* @param jsonQuery - Whether the schema is a JSON query
|
|
9
|
+
* @returns The parameters for the schema
|
|
10
|
+
*/
|
|
11
|
+
export declare const schemaObjectToParameters: (schema: SchemaObject, where: 'query' | 'header' | 'path', jsonQuery?: boolean) => ParameterObject[];
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { type AppRoute, type AppRouter } from '@sapporta/rest-core';
|
|
2
|
+
import type { ExamplesObject, InfoObject, OpenAPIObject, OperationObject } from 'openapi3-ts';
|
|
3
|
+
import { SchemaTransformerAsync, SchemaTransformerSync } from './types';
|
|
4
|
+
declare module 'openapi3-ts' {
|
|
5
|
+
interface SchemaObject {
|
|
6
|
+
mediaExamples?: ExamplesObject;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Generate OpenAPI specification from ts-rest router
|
|
11
|
+
*
|
|
12
|
+
* @param router - The ts-rest router to generate OpenAPI from
|
|
13
|
+
* @param apiDoc - Base OpenAPI document configuration
|
|
14
|
+
* @param options - Generation options
|
|
15
|
+
* @param options.setOperationId - Whether to set operation IDs (true, false, or 'concatenated-path')
|
|
16
|
+
* @param options.jsonQuery - Enable JSON query parameters, [see](/docs/open-api#json-query-params)
|
|
17
|
+
* @param options.operationMapper - Function to customize OpenAPI operations. Receives the operation object, app route, and operation ID
|
|
18
|
+
* @returns OpenAPI specification object
|
|
19
|
+
*/
|
|
20
|
+
export declare function generateOpenApi(router: AppRouter, apiDoc: Omit<OpenAPIObject, 'paths' | 'openapi'> & {
|
|
21
|
+
info: InfoObject;
|
|
22
|
+
}, options: {
|
|
23
|
+
setOperationId?: boolean | 'concatenated-path';
|
|
24
|
+
jsonQuery?: boolean;
|
|
25
|
+
operationMapper?: (operation: OperationObject, appRoute: AppRoute, id: string) => OperationObject;
|
|
26
|
+
schemaTransformer: SchemaTransformerSync;
|
|
27
|
+
}): OpenAPIObject;
|
|
28
|
+
/**
|
|
29
|
+
* Generate OpenAPI specification from ts-rest router with custom schema transformer
|
|
30
|
+
*
|
|
31
|
+
* @param router - The ts-rest router to generate OpenAPI from
|
|
32
|
+
* @param apiDoc - Base OpenAPI document configuration
|
|
33
|
+
* @param options - Generation options
|
|
34
|
+
* @param options.setOperationId - Whether to set operation IDs (true, false, or 'concatenated-path')
|
|
35
|
+
* @param options.jsonQuery - Enable JSON query parameters, [see](/docs/open-api#json-query-params)
|
|
36
|
+
* @param options.operationMapper - Function to customize OpenAPI operations. Receives the operation object, app route, and operation ID
|
|
37
|
+
* @param options.schemaTransformer - Custom schema transformer function.
|
|
38
|
+
*/
|
|
39
|
+
export declare function generateOpenApiAsync(router: AppRouter, apiDoc: Omit<OpenAPIObject, 'paths' | 'openapi'> & {
|
|
40
|
+
info: InfoObject;
|
|
41
|
+
}, options: {
|
|
42
|
+
setOperationId?: boolean | 'concatenated-path';
|
|
43
|
+
jsonQuery?: boolean;
|
|
44
|
+
operationMapper?: (operation: OperationObject, appRoute: AppRoute, id: string) => OperationObject;
|
|
45
|
+
schemaTransformer: SchemaTransformerAsync;
|
|
46
|
+
}): Promise<OpenAPIObject>;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { AppRoute } from '@sapporta/rest-core';
|
|
2
|
+
import { ParameterObject, SchemaObject } from 'openapi3-ts';
|
|
3
|
+
type SchemaTransformerArgs = {
|
|
4
|
+
/**
|
|
5
|
+
* The schema to transform.
|
|
6
|
+
*/
|
|
7
|
+
schema: unknown;
|
|
8
|
+
/**
|
|
9
|
+
* The app route.
|
|
10
|
+
*/
|
|
11
|
+
appRoute: AppRoute;
|
|
12
|
+
/**
|
|
13
|
+
* The key of the route in a contract e.g. `getPokemon` or `createPokemon`.
|
|
14
|
+
*/
|
|
15
|
+
id: string;
|
|
16
|
+
/**
|
|
17
|
+
* The concatenated path of the route. e.g. `pokemon.getPokemon` or `pokemon.createPokemon`.
|
|
18
|
+
*/
|
|
19
|
+
concatenatedPath: string;
|
|
20
|
+
/**
|
|
21
|
+
* Where the schema is used, can be used to conditionally transform the schema.
|
|
22
|
+
*/
|
|
23
|
+
type: 'body' | 'response' | 'query' | 'header' | 'path';
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Sync schema transformer.
|
|
27
|
+
*
|
|
28
|
+
* This will be invoked for all schemas, e.g. every query, pathParam, body, etc.
|
|
29
|
+
*
|
|
30
|
+
* You should guard against your schema type here, and return null if it's not the schema you want to transform.
|
|
31
|
+
*/
|
|
32
|
+
export type SchemaTransformerSync = (args: SchemaTransformerArgs) => SchemaObject | null;
|
|
33
|
+
/**
|
|
34
|
+
* Async schema transformer.
|
|
35
|
+
*
|
|
36
|
+
* This will be invoked for all schemas, e.g. every query, pathParam, body, etc.
|
|
37
|
+
*
|
|
38
|
+
* You should guard against your schema type here, and return null if it's not the schema you want to transform.
|
|
39
|
+
*/
|
|
40
|
+
export type SchemaTransformerAsync = (args: SchemaTransformerArgs) => Promise<SchemaObject | null>;
|
|
41
|
+
export type SchemaTransformer = SchemaTransformerSync | SchemaTransformerAsync;
|
|
42
|
+
/**
|
|
43
|
+
* We need to have many functions that are the same, but some are sync and some are async.
|
|
44
|
+
*
|
|
45
|
+
* This helper lets us make this trivial and avoids having different types for each function.
|
|
46
|
+
*
|
|
47
|
+
* @hidden
|
|
48
|
+
*/
|
|
49
|
+
export type AsyncAndSyncHelper<T, TFuncSyncArgs, TFuncAsyncArgs, TReturn> = {
|
|
50
|
+
sync: (args: T & TFuncSyncArgs) => TReturn;
|
|
51
|
+
async: (args: T & TFuncAsyncArgs) => Promise<TReturn>;
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* @hidden
|
|
55
|
+
*/
|
|
56
|
+
export type GetSyncFunction<THelper> = THelper extends AsyncAndSyncHelper<any, any, any, any> ? THelper['sync'] : never;
|
|
57
|
+
/**
|
|
58
|
+
* @hidden
|
|
59
|
+
*/
|
|
60
|
+
export type GetAsyncFunction<THelper> = THelper extends AsyncAndSyncHelper<any, any, any, any> ? THelper['async'] : never;
|
|
61
|
+
/**
|
|
62
|
+
* @hidden
|
|
63
|
+
*/
|
|
64
|
+
export type RouterPath = {
|
|
65
|
+
id: string;
|
|
66
|
+
path: string;
|
|
67
|
+
route: AppRoute;
|
|
68
|
+
paths: string[];
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* @hidden
|
|
72
|
+
*/
|
|
73
|
+
export type PathSchemaResults = {
|
|
74
|
+
path: ParameterObject[];
|
|
75
|
+
headers: ParameterObject[];
|
|
76
|
+
query: ParameterObject[];
|
|
77
|
+
body: SchemaObject | null;
|
|
78
|
+
/**
|
|
79
|
+
* Status code to response.
|
|
80
|
+
*/
|
|
81
|
+
responses: Record<string, SchemaObject>;
|
|
82
|
+
};
|
|
83
|
+
export {};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { SchemaObject, MediaTypeObject } from 'openapi3-ts';
|
|
2
|
+
export declare const convertSchemaObjectToMediaTypeObject: (input: SchemaObject) => MediaTypeObject;
|
|
3
|
+
export declare const extractReferenceSchemas: (schema: SchemaObject, referenceSchemas: {
|
|
4
|
+
[id: string]: SchemaObject;
|
|
5
|
+
}) => SchemaObject;
|
package/.babelrc
DELETED
package/.eslintrc.json
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": ["../../../.eslintrc.json"],
|
|
3
|
-
"ignorePatterns": ["!**/*"],
|
|
4
|
-
"overrides": [
|
|
5
|
-
{
|
|
6
|
-
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
|
|
7
|
-
"rules": {
|
|
8
|
-
"@typescript-eslint/no-unused-vars": ["warn"],
|
|
9
|
-
"@typescript-eslint/no-explicit-any": ["warn"]
|
|
10
|
-
}
|
|
11
|
-
},
|
|
12
|
-
{
|
|
13
|
-
"files": ["*.ts", "*.tsx"],
|
|
14
|
-
"rules": {}
|
|
15
|
-
},
|
|
16
|
-
{
|
|
17
|
-
"files": ["*.js", "*.jsx"],
|
|
18
|
-
"rules": {}
|
|
19
|
-
}
|
|
20
|
-
]
|
|
21
|
-
}
|
package/jest.config.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/* eslint-disable */
|
|
2
|
-
export default {
|
|
3
|
-
displayName: 'sapporta-rest-open-api',
|
|
4
|
-
preset: '../../../jest.preset.js',
|
|
5
|
-
globals: {},
|
|
6
|
-
transform: {
|
|
7
|
-
'^.+\\.[tj]s$': [
|
|
8
|
-
'ts-jest',
|
|
9
|
-
{
|
|
10
|
-
tsconfig: '<rootDir>/tsconfig.spec.json',
|
|
11
|
-
},
|
|
12
|
-
],
|
|
13
|
-
},
|
|
14
|
-
moduleFileExtensions: ['ts', 'js', 'html'],
|
|
15
|
-
testEnvironment: 'node',
|
|
16
|
-
};
|
package/project.json
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "sapporta-rest-open-api",
|
|
3
|
-
"$schema": "../../../node_modules/nx/schemas/project-schema.json",
|
|
4
|
-
"sourceRoot": "libs/ts-rest/open-api/src",
|
|
5
|
-
"projectType": "library",
|
|
6
|
-
"targets": {
|
|
7
|
-
"build": {
|
|
8
|
-
"executor": "@nx/rollup:rollup",
|
|
9
|
-
"outputs": ["{options.outputPath}"],
|
|
10
|
-
"options": {
|
|
11
|
-
"project": "libs/ts-rest/open-api/package.json",
|
|
12
|
-
"outputPath": "dist/libs/ts-rest/open-api",
|
|
13
|
-
"main": "libs/ts-rest/open-api/src/index.ts",
|
|
14
|
-
"tsConfig": "libs/ts-rest/open-api/tsconfig.lib.json",
|
|
15
|
-
"assets": [
|
|
16
|
-
{
|
|
17
|
-
"glob": "CHANGELOG.md",
|
|
18
|
-
"input": "libs/ts-rest/open-api",
|
|
19
|
-
"output": "."
|
|
20
|
-
},
|
|
21
|
-
{
|
|
22
|
-
"glob": "README.md",
|
|
23
|
-
"input": ".",
|
|
24
|
-
"output": "."
|
|
25
|
-
}
|
|
26
|
-
],
|
|
27
|
-
"format": ["esm", "cjs"],
|
|
28
|
-
"compiler": "tsc",
|
|
29
|
-
"rollupConfig": "tools/scripts/rollup.config.js",
|
|
30
|
-
"generateExportsField": true,
|
|
31
|
-
"updateBuildableProjectDepsInPackageJson": true
|
|
32
|
-
}
|
|
33
|
-
},
|
|
34
|
-
"lint": {
|
|
35
|
-
"executor": "@nx/eslint:lint",
|
|
36
|
-
"outputs": ["{options.outputFile}"],
|
|
37
|
-
"options": {
|
|
38
|
-
"lintFilePatterns": ["libs/ts-rest/open-api/**/*.ts"],
|
|
39
|
-
"ignorePath": ".gitignore"
|
|
40
|
-
}
|
|
41
|
-
},
|
|
42
|
-
"test": {
|
|
43
|
-
"executor": "@nx/jest:jest",
|
|
44
|
-
"outputs": ["{workspaceRoot}/coverage/libs/ts-rest/open-api"],
|
|
45
|
-
"options": {
|
|
46
|
-
"jestConfig": "libs/ts-rest/open-api/jest.config.ts"
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
},
|
|
50
|
-
"tags": []
|
|
51
|
-
}
|
package/src/index.ts
DELETED
|
@@ -1,217 +0,0 @@
|
|
|
1
|
-
import { AppRouter, isAppRoute, isAppRouteOtherResponse } from '@sapporta/rest-core';
|
|
2
|
-
import {
|
|
3
|
-
AsyncAndSyncHelper,
|
|
4
|
-
GetAsyncFunction,
|
|
5
|
-
GetSyncFunction,
|
|
6
|
-
PathSchemaResults,
|
|
7
|
-
RouterPath,
|
|
8
|
-
SchemaTransformerAsync,
|
|
9
|
-
SchemaTransformerSync,
|
|
10
|
-
} from './types';
|
|
11
|
-
import { getPathParameterSchema } from './parsers/path-params';
|
|
12
|
-
import { getHeaderParameterSchema } from './parsers/headers';
|
|
13
|
-
import { getQueryParameterSchema } from './parsers/query-params';
|
|
14
|
-
import { getBodySchema } from './parsers/body';
|
|
15
|
-
import { SchemaObject } from 'openapi3-ts';
|
|
16
|
-
|
|
17
|
-
type PerformContractTraversalHelper = AsyncAndSyncHelper<
|
|
18
|
-
{
|
|
19
|
-
contract: AppRouter;
|
|
20
|
-
jsonQuery: boolean;
|
|
21
|
-
},
|
|
22
|
-
{
|
|
23
|
-
transformSchema: SchemaTransformerSync;
|
|
24
|
-
},
|
|
25
|
-
{
|
|
26
|
-
transformSchema: SchemaTransformerAsync;
|
|
27
|
-
},
|
|
28
|
-
Array<RouterPath & { schemaResults: PathSchemaResults }>
|
|
29
|
-
>;
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Recursively step through the router and get all the individual routes with their paths etc.
|
|
33
|
-
*/
|
|
34
|
-
const getPathsFromRouter = (
|
|
35
|
-
router: AppRouter,
|
|
36
|
-
pathHistory?: string[],
|
|
37
|
-
): RouterPath[] => {
|
|
38
|
-
const paths: RouterPath[] = [];
|
|
39
|
-
|
|
40
|
-
Object.keys(router).forEach((key) => {
|
|
41
|
-
const value = router[key];
|
|
42
|
-
|
|
43
|
-
if (isAppRoute(value)) {
|
|
44
|
-
const pathWithPathParams = value.path.replace(/:(\w+)/g, '{$1}');
|
|
45
|
-
|
|
46
|
-
paths.push({
|
|
47
|
-
id: key,
|
|
48
|
-
path: pathWithPathParams,
|
|
49
|
-
route: value,
|
|
50
|
-
paths: pathHistory ?? [],
|
|
51
|
-
});
|
|
52
|
-
} else {
|
|
53
|
-
paths.push(...getPathsFromRouter(value, [...(pathHistory ?? []), key]));
|
|
54
|
-
}
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
return paths;
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
const syncFunc: GetSyncFunction<PerformContractTraversalHelper> = ({
|
|
61
|
-
contract,
|
|
62
|
-
transformSchema,
|
|
63
|
-
jsonQuery,
|
|
64
|
-
}) => {
|
|
65
|
-
const paths = getPathsFromRouter(contract);
|
|
66
|
-
|
|
67
|
-
const results: Array<RouterPath & { schemaResults: PathSchemaResults }> = [];
|
|
68
|
-
|
|
69
|
-
for (const path of paths) {
|
|
70
|
-
const concatenatedPath = [...path.paths, path.id].join('.');
|
|
71
|
-
|
|
72
|
-
const pathParams = getPathParameterSchema.sync({
|
|
73
|
-
transformSchema,
|
|
74
|
-
appRoute: path.route,
|
|
75
|
-
id: path.id,
|
|
76
|
-
concatenatedPath,
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
const headerParams = getHeaderParameterSchema.sync({
|
|
80
|
-
transformSchema,
|
|
81
|
-
appRoute: path.route,
|
|
82
|
-
id: path.id,
|
|
83
|
-
concatenatedPath,
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
const querySchema = getQueryParameterSchema.sync({
|
|
87
|
-
transformSchema,
|
|
88
|
-
appRoute: path.route,
|
|
89
|
-
id: path.id,
|
|
90
|
-
concatenatedPath,
|
|
91
|
-
jsonQuery: !!jsonQuery,
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
const bodySchema = getBodySchema.sync({
|
|
95
|
-
transformSchema,
|
|
96
|
-
appRoute: path.route,
|
|
97
|
-
id: path.id,
|
|
98
|
-
concatenatedPath,
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
const responses: Record<string, SchemaObject> = {};
|
|
102
|
-
for (const [statusCode, _response] of Object.entries(
|
|
103
|
-
path.route.responses,
|
|
104
|
-
)) {
|
|
105
|
-
const schemaValidator = isAppRouteOtherResponse(_response)
|
|
106
|
-
? _response.body
|
|
107
|
-
: _response;
|
|
108
|
-
|
|
109
|
-
const responseSchema = transformSchema({
|
|
110
|
-
schema: schemaValidator,
|
|
111
|
-
appRoute: path.route,
|
|
112
|
-
id: path.id,
|
|
113
|
-
concatenatedPath,
|
|
114
|
-
type: 'response',
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
if (responseSchema) {
|
|
118
|
-
responses[statusCode] = responseSchema;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
results.push({
|
|
123
|
-
...path,
|
|
124
|
-
schemaResults: {
|
|
125
|
-
path: pathParams,
|
|
126
|
-
headers: headerParams,
|
|
127
|
-
query: querySchema,
|
|
128
|
-
body: bodySchema,
|
|
129
|
-
responses,
|
|
130
|
-
},
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
return results;
|
|
135
|
-
};
|
|
136
|
-
|
|
137
|
-
const asyncFunc: GetAsyncFunction<PerformContractTraversalHelper> = async ({
|
|
138
|
-
contract,
|
|
139
|
-
transformSchema,
|
|
140
|
-
jsonQuery,
|
|
141
|
-
}) => {
|
|
142
|
-
const paths = getPathsFromRouter(contract);
|
|
143
|
-
|
|
144
|
-
const results: Array<RouterPath & { schemaResults: PathSchemaResults }> = [];
|
|
145
|
-
|
|
146
|
-
for (const path of paths) {
|
|
147
|
-
const concatenatedPath = [...path.paths, path.id].join('.');
|
|
148
|
-
|
|
149
|
-
const pathParams = await getPathParameterSchema.async({
|
|
150
|
-
transformSchema,
|
|
151
|
-
appRoute: path.route,
|
|
152
|
-
id: path.id,
|
|
153
|
-
concatenatedPath,
|
|
154
|
-
});
|
|
155
|
-
|
|
156
|
-
const headerParams = await getHeaderParameterSchema.async({
|
|
157
|
-
transformSchema,
|
|
158
|
-
appRoute: path.route,
|
|
159
|
-
id: path.id,
|
|
160
|
-
concatenatedPath,
|
|
161
|
-
});
|
|
162
|
-
|
|
163
|
-
const querySchema = await getQueryParameterSchema.async({
|
|
164
|
-
transformSchema,
|
|
165
|
-
appRoute: path.route,
|
|
166
|
-
id: path.id,
|
|
167
|
-
concatenatedPath,
|
|
168
|
-
jsonQuery: !!jsonQuery,
|
|
169
|
-
});
|
|
170
|
-
|
|
171
|
-
const bodySchema = await getBodySchema.async({
|
|
172
|
-
transformSchema,
|
|
173
|
-
appRoute: path.route,
|
|
174
|
-
id: path.id,
|
|
175
|
-
concatenatedPath,
|
|
176
|
-
});
|
|
177
|
-
|
|
178
|
-
const responses: Record<string, SchemaObject> = {};
|
|
179
|
-
for (const [statusCode, _response] of Object.entries(
|
|
180
|
-
path.route.responses,
|
|
181
|
-
)) {
|
|
182
|
-
const schemaValidator = isAppRouteOtherResponse(_response)
|
|
183
|
-
? _response.body
|
|
184
|
-
: _response;
|
|
185
|
-
|
|
186
|
-
const responseSchema = await transformSchema({
|
|
187
|
-
schema: schemaValidator,
|
|
188
|
-
appRoute: path.route,
|
|
189
|
-
id: path.id,
|
|
190
|
-
concatenatedPath,
|
|
191
|
-
type: 'response',
|
|
192
|
-
});
|
|
193
|
-
|
|
194
|
-
if (responseSchema) {
|
|
195
|
-
responses[statusCode] = responseSchema;
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
results.push({
|
|
200
|
-
...path,
|
|
201
|
-
schemaResults: {
|
|
202
|
-
path: pathParams,
|
|
203
|
-
headers: headerParams,
|
|
204
|
-
query: querySchema,
|
|
205
|
-
body: bodySchema,
|
|
206
|
-
responses,
|
|
207
|
-
},
|
|
208
|
-
});
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
return results;
|
|
212
|
-
};
|
|
213
|
-
|
|
214
|
-
export const performContractTraversal: PerformContractTraversalHelper = {
|
|
215
|
-
sync: syncFunc,
|
|
216
|
-
async: asyncFunc,
|
|
217
|
-
};
|
package/src/lib/parsers/body.ts
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import { AppRoute } from '@sapporta/rest-core';
|
|
2
|
-
import {
|
|
3
|
-
AsyncAndSyncHelper,
|
|
4
|
-
GetAsyncFunction,
|
|
5
|
-
GetSyncFunction,
|
|
6
|
-
SchemaTransformerAsync,
|
|
7
|
-
SchemaTransformerSync,
|
|
8
|
-
} from '../types';
|
|
9
|
-
import { SchemaObject } from 'openapi3-ts';
|
|
10
|
-
|
|
11
|
-
type GetBodySchemaHelper = AsyncAndSyncHelper<
|
|
12
|
-
{
|
|
13
|
-
appRoute: AppRoute;
|
|
14
|
-
id: string;
|
|
15
|
-
concatenatedPath: string;
|
|
16
|
-
},
|
|
17
|
-
{
|
|
18
|
-
transformSchema: SchemaTransformerSync;
|
|
19
|
-
},
|
|
20
|
-
{
|
|
21
|
-
transformSchema: SchemaTransformerAsync;
|
|
22
|
-
},
|
|
23
|
-
SchemaObject | null
|
|
24
|
-
>;
|
|
25
|
-
|
|
26
|
-
const syncFunc: GetSyncFunction<GetBodySchemaHelper> = ({
|
|
27
|
-
transformSchema,
|
|
28
|
-
appRoute,
|
|
29
|
-
id,
|
|
30
|
-
concatenatedPath,
|
|
31
|
-
}) => {
|
|
32
|
-
const schema = 'body' in appRoute ? appRoute.body : undefined;
|
|
33
|
-
|
|
34
|
-
const transformedSchema = transformSchema({
|
|
35
|
-
schema,
|
|
36
|
-
appRoute,
|
|
37
|
-
id,
|
|
38
|
-
concatenatedPath,
|
|
39
|
-
type: 'body',
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
if (!transformedSchema) {
|
|
43
|
-
return null;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
return transformedSchema;
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
const asyncFunc: GetAsyncFunction<GetBodySchemaHelper> = async ({
|
|
50
|
-
transformSchema,
|
|
51
|
-
appRoute,
|
|
52
|
-
id,
|
|
53
|
-
concatenatedPath,
|
|
54
|
-
}) => {
|
|
55
|
-
const schema = 'body' in appRoute ? appRoute.body : undefined;
|
|
56
|
-
|
|
57
|
-
const transformedSchema = await transformSchema({
|
|
58
|
-
schema,
|
|
59
|
-
appRoute,
|
|
60
|
-
id,
|
|
61
|
-
concatenatedPath,
|
|
62
|
-
type: 'body',
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
return transformedSchema;
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
export const getBodySchema: GetBodySchemaHelper = {
|
|
69
|
-
sync: syncFunc,
|
|
70
|
-
async: asyncFunc,
|
|
71
|
-
};
|