snap-on-openapi 1.0.1
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/README.md +643 -0
- package/dist/OpenApi.d.ts +58 -0
- package/dist/OpenApi.js +272 -0
- package/dist/README.md +643 -0
- package/dist/assets/stoplight.html +27 -0
- package/dist/assets/swagger.html +892 -0
- package/dist/enums/ErrorCode.d.ts +5 -0
- package/dist/enums/ErrorCode.js +6 -0
- package/dist/enums/Methods.d.ts +7 -0
- package/dist/enums/Methods.js +8 -0
- package/dist/enums/SampleRouteType.d.ts +3 -0
- package/dist/enums/SampleRouteType.js +4 -0
- package/dist/enums/ValidationLocations.d.ts +6 -0
- package/dist/enums/ValidationLocations.js +7 -0
- package/dist/index.d.ts +39 -0
- package/dist/index.js +23 -0
- package/dist/services/ClientGenerator/ClientGenerator.d.ts +9 -0
- package/dist/services/ClientGenerator/ClientGenerator.js +48 -0
- package/dist/services/ConfigBuilder/ConfigBuilder.d.ts +31 -0
- package/dist/services/ConfigBuilder/ConfigBuilder.js +65 -0
- package/dist/services/ConfigBuilder/types/DefaultConfig.d.ts +22 -0
- package/dist/services/ConfigBuilder/types/DefaultConfig.js +47 -0
- package/dist/services/ConfigBuilder/types/DefaultErrorMap.d.ts +113 -0
- package/dist/services/ConfigBuilder/types/DefaultErrorMap.js +21 -0
- package/dist/services/ConfigBuilder/types/DefaultRouteContextMap.d.ts +6 -0
- package/dist/services/ConfigBuilder/types/DefaultRouteContextMap.js +3 -0
- package/dist/services/ConfigBuilder/types/DefaultRouteMap.d.ts +12 -0
- package/dist/services/ConfigBuilder/types/DefaultRouteMap.js +9 -0
- package/dist/services/ConfigBuilder/types/DefaultRouteParamsMap.d.ts +5 -0
- package/dist/services/ConfigBuilder/types/DefaultRouteParamsMap.js +3 -0
- package/dist/services/ConfigBuilder/types/OpenApiConstructor.d.ts +2 -0
- package/dist/services/ConfigBuilder/types/OpenApiConstructor.js +1 -0
- package/dist/services/DescriptionChecker/DescriptionChecker.d.ts +16 -0
- package/dist/services/DescriptionChecker/DescriptionChecker.js +47 -0
- package/dist/services/DevelopmentUtils/DevelopmentUtils.d.ts +4 -0
- package/dist/services/DevelopmentUtils/DevelopmentUtils.js +15 -0
- package/dist/services/ExpressWrapper/ExpressWrapper.d.ts +15 -0
- package/dist/services/ExpressWrapper/ExpressWrapper.js +68 -0
- package/dist/services/ExpressWrapper/types/ExpressApp.d.ts +8 -0
- package/dist/services/ExpressWrapper/types/ExpressApp.js +1 -0
- package/dist/services/ExpressWrapper/types/ExpressHandler.d.ts +3 -0
- package/dist/services/ExpressWrapper/types/ExpressHandler.js +1 -0
- package/dist/services/ExpressWrapper/types/ExpressRequest.d.ts +8 -0
- package/dist/services/ExpressWrapper/types/ExpressRequest.js +1 -0
- package/dist/services/ExpressWrapper/types/ExpressResponse.d.ts +6 -0
- package/dist/services/ExpressWrapper/types/ExpressResponse.js +1 -0
- package/dist/services/Logger/Logger.d.ts +15 -0
- package/dist/services/Logger/Logger.js +100 -0
- package/dist/services/Logger/types/LogLevel.d.ts +6 -0
- package/dist/services/Logger/types/LogLevel.js +7 -0
- package/dist/services/RoutingFactory/RoutingFactory.d.ts +10 -0
- package/dist/services/RoutingFactory/RoutingFactory.js +23 -0
- package/dist/services/SchemaGenerator/SchemaGenerator.d.ts +19 -0
- package/dist/services/SchemaGenerator/SchemaGenerator.js +131 -0
- package/dist/services/TanstackStartWrapper/TanstackStartWrapper.d.ts +35 -0
- package/dist/services/TanstackStartWrapper/TanstackStartWrapper.js +67 -0
- package/dist/services/TestUtils/TestUtils.d.ts +13 -0
- package/dist/services/TestUtils/TestUtils.js +48 -0
- package/dist/services/ValidationUtils/ValidationUtils.d.ts +56 -0
- package/dist/services/ValidationUtils/ValidationUtils.js +38 -0
- package/dist/services/ValidationUtils/transformers/stringBooleanTransformer.d.ts +3 -0
- package/dist/services/ValidationUtils/transformers/stringBooleanTransformer.js +5 -0
- package/dist/services/ValidationUtils/transformers/stringDateTransformer.d.ts +3 -0
- package/dist/services/ValidationUtils/transformers/stringDateTransformer.js +16 -0
- package/dist/services/ValidationUtils/transformers/stringNumberTransfromer.d.ts +3 -0
- package/dist/services/ValidationUtils/transformers/stringNumberTransfromer.js +24 -0
- package/dist/services/ValidationUtils/types/PaginatedResponse.d.ts +8 -0
- package/dist/services/ValidationUtils/types/PaginatedResponse.js +1 -0
- package/dist/types/AnyRoute.d.ts +3 -0
- package/dist/types/AnyRoute.js +1 -0
- package/dist/types/InitialBuilder.d.ts +9 -0
- package/dist/types/InitialBuilder.js +1 -0
- package/dist/types/NonEmptyArray.d.ts +1 -0
- package/dist/types/NonEmptyArray.js +1 -0
- package/dist/types/Route.d.ts +22 -0
- package/dist/types/Route.js +1 -0
- package/dist/types/RouteMap.d.ts +3 -0
- package/dist/types/RouteMap.js +1 -0
- package/dist/types/RoutePath.d.ts +1 -0
- package/dist/types/RoutePath.js +1 -0
- package/dist/types/Wrappers.d.ts +7 -0
- package/dist/types/Wrappers.js +1 -0
- package/dist/types/config/AnyConfig.d.ts +4 -0
- package/dist/types/config/AnyConfig.js +1 -0
- package/dist/types/config/AnyRouteConfigMap.d.ts +4 -0
- package/dist/types/config/AnyRouteConfigMap.js +1 -0
- package/dist/types/config/Config.d.ts +19 -0
- package/dist/types/config/Config.js +1 -0
- package/dist/types/config/ContextParams.d.ts +12 -0
- package/dist/types/config/ContextParams.js +1 -0
- package/dist/types/config/ErrorConfig.d.ts +6 -0
- package/dist/types/config/ErrorConfig.js +1 -0
- package/dist/types/config/ErrorConfigMap.d.ts +5 -0
- package/dist/types/config/ErrorConfigMap.js +1 -0
- package/dist/types/config/ErrorResponse.d.ts +8 -0
- package/dist/types/config/ErrorResponse.js +1 -0
- package/dist/types/config/ISpecificationExtension.d.ts +6 -0
- package/dist/types/config/ISpecificationExtension.js +1 -0
- package/dist/types/config/Info.d.ts +7 -0
- package/dist/types/config/Info.js +1 -0
- package/dist/types/config/OmitMappedField.d.ts +3 -0
- package/dist/types/config/OmitMappedField.js +1 -0
- package/dist/types/config/RouteConfig.d.ts +10 -0
- package/dist/types/config/RouteConfig.js +1 -0
- package/dist/types/config/RouteConfigMap.d.ts +7 -0
- package/dist/types/config/RouteConfigMap.js +1 -0
- package/dist/types/config/RouteContextMap.d.ts +6 -0
- package/dist/types/config/RouteContextMap.js +1 -0
- package/dist/types/config/RouteExtraProps.d.ts +2 -0
- package/dist/types/config/RouteExtraProps.js +1 -0
- package/dist/types/config/RouteExtraPropsMap.d.ts +4 -0
- package/dist/types/config/RouteExtraPropsMap.js +1 -0
- package/dist/types/config/Server.d.ts +5 -0
- package/dist/types/config/Server.js +1 -0
- package/dist/types/errors/ApiError.d.ts +5 -0
- package/dist/types/errors/ApiError.js +10 -0
- package/dist/types/errors/BuiltInError.d.ts +4 -0
- package/dist/types/errors/BuiltInError.js +3 -0
- package/dist/types/errors/FieldError.d.ts +33 -0
- package/dist/types/errors/FieldError.js +9 -0
- package/dist/types/errors/ValidationError.d.ts +10 -0
- package/dist/types/errors/ValidationError.js +17 -0
- package/dist/types/errors/responses/NotFoundErrorResponse.d.ts +12 -0
- package/dist/types/errors/responses/NotFoundErrorResponse.js +6 -0
- package/dist/types/errors/responses/UnknownErrorResponse.d.ts +12 -0
- package/dist/types/errors/responses/UnknownErrorResponse.js +6 -0
- package/dist/types/errors/responses/ValidationErrorResponse.d.ts +89 -0
- package/dist/types/errors/responses/ValidationErrorResponse.js +12 -0
- package/dist/vitest.config.d.ts +2 -0
- package/dist/vitest.config.js +25 -0
- package/package.json +53 -0
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import 'zod-openapi/extend';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { ErrorCode } from '../../../enums/ErrorCode.js';
|
|
4
|
+
import { ValidationLocation } from '../../../enums/ValidationLocations.js';
|
|
5
|
+
export declare const validationErrorResponseValidator: z.ZodObject<{
|
|
6
|
+
error: z.ZodObject<{
|
|
7
|
+
code: z.ZodLiteral<ErrorCode.ValidationFailed>;
|
|
8
|
+
fieldErrors: z.ZodArray<z.ZodObject<{
|
|
9
|
+
field: z.ZodString;
|
|
10
|
+
message: z.ZodString;
|
|
11
|
+
} & {
|
|
12
|
+
fieldErrors: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
13
|
+
field: z.ZodString;
|
|
14
|
+
message: z.ZodString;
|
|
15
|
+
}, "strip", z.ZodTypeAny, {
|
|
16
|
+
message: string;
|
|
17
|
+
field: string;
|
|
18
|
+
}, {
|
|
19
|
+
message: string;
|
|
20
|
+
field: string;
|
|
21
|
+
}>, "many">>;
|
|
22
|
+
}, "strip", z.ZodTypeAny, {
|
|
23
|
+
message: string;
|
|
24
|
+
field: string;
|
|
25
|
+
fieldErrors?: {
|
|
26
|
+
message: string;
|
|
27
|
+
field: string;
|
|
28
|
+
}[] | undefined;
|
|
29
|
+
}, {
|
|
30
|
+
message: string;
|
|
31
|
+
field: string;
|
|
32
|
+
fieldErrors?: {
|
|
33
|
+
message: string;
|
|
34
|
+
field: string;
|
|
35
|
+
}[] | undefined;
|
|
36
|
+
}>, "many">;
|
|
37
|
+
location: z.ZodNativeEnum<typeof ValidationLocation>;
|
|
38
|
+
}, "strip", z.ZodTypeAny, {
|
|
39
|
+
code: ErrorCode.ValidationFailed;
|
|
40
|
+
fieldErrors: {
|
|
41
|
+
message: string;
|
|
42
|
+
field: string;
|
|
43
|
+
fieldErrors?: {
|
|
44
|
+
message: string;
|
|
45
|
+
field: string;
|
|
46
|
+
}[] | undefined;
|
|
47
|
+
}[];
|
|
48
|
+
location: ValidationLocation;
|
|
49
|
+
}, {
|
|
50
|
+
code: ErrorCode.ValidationFailed;
|
|
51
|
+
fieldErrors: {
|
|
52
|
+
message: string;
|
|
53
|
+
field: string;
|
|
54
|
+
fieldErrors?: {
|
|
55
|
+
message: string;
|
|
56
|
+
field: string;
|
|
57
|
+
}[] | undefined;
|
|
58
|
+
}[];
|
|
59
|
+
location: ValidationLocation;
|
|
60
|
+
}>;
|
|
61
|
+
}, "strip", z.ZodTypeAny, {
|
|
62
|
+
error: {
|
|
63
|
+
code: ErrorCode.ValidationFailed;
|
|
64
|
+
fieldErrors: {
|
|
65
|
+
message: string;
|
|
66
|
+
field: string;
|
|
67
|
+
fieldErrors?: {
|
|
68
|
+
message: string;
|
|
69
|
+
field: string;
|
|
70
|
+
}[] | undefined;
|
|
71
|
+
}[];
|
|
72
|
+
location: ValidationLocation;
|
|
73
|
+
};
|
|
74
|
+
}, {
|
|
75
|
+
error: {
|
|
76
|
+
code: ErrorCode.ValidationFailed;
|
|
77
|
+
fieldErrors: {
|
|
78
|
+
message: string;
|
|
79
|
+
field: string;
|
|
80
|
+
fieldErrors?: {
|
|
81
|
+
message: string;
|
|
82
|
+
field: string;
|
|
83
|
+
}[] | undefined;
|
|
84
|
+
}[];
|
|
85
|
+
location: ValidationLocation;
|
|
86
|
+
};
|
|
87
|
+
}>;
|
|
88
|
+
export type ValidationErrorResponseValidator = typeof validationErrorResponseValidator;
|
|
89
|
+
export type ValidationErrorResponse = z.TypeOf<ValidationErrorResponseValidator>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import 'zod-openapi/extend';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { ErrorCode } from '../../../enums/ErrorCode.js';
|
|
4
|
+
import { fieldErrorValidator } from '../FieldError.js';
|
|
5
|
+
import { ValidationLocation } from '../../../enums/ValidationLocations.js';
|
|
6
|
+
export const validationErrorResponseValidator = z.object({
|
|
7
|
+
error: z.object({
|
|
8
|
+
code: z.literal(ErrorCode.ValidationFailed).openapi({ description: 'Code to handle on the frontend' }),
|
|
9
|
+
fieldErrors: fieldErrorValidator.array(),
|
|
10
|
+
location: z.nativeEnum(ValidationLocation),
|
|
11
|
+
}).openapi({ description: 'Error response' }),
|
|
12
|
+
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { defineConfig } from 'vitest/config';
|
|
2
|
+
export default defineConfig({
|
|
3
|
+
test: {
|
|
4
|
+
reporters: ['verbose', 'html'],
|
|
5
|
+
coverage: {
|
|
6
|
+
exclude: [
|
|
7
|
+
'html/**',
|
|
8
|
+
'dist/**',
|
|
9
|
+
'vitest.config.ts',
|
|
10
|
+
'vitest',
|
|
11
|
+
'index.ts',
|
|
12
|
+
'eslint.config.mjs',
|
|
13
|
+
'overrides.d.ts',
|
|
14
|
+
'reset.d.ts',
|
|
15
|
+
],
|
|
16
|
+
reportsDirectory: 'html/coverage',
|
|
17
|
+
reporter: [
|
|
18
|
+
['html-spa', { subdir: 'spa' }],
|
|
19
|
+
['html', { subdir: 'html' }],
|
|
20
|
+
['text'],
|
|
21
|
+
],
|
|
22
|
+
provider: 'v8',
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "snap-on-openapi",
|
|
3
|
+
"author": "Alex Sarychev",
|
|
4
|
+
"version": "1.0.1",
|
|
5
|
+
"description": "Swiftly build type-checked OpenAPI applications with Zod and TypeScript",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"license": "ISC",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist"
|
|
10
|
+
],
|
|
11
|
+
"exports": {
|
|
12
|
+
".": [
|
|
13
|
+
"./dist/index.js",
|
|
14
|
+
"./dist/index.d.ts"
|
|
15
|
+
]
|
|
16
|
+
},
|
|
17
|
+
"scripts": {
|
|
18
|
+
"build": "rm -rf dist && tsc && tsc-alias && cp -R ./assets ./dist && cp ./README.md ./dist",
|
|
19
|
+
"check": "npm run test:typecheck && npm run lint && npm run test",
|
|
20
|
+
"test": "vitest --run",
|
|
21
|
+
"test:gha": "npx vitest --run --coverage --reporter=verbose",
|
|
22
|
+
"test:typecheck": "tsc -p tsconfig.test.json",
|
|
23
|
+
"test:coverage": "npm run test:coverage:html ; npm run test:swap-html-coverage ; vite preview --outDir html --open",
|
|
24
|
+
"test:coverage:html": "npm run test -- --coverage",
|
|
25
|
+
"test:swap-html-coverage": "rm -R ./html/coverage/html && mv ./html/coverage/spa ./html/coverage/html",
|
|
26
|
+
"lint": "eslint . --fix"
|
|
27
|
+
},
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"@hey-api/client-axios": "^0.9.1",
|
|
30
|
+
"@hey-api/openapi-ts": "^0.76.0",
|
|
31
|
+
"yaml": "^2.8.0",
|
|
32
|
+
"zod": "^3.25.67",
|
|
33
|
+
"zod-openapi": "^4.2.4"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@total-typescript/ts-reset": "^0.6.1",
|
|
37
|
+
"@types/express": "^5.0.3",
|
|
38
|
+
"@types/node": "^24.0.3",
|
|
39
|
+
"@types/supertest": "^6.0.3",
|
|
40
|
+
"@vitest/coverage-istanbul": "^3.2.4",
|
|
41
|
+
"@vitest/coverage-v8": "^3.2.4",
|
|
42
|
+
"@vitest/ui": "^3.2.4",
|
|
43
|
+
"eslint": "^9.29.0",
|
|
44
|
+
"eslint-plugin-import": "^2.32.0",
|
|
45
|
+
"express": "^5.1.0",
|
|
46
|
+
"jest": "^30.0.2",
|
|
47
|
+
"supertest": "^7.1.1",
|
|
48
|
+
"tsc-alias": "^1.8.16",
|
|
49
|
+
"typescript-eslint": "^8.34.1",
|
|
50
|
+
"vite": "^7.0.0",
|
|
51
|
+
"vitest": "^3.2.4"
|
|
52
|
+
}
|
|
53
|
+
}
|