@miiajs/swagger 0.1.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/LICENSE +21 -0
- package/README.md +17 -0
- package/dist/builder/index.d.ts +5 -0
- package/dist/builder/index.d.ts.map +1 -0
- package/dist/builder/index.js +4 -0
- package/dist/builder/index.js.map +1 -0
- package/dist/builder/path-converter.d.ts +3 -0
- package/dist/builder/path-converter.d.ts.map +1 -0
- package/dist/builder/path-converter.js +9 -0
- package/dist/builder/path-converter.js.map +1 -0
- package/dist/builder/schema-converter.d.ts +3 -0
- package/dist/builder/schema-converter.d.ts.map +1 -0
- package/dist/builder/schema-converter.js +234 -0
- package/dist/builder/schema-converter.js.map +1 -0
- package/dist/builder/spec-builder.d.ts +18 -0
- package/dist/builder/spec-builder.d.ts.map +1 -0
- package/dist/builder/spec-builder.js +245 -0
- package/dist/builder/spec-builder.js.map +1 -0
- package/dist/constants.d.ts +10 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +10 -0
- package/dist/constants.js.map +1 -0
- package/dist/decorators/api-body.d.ts +39 -0
- package/dist/decorators/api-body.d.ts.map +1 -0
- package/dist/decorators/api-body.js +44 -0
- package/dist/decorators/api-body.js.map +1 -0
- package/dist/decorators/api-exclude.d.ts +2 -0
- package/dist/decorators/api-exclude.d.ts.map +1 -0
- package/dist/decorators/api-exclude.js +9 -0
- package/dist/decorators/api-exclude.js.map +1 -0
- package/dist/decorators/api-header.d.ts +3 -0
- package/dist/decorators/api-header.d.ts.map +1 -0
- package/dist/decorators/api-header.js +12 -0
- package/dist/decorators/api-header.js.map +1 -0
- package/dist/decorators/api-operation.d.ts +3 -0
- package/dist/decorators/api-operation.d.ts.map +1 -0
- package/dist/decorators/api-operation.js +6 -0
- package/dist/decorators/api-operation.js.map +1 -0
- package/dist/decorators/api-param.d.ts +3 -0
- package/dist/decorators/api-param.d.ts.map +1 -0
- package/dist/decorators/api-param.js +9 -0
- package/dist/decorators/api-param.js.map +1 -0
- package/dist/decorators/api-query.d.ts +3 -0
- package/dist/decorators/api-query.d.ts.map +1 -0
- package/dist/decorators/api-query.js +9 -0
- package/dist/decorators/api-query.js.map +1 -0
- package/dist/decorators/api-response.d.ts +3 -0
- package/dist/decorators/api-response.d.ts.map +1 -0
- package/dist/decorators/api-response.js +9 -0
- package/dist/decorators/api-response.js.map +1 -0
- package/dist/decorators/api-security.d.ts +2 -0
- package/dist/decorators/api-security.d.ts.map +1 -0
- package/dist/decorators/api-security.js +11 -0
- package/dist/decorators/api-security.js.map +1 -0
- package/dist/decorators/api-tag.d.ts +2 -0
- package/dist/decorators/api-tag.d.ts.map +1 -0
- package/dist/decorators/api-tag.js +6 -0
- package/dist/decorators/api-tag.js.map +1 -0
- package/dist/decorators/index.d.ts +10 -0
- package/dist/decorators/index.d.ts.map +1 -0
- package/dist/decorators/index.js +10 -0
- package/dist/decorators/index.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -0
- package/dist/swagger-ui.d.ts +2 -0
- package/dist/swagger-ui.d.ts.map +1 -0
- package/dist/swagger-ui.js +16 -0
- package/dist/swagger-ui.js.map +1 -0
- package/dist/swagger.module.d.ts +7 -0
- package/dist/swagger.module.d.ts.map +1 -0
- package/dist/swagger.module.js +19 -0
- package/dist/swagger.module.js.map +1 -0
- package/dist/swagger.service.d.ts +8 -0
- package/dist/swagger.service.d.ts.map +1 -0
- package/dist/swagger.service.js +96 -0
- package/dist/swagger.service.js.map +1 -0
- package/dist/types.d.ts +95 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +61 -0
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export const API_TAG = Symbol('apiTag');
|
|
2
|
+
export const API_OPERATIONS = Symbol('apiOperations');
|
|
3
|
+
export const API_RESPONSES = Symbol('apiResponses');
|
|
4
|
+
export const API_PARAMS = Symbol('apiParams');
|
|
5
|
+
export const API_QUERIES = Symbol('apiQueries');
|
|
6
|
+
export const API_SECURITY = Symbol('apiSecurity');
|
|
7
|
+
export const API_HEADERS = Symbol('apiHeaders');
|
|
8
|
+
export const API_EXCLUDE = Symbol('apiExclude');
|
|
9
|
+
export const API_BODY_OPTIONS = Symbol('apiBodyOptions');
|
|
10
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,OAAO,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAA;AACvC,MAAM,CAAC,MAAM,cAAc,GAAG,MAAM,CAAC,eAAe,CAAC,CAAA;AACrD,MAAM,CAAC,MAAM,aAAa,GAAG,MAAM,CAAC,cAAc,CAAC,CAAA;AACnD,MAAM,CAAC,MAAM,UAAU,GAAG,MAAM,CAAC,WAAW,CAAC,CAAA;AAC7C,MAAM,CAAC,MAAM,WAAW,GAAG,MAAM,CAAC,YAAY,CAAC,CAAA;AAC/C,MAAM,CAAC,MAAM,YAAY,GAAG,MAAM,CAAC,aAAa,CAAC,CAAA;AACjD,MAAM,CAAC,MAAM,WAAW,GAAG,MAAM,CAAC,YAAY,CAAC,CAAA;AAC/C,MAAM,CAAC,MAAM,WAAW,GAAG,MAAM,CAAC,YAAY,CAAC,CAAA;AAC/C,MAAM,CAAC,MAAM,gBAAgB,GAAG,MAAM,CAAC,gBAAgB,CAAC,CAAA"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { type ZodLike } from '@miiajs/core';
|
|
2
|
+
import type { ApiBodyOptions, JsonSchema } from '../types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Document a route's request body for OpenAPI **without** running runtime
|
|
5
|
+
* validation. Writes to the same `BODY_SCHEMAS` metadata key that `@ValidateBody`
|
|
6
|
+
* uses, so `SpecBuilder` picks it up automatically.
|
|
7
|
+
*
|
|
8
|
+
* Use when the request body is validated elsewhere (e.g. inside an auth
|
|
9
|
+
* provider, a custom middleware, or consumed raw as a stream) but you still
|
|
10
|
+
* want Swagger to show the expected shape. If you already apply `@ValidateBody`,
|
|
11
|
+
* you don't need `@ApiBody` - the schema is discovered from the validator.
|
|
12
|
+
*
|
|
13
|
+
* ## Content type
|
|
14
|
+
*
|
|
15
|
+
* Pass `{ contentType }` as the second argument to describe a non-JSON body -
|
|
16
|
+
* for example, `multipart/form-data` for file uploads. The schema can be any
|
|
17
|
+
* `ZodLike`, or a raw OpenAPI JSON Schema object when Zod cannot express the
|
|
18
|
+
* shape (e.g. binary file fields).
|
|
19
|
+
*
|
|
20
|
+
* **Raw JSON Schema requirement:** raw (non-Zod) schemas passed here must
|
|
21
|
+
* include a top-level `type` field. Unions without `type` (e.g. `{ anyOf }`)
|
|
22
|
+
* currently fall back to `{ type: 'object' }` - use a Zod schema for those.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```ts
|
|
26
|
+
* @Post(':id/avatar')
|
|
27
|
+
* @ApiBody(
|
|
28
|
+
* {
|
|
29
|
+
* type: 'object',
|
|
30
|
+
* properties: { file: { type: 'string', format: 'binary' } },
|
|
31
|
+
* required: ['file'],
|
|
32
|
+
* },
|
|
33
|
+
* { contentType: 'multipart/form-data' },
|
|
34
|
+
* )
|
|
35
|
+
* uploadAvatar(ctx: RequestContext) { ... }
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export declare const ApiBody: (schema: ZodLike<any> | JsonSchema, options?: ApiBodyOptions | undefined) => (target: Function, context: ClassMethodDecoratorContext) => void;
|
|
39
|
+
//# sourceMappingURL=api-body.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-body.d.ts","sourceRoot":"","sources":["../../src/decorators/api-body.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqD,KAAK,OAAO,EAAE,MAAM,cAAc,CAAA;AAE9F,OAAO,KAAK,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAE7D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,eAAO,MAAM,OAAO,+IAOnB,CAAA"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { BODY_SCHEMAS, createMethodDecorator, setInMapMeta } from '@miiajs/core';
|
|
2
|
+
import { API_BODY_OPTIONS } from '../constants.js';
|
|
3
|
+
/**
|
|
4
|
+
* Document a route's request body for OpenAPI **without** running runtime
|
|
5
|
+
* validation. Writes to the same `BODY_SCHEMAS` metadata key that `@ValidateBody`
|
|
6
|
+
* uses, so `SpecBuilder` picks it up automatically.
|
|
7
|
+
*
|
|
8
|
+
* Use when the request body is validated elsewhere (e.g. inside an auth
|
|
9
|
+
* provider, a custom middleware, or consumed raw as a stream) but you still
|
|
10
|
+
* want Swagger to show the expected shape. If you already apply `@ValidateBody`,
|
|
11
|
+
* you don't need `@ApiBody` - the schema is discovered from the validator.
|
|
12
|
+
*
|
|
13
|
+
* ## Content type
|
|
14
|
+
*
|
|
15
|
+
* Pass `{ contentType }` as the second argument to describe a non-JSON body -
|
|
16
|
+
* for example, `multipart/form-data` for file uploads. The schema can be any
|
|
17
|
+
* `ZodLike`, or a raw OpenAPI JSON Schema object when Zod cannot express the
|
|
18
|
+
* shape (e.g. binary file fields).
|
|
19
|
+
*
|
|
20
|
+
* **Raw JSON Schema requirement:** raw (non-Zod) schemas passed here must
|
|
21
|
+
* include a top-level `type` field. Unions without `type` (e.g. `{ anyOf }`)
|
|
22
|
+
* currently fall back to `{ type: 'object' }` - use a Zod schema for those.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```ts
|
|
26
|
+
* @Post(':id/avatar')
|
|
27
|
+
* @ApiBody(
|
|
28
|
+
* {
|
|
29
|
+
* type: 'object',
|
|
30
|
+
* properties: { file: { type: 'string', format: 'binary' } },
|
|
31
|
+
* required: ['file'],
|
|
32
|
+
* },
|
|
33
|
+
* { contentType: 'multipart/form-data' },
|
|
34
|
+
* )
|
|
35
|
+
* uploadAvatar(ctx: RequestContext) { ... }
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export const ApiBody = createMethodDecorator((_target, context, schema, options) => {
|
|
39
|
+
setInMapMeta(context.metadata, BODY_SCHEMAS, String(context.name), schema);
|
|
40
|
+
if (options) {
|
|
41
|
+
setInMapMeta(context.metadata, API_BODY_OPTIONS, String(context.name), options);
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
//# sourceMappingURL=api-body.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-body.js","sourceRoot":"","sources":["../../src/decorators/api-body.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,qBAAqB,EAAE,YAAY,EAAgB,MAAM,cAAc,CAAA;AAC9F,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAGlD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,qBAAqB,CAC1C,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,EAAE;IACpC,YAAY,CAAC,OAAO,CAAC,QAAS,EAAE,YAAY,EAAE,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC,CAAA;IAC3E,IAAI,OAAO,EAAE,CAAC;QACZ,YAAY,CAAC,OAAO,CAAC,QAAS,EAAE,gBAAgB,EAAE,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC,CAAA;IAClF,CAAC;AACH,CAAC,CACF,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-exclude.d.ts","sourceRoot":"","sources":["../../src/decorators/api-exclude.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,UAAU,0FAKrB,CAAA"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { createDecorator } from '@miiajs/core';
|
|
2
|
+
import { API_EXCLUDE } from '../constants.js';
|
|
3
|
+
export const ApiExclude = createDecorator((context) => {
|
|
4
|
+
const meta = context.metadata;
|
|
5
|
+
const set = meta[API_EXCLUDE] ?? new Set();
|
|
6
|
+
set.add(context.kind === 'class' ? '*' : String(context.name));
|
|
7
|
+
meta[API_EXCLUDE] = set;
|
|
8
|
+
});
|
|
9
|
+
//# sourceMappingURL=api-exclude.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-exclude.js","sourceRoot":"","sources":["../../src/decorators/api-exclude.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAE7C,MAAM,CAAC,MAAM,UAAU,GAAG,eAAe,CAAC,CAAC,OAAO,EAAE,EAAE;IACpD,MAAM,IAAI,GAAG,OAAO,CAAC,QAA+B,CAAA;IACpD,MAAM,GAAG,GAAgB,IAAI,CAAC,WAAW,CAAC,IAAI,IAAI,GAAG,EAAE,CAAA;IACvD,GAAG,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,KAAK,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAA;IAC9D,IAAI,CAAC,WAAW,CAAC,GAAG,GAAG,CAAA;AACzB,CAAC,CAAC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-header.d.ts","sourceRoot":"","sources":["../../src/decorators/api-header.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAiB,gBAAgB,EAAE,MAAM,aAAa,CAAA;AAElE,eAAO,MAAM,SAAS,8IAQpB,CAAA"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { createDecorator } from '@miiajs/core';
|
|
2
|
+
import { API_HEADERS } from '../constants.js';
|
|
3
|
+
export const ApiHeader = createDecorator((context, name, options) => {
|
|
4
|
+
const entry = { name, ...options };
|
|
5
|
+
const meta = context.metadata;
|
|
6
|
+
const map = meta[API_HEADERS] ?? new Map();
|
|
7
|
+
const key = context.kind === 'class' ? '*' : String(context.name);
|
|
8
|
+
const existing = map.get(key) ?? [];
|
|
9
|
+
map.set(key, [...existing, entry]);
|
|
10
|
+
meta[API_HEADERS] = map;
|
|
11
|
+
});
|
|
12
|
+
//# sourceMappingURL=api-header.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-header.js","sourceRoot":"","sources":["../../src/decorators/api-header.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAG7C,MAAM,CAAC,MAAM,SAAS,GAAG,eAAe,CAA6C,CAAC,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE;IAC9G,MAAM,KAAK,GAAkB,EAAE,IAAI,EAAE,GAAG,OAAO,EAAE,CAAA;IACjD,MAAM,IAAI,GAAG,OAAO,CAAC,QAA+B,CAAA;IACpD,MAAM,GAAG,GAAiC,IAAI,CAAC,WAAW,CAAC,IAAI,IAAI,GAAG,EAAE,CAAA;IACxE,MAAM,GAAG,GAAG,OAAO,CAAC,IAAI,KAAK,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;IACjE,MAAM,QAAQ,GAAG,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,EAAE,CAAA;IACnC,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,GAAG,QAAQ,EAAE,KAAK,CAAC,CAAC,CAAA;IAClC,IAAI,CAAC,WAAW,CAAC,GAAG,GAAG,CAAA;AACzB,CAAC,CAAC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-operation.d.ts","sourceRoot":"","sources":["../../src/decorators/api-operation.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAA;AAEtD,eAAO,MAAM,YAAY,oGAEvB,CAAA"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { createMethodDecorator, setInMapMeta } from '@miiajs/core';
|
|
2
|
+
import { API_OPERATIONS } from '../constants.js';
|
|
3
|
+
export const ApiOperation = createMethodDecorator((_target, context, options) => {
|
|
4
|
+
setInMapMeta(context.metadata, API_OPERATIONS, String(context.name), options);
|
|
5
|
+
});
|
|
6
|
+
//# sourceMappingURL=api-operation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-operation.js","sourceRoot":"","sources":["../../src/decorators/api-operation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAClE,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAGhD,MAAM,CAAC,MAAM,YAAY,GAAG,qBAAqB,CAAiC,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,EAAE;IAC9G,YAAY,CAAC,OAAO,CAAC,QAAS,EAAE,cAAc,EAAE,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC,CAAA;AAChF,CAAC,CAAC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-param.d.ts","sourceRoot":"","sources":["../../src/decorators/api-param.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAgB,eAAe,EAAE,MAAM,aAAa,CAAA;AAEhE,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,eAAe,IACtD,SAAS,QAAQ,EAAE,SAAS,2BAA2B,KAAG,IAAI,CAIvE"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { addToMapMeta } from '@miiajs/core';
|
|
2
|
+
import { API_PARAMS } from '../constants.js';
|
|
3
|
+
export function ApiParam(name, options) {
|
|
4
|
+
return (_target, context) => {
|
|
5
|
+
const entry = { name, ...options };
|
|
6
|
+
addToMapMeta(context.metadata, API_PARAMS, String(context.name), [entry]);
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=api-param.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-param.js","sourceRoot":"","sources":["../../src/decorators/api-param.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAC3C,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAG5C,MAAM,UAAU,QAAQ,CAAC,IAAY,EAAE,OAAyB;IAC9D,OAAO,CAAC,OAAiB,EAAE,OAAoC,EAAQ,EAAE;QACvE,MAAM,KAAK,GAAiB,EAAE,IAAI,EAAE,GAAG,OAAO,EAAE,CAAA;QAChD,YAAY,CAAC,OAAO,CAAC,QAAS,EAAE,UAAU,EAAE,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAA;IAC5E,CAAC,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-query.d.ts","sourceRoot":"","sources":["../../src/decorators/api-query.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAgB,eAAe,EAAE,MAAM,aAAa,CAAA;AAEhE,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,eAAe,IACtD,SAAS,QAAQ,EAAE,SAAS,2BAA2B,KAAG,IAAI,CAIvE"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { addToMapMeta } from '@miiajs/core';
|
|
2
|
+
import { API_QUERIES } from '../constants.js';
|
|
3
|
+
export function ApiQuery(name, options) {
|
|
4
|
+
return (_target, context) => {
|
|
5
|
+
const entry = { name, ...options };
|
|
6
|
+
addToMapMeta(context.metadata, API_QUERIES, String(context.name), [entry]);
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=api-query.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-query.js","sourceRoot":"","sources":["../../src/decorators/api-query.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAG7C,MAAM,UAAU,QAAQ,CAAC,IAAY,EAAE,OAAyB;IAC9D,OAAO,CAAC,OAAiB,EAAE,OAAoC,EAAQ,EAAE;QACvE,MAAM,KAAK,GAAiB,EAAE,IAAI,EAAE,GAAG,OAAO,EAAE,CAAA;QAChD,YAAY,CAAC,OAAO,CAAC,QAAS,EAAE,WAAW,EAAE,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAA;IAC7E,CAAC,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-response.d.ts","sourceRoot":"","sources":["../../src/decorators/api-response.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAmB,kBAAkB,EAAE,MAAM,aAAa,CAAA;AAEtE,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,kBAAkB,IAC9D,SAAS,QAAQ,EAAE,SAAS,2BAA2B,KAAG,IAAI,CAIvE"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { addToMapMeta } from '@miiajs/core';
|
|
2
|
+
import { API_RESPONSES } from '../constants.js';
|
|
3
|
+
export function ApiResponse(status, options) {
|
|
4
|
+
return (_target, context) => {
|
|
5
|
+
const entry = { status, ...options };
|
|
6
|
+
addToMapMeta(context.metadata, API_RESPONSES, String(context.name), [entry]);
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=api-response.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-response.js","sourceRoot":"","sources":["../../src/decorators/api-response.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAC3C,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAG/C,MAAM,UAAU,WAAW,CAAC,MAAc,EAAE,OAA4B;IACtE,OAAO,CAAC,OAAiB,EAAE,OAAoC,EAAQ,EAAE;QACvE,MAAM,KAAK,GAAoB,EAAE,MAAM,EAAE,GAAG,OAAO,EAAE,CAAA;QACrD,YAAY,CAAC,OAAO,CAAC,QAAS,EAAE,aAAa,EAAE,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAA;IAC/E,CAAC,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-security.d.ts","sourceRoot":"","sources":["../../src/decorators/api-security.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,WAAW,qIAOtB,CAAA"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { createDecorator } from '@miiajs/core';
|
|
2
|
+
import { API_SECURITY } from '../constants.js';
|
|
3
|
+
export const ApiSecurity = createDecorator((context, name, scopes = []) => {
|
|
4
|
+
const meta = context.metadata;
|
|
5
|
+
const map = meta[API_SECURITY] ?? new Map();
|
|
6
|
+
const key = context.kind === 'class' ? '*' : String(context.name);
|
|
7
|
+
const existing = map.get(key) ?? [];
|
|
8
|
+
map.set(key, [...existing, { name, scopes }]);
|
|
9
|
+
meta[API_SECURITY] = map;
|
|
10
|
+
});
|
|
11
|
+
//# sourceMappingURL=api-security.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-security.js","sourceRoot":"","sources":["../../src/decorators/api-security.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAC9C,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAG9C,MAAM,CAAC,MAAM,WAAW,GAAG,eAAe,CAAoC,CAAC,OAAO,EAAE,IAAI,EAAE,MAAM,GAAG,EAAE,EAAE,EAAE;IAC3G,MAAM,IAAI,GAAG,OAAO,CAAC,QAA+B,CAAA;IACpD,MAAM,GAAG,GAAmC,IAAI,CAAC,YAAY,CAAC,IAAI,IAAI,GAAG,EAAE,CAAA;IAC3E,MAAM,GAAG,GAAG,OAAO,CAAC,IAAI,KAAK,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;IACjE,MAAM,QAAQ,GAAG,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,EAAE,CAAA;IACnC,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,GAAG,QAAQ,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC,CAAA;IAC7C,IAAI,CAAC,YAAY,CAAC,GAAG,GAAG,CAAA;AAC1B,CAAC,CAAC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-tag.d.ts","sourceRoot":"","sources":["../../src/decorators/api-tag.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,MAAM,0HAEjB,CAAA"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { createClassDecorator, setMeta } from '@miiajs/core';
|
|
2
|
+
import { API_TAG } from '../constants.js';
|
|
3
|
+
export const ApiTag = createClassDecorator((_target, context, ...names) => {
|
|
4
|
+
setMeta(context.metadata, API_TAG, names);
|
|
5
|
+
});
|
|
6
|
+
//# sourceMappingURL=api-tag.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-tag.js","sourceRoot":"","sources":["../../src/decorators/api-tag.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAC5D,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAA;AAEzC,MAAM,CAAC,MAAM,MAAM,GAAG,oBAAoB,CAAuB,CAAC,OAAO,EAAE,OAAO,EAAE,GAAG,KAAK,EAAE,EAAE;IAC9F,OAAO,CAAC,OAAO,CAAC,QAAS,EAAE,OAAO,EAAE,KAAK,CAAC,CAAA;AAC5C,CAAC,CAAC,CAAA"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { ApiTag } from './api-tag.js';
|
|
2
|
+
export { ApiOperation } from './api-operation.js';
|
|
3
|
+
export { ApiResponse } from './api-response.js';
|
|
4
|
+
export { ApiBody } from './api-body.js';
|
|
5
|
+
export { ApiParam } from './api-param.js';
|
|
6
|
+
export { ApiQuery } from './api-query.js';
|
|
7
|
+
export { ApiSecurity } from './api-security.js';
|
|
8
|
+
export { ApiHeader } from './api-header.js';
|
|
9
|
+
export { ApiExclude } from './api-exclude.js';
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/decorators/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AACrC,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AACjD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAC/C,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AACvC,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AACzC,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAC/C,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAC3C,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { ApiTag } from './api-tag.js';
|
|
2
|
+
export { ApiOperation } from './api-operation.js';
|
|
3
|
+
export { ApiResponse } from './api-response.js';
|
|
4
|
+
export { ApiBody } from './api-body.js';
|
|
5
|
+
export { ApiParam } from './api-param.js';
|
|
6
|
+
export { ApiQuery } from './api-query.js';
|
|
7
|
+
export { ApiSecurity } from './api-security.js';
|
|
8
|
+
export { ApiHeader } from './api-header.js';
|
|
9
|
+
export { ApiExclude } from './api-exclude.js';
|
|
10
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/decorators/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AACrC,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AACjD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAC/C,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AACvC,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AACzC,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAC/C,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAC3C,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { SwaggerModule, SWAGGER_OPTIONS } from './swagger.module.js';
|
|
2
|
+
export { SwaggerService } from './swagger.service.js';
|
|
3
|
+
export { ApiTag, ApiOperation, ApiResponse, ApiBody, ApiParam, ApiQuery, ApiSecurity, ApiHeader, ApiExclude, } from './decorators/index.js';
|
|
4
|
+
export { SpecBuilder, convertSchema, toOpenApiPath, extractPathParams } from './builder/index.js';
|
|
5
|
+
export type { DiscoveredController } from './builder/index.js';
|
|
6
|
+
export type { SwaggerSetupOptions, ApiOperationOptions, ApiResponseOptions, ApiParamOptions, ApiQueryOptions, ApiHeaderOptions, ApiBodyOptions, ApiResponseMeta, ApiParamMeta, ApiQueryMeta, ApiSecurityMeta, ApiHeaderMeta, JsonSchema, } from './types.js';
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AACpE,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAGrD,OAAO,EACL,MAAM,EACN,YAAY,EACZ,WAAW,EACX,OAAO,EACP,QAAQ,EACR,QAAQ,EACR,WAAW,EACX,SAAS,EACT,UAAU,GACX,MAAM,uBAAuB,CAAA;AAG9B,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAA;AACjG,YAAY,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAA;AAG9D,YAAY,EACV,mBAAmB,EACnB,mBAAmB,EACnB,kBAAkB,EAClB,eAAe,EACf,eAAe,EACf,gBAAgB,EAChB,cAAc,EACd,eAAe,EACf,YAAY,EACZ,YAAY,EACZ,eAAe,EACf,aAAa,EACb,UAAU,GACX,MAAM,YAAY,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// @miiajs/swagger - public API
|
|
2
|
+
// Module
|
|
3
|
+
export { SwaggerModule, SWAGGER_OPTIONS } from './swagger.module.js';
|
|
4
|
+
export { SwaggerService } from './swagger.service.js';
|
|
5
|
+
// Decorators
|
|
6
|
+
export { ApiTag, ApiOperation, ApiResponse, ApiBody, ApiParam, ApiQuery, ApiSecurity, ApiHeader, ApiExclude, } from './decorators/index.js';
|
|
7
|
+
// Builder (for advanced usage)
|
|
8
|
+
export { SpecBuilder, convertSchema, toOpenApiPath, extractPathParams } from './builder/index.js';
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,+BAA+B;AAE/B,SAAS;AACT,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AACpE,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAErD,aAAa;AACb,OAAO,EACL,MAAM,EACN,YAAY,EACZ,WAAW,EACX,OAAO,EACP,QAAQ,EACR,QAAQ,EACR,WAAW,EACX,SAAS,EACT,UAAU,GACX,MAAM,uBAAuB,CAAA;AAE9B,+BAA+B;AAC/B,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"swagger-ui.d.ts","sourceRoot":"","sources":["../src/swagger-ui.ts"],"names":[],"mappings":"AAAA,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,MAAM,EAAE,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,MAAM,CAerG"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export function buildSwaggerInitializer(specUrl, swaggerOptions) {
|
|
2
|
+
const config = JSON.stringify({
|
|
3
|
+
url: specUrl,
|
|
4
|
+
dom_id: '#swagger-ui',
|
|
5
|
+
deepLinking: true,
|
|
6
|
+
...swaggerOptions,
|
|
7
|
+
});
|
|
8
|
+
return `window.onload = function() {
|
|
9
|
+
var config = ${config};
|
|
10
|
+
config.presets = [SwaggerUIBundle.presets.apis, SwaggerUIStandalonePreset];
|
|
11
|
+
config.plugins = [SwaggerUIBundle.plugins.DownloadUrl];
|
|
12
|
+
config.layout = "StandaloneLayout";
|
|
13
|
+
window.ui = SwaggerUIBundle(config);
|
|
14
|
+
};`;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=swagger-ui.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"swagger-ui.js","sourceRoot":"","sources":["../src/swagger-ui.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,uBAAuB,CAAC,OAAe,EAAE,cAAoC;IAC3F,MAAM,MAAM,GAAG,IAAI,CAAC,SAAS,CAAC;QAC5B,GAAG,EAAE,OAAO;QACZ,MAAM,EAAE,aAAa;QACrB,WAAW,EAAE,IAAI;QACjB,GAAG,cAAc;KAClB,CAAC,CAAA;IAEF,OAAO;iBACQ,MAAM;;;;;GAKpB,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ConfiguredModule, OptionsOrFactory } from '@miiajs/core';
|
|
2
|
+
import type { SwaggerSetupOptions } from './types.js';
|
|
3
|
+
export declare const SWAGGER_OPTIONS = "SWAGGER_OPTIONS";
|
|
4
|
+
export declare class SwaggerModule {
|
|
5
|
+
static configure(optionsOrFactory: OptionsOrFactory<SwaggerSetupOptions>): ConfiguredModule;
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=swagger.module.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"swagger.module.d.ts","sourceRoot":"","sources":["../src/swagger.module.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAA;AAGtE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAA;AAGrD,eAAO,MAAM,eAAe,oBAAoB,CAAA;AAEhD,qBAAa,aAAa;IACxB,MAAM,CAAC,SAAS,CAAC,gBAAgB,EAAE,gBAAgB,CAAC,mBAAmB,CAAC,GAAG,gBAAgB;CAY5F"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { resolveOptions } from '@miiajs/core';
|
|
2
|
+
import { SwaggerService } from './swagger.service.js';
|
|
3
|
+
// String token - miia's DI container does not support Symbol tokens.
|
|
4
|
+
export const SWAGGER_OPTIONS = 'SWAGGER_OPTIONS';
|
|
5
|
+
export class SwaggerModule {
|
|
6
|
+
static configure(optionsOrFactory) {
|
|
7
|
+
return {
|
|
8
|
+
module: SwaggerModule,
|
|
9
|
+
providers: [
|
|
10
|
+
{
|
|
11
|
+
token: SWAGGER_OPTIONS,
|
|
12
|
+
factory: (resolve) => resolveOptions(optionsOrFactory, { resolve }),
|
|
13
|
+
},
|
|
14
|
+
SwaggerService,
|
|
15
|
+
],
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=swagger.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"swagger.module.js","sourceRoot":"","sources":["../src/swagger.module.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAGrD,qEAAqE;AACrE,MAAM,CAAC,MAAM,eAAe,GAAG,iBAAiB,CAAA;AAEhD,MAAM,OAAO,aAAa;IACxB,MAAM,CAAC,SAAS,CAAC,gBAAuD;QACtE,OAAO;YACL,MAAM,EAAE,aAAa;YACrB,SAAS,EAAE;gBACT;oBACE,KAAK,EAAE,eAAe;oBACtB,OAAO,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,cAAc,CAAC,gBAAgB,EAAE,EAAE,OAAO,EAAE,CAAC;iBACpE;gBACD,cAAc;aACf;SACF,CAAA;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"swagger.service.d.ts","sourceRoot":"","sources":["../src/swagger.service.ts"],"names":[],"mappings":"AAWA,qBACa,cAAc;IACzB,OAAO,CAAC,SAAS,CAA2B;IAC5C,OAAO,CAAC,MAAM,CAAiB;IAC/B,OAAO,CAAC,OAAO,CAA+C;IAExD,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAqC9B,OAAO,CAAC,kBAAkB;CAQ3B"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
|
|
2
|
+
function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
|
|
3
|
+
var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
|
|
4
|
+
var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
|
|
5
|
+
var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
|
|
6
|
+
var _, done = false;
|
|
7
|
+
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
8
|
+
var context = {};
|
|
9
|
+
for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
|
|
10
|
+
for (var p in contextIn.access) context.access[p] = contextIn.access[p];
|
|
11
|
+
context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
|
|
12
|
+
var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
|
|
13
|
+
if (kind === "accessor") {
|
|
14
|
+
if (result === void 0) continue;
|
|
15
|
+
if (result === null || typeof result !== "object") throw new TypeError("Object expected");
|
|
16
|
+
if (_ = accept(result.get)) descriptor.get = _;
|
|
17
|
+
if (_ = accept(result.set)) descriptor.set = _;
|
|
18
|
+
if (_ = accept(result.init)) initializers.unshift(_);
|
|
19
|
+
}
|
|
20
|
+
else if (_ = accept(result)) {
|
|
21
|
+
if (kind === "field") initializers.unshift(_);
|
|
22
|
+
else descriptor[key] = _;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
if (target) Object.defineProperty(target, contextIn.name, descriptor);
|
|
26
|
+
done = true;
|
|
27
|
+
};
|
|
28
|
+
var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
|
|
29
|
+
var useValue = arguments.length > 2;
|
|
30
|
+
for (var i = 0; i < initializers.length; i++) {
|
|
31
|
+
value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
|
|
32
|
+
}
|
|
33
|
+
return useValue ? value : void 0;
|
|
34
|
+
};
|
|
35
|
+
import { dirname } from 'node:path';
|
|
36
|
+
import { fileURLToPath } from 'node:url';
|
|
37
|
+
import { DiscoveryService, Injectable, RESOLVED_PREFIX, Router, getMeta, inject } from '@miiajs/core';
|
|
38
|
+
import { createStaticHandler } from '@miiajs/serve-static';
|
|
39
|
+
import { SpecBuilder } from './builder/index.js';
|
|
40
|
+
import { SWAGGER_OPTIONS } from './swagger.module.js';
|
|
41
|
+
import { buildSwaggerInitializer } from './swagger-ui.js';
|
|
42
|
+
const swaggerUiDistPath = dirname(fileURLToPath(import.meta.resolve('swagger-ui-dist/package.json')));
|
|
43
|
+
let SwaggerService = (() => {
|
|
44
|
+
let _classDecorators = [Injectable()];
|
|
45
|
+
let _classDescriptor;
|
|
46
|
+
let _classExtraInitializers = [];
|
|
47
|
+
let _classThis;
|
|
48
|
+
var SwaggerService = class {
|
|
49
|
+
static { _classThis = this; }
|
|
50
|
+
static {
|
|
51
|
+
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
|
|
52
|
+
__esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
|
|
53
|
+
SwaggerService = _classThis = _classDescriptor.value;
|
|
54
|
+
if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
55
|
+
__runInitializers(_classThis, _classExtraInitializers);
|
|
56
|
+
}
|
|
57
|
+
discovery = inject(DiscoveryService);
|
|
58
|
+
router = inject(Router);
|
|
59
|
+
options = inject(SWAGGER_OPTIONS);
|
|
60
|
+
async onReady() {
|
|
61
|
+
const controllers = this.collectControllers();
|
|
62
|
+
const spec = new SpecBuilder().build(controllers, this.options);
|
|
63
|
+
const specJson = JSON.stringify(spec);
|
|
64
|
+
const specPath = this.options.path ?? '/docs/json';
|
|
65
|
+
const uiPath = this.options.uiPath ?? '/docs';
|
|
66
|
+
// NOTE: routes registered here bypass router.compileAll() - it already ran
|
|
67
|
+
// in compilePipelines() before bootstrapAll(), so `compiledPipeline` stays
|
|
68
|
+
// undefined and no per-route guards are grafted on. Global middleware from
|
|
69
|
+
// `app.use()` still wraps the dispatch (cors, logger, request-id on /docs
|
|
70
|
+
// is desirable). `skipGlobalGuards: true` is kept as a semantic marker +
|
|
71
|
+
// safety net: if the user later calls app.addRoute() (flipping compiled=false),
|
|
72
|
+
// a subsequent compilePipelines() re-runs compileAll across all entries, and
|
|
73
|
+
// this flag ensures global auth guards still don't graft onto swagger endpoints.
|
|
74
|
+
this.router.add('GET', specPath, () => new Response(specJson, { headers: { 'Content-Type': 'application/json' } }), { skipGlobalGuards: true });
|
|
75
|
+
if (this.options.ui !== false) {
|
|
76
|
+
const initializer = buildSwaggerInitializer(specPath, this.options.swaggerOptions);
|
|
77
|
+
this.router.add('GET', `${uiPath}/swagger-initializer.js`, () => new Response(initializer, { headers: { 'Content-Type': 'application/javascript' } }), { skipGlobalGuards: true });
|
|
78
|
+
this.router.add('GET', `${uiPath}/*`, createStaticHandler(swaggerUiDistPath, { maxAge: 3600 }), {
|
|
79
|
+
skipGlobalGuards: true,
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
collectControllers() {
|
|
84
|
+
const result = [];
|
|
85
|
+
for (const { ctor } of this.discovery.getSingletons()) {
|
|
86
|
+
const prefix = getMeta(ctor, RESOLVED_PREFIX);
|
|
87
|
+
if (prefix !== undefined)
|
|
88
|
+
result.push({ controller: ctor, prefix });
|
|
89
|
+
}
|
|
90
|
+
return result;
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
return SwaggerService = _classThis;
|
|
94
|
+
})();
|
|
95
|
+
export { SwaggerService };
|
|
96
|
+
//# sourceMappingURL=swagger.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"swagger.service.js","sourceRoot":"","sources":["../src/swagger.service.ts"],"names":[],"mappings":"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"}
|