@byyuurin/nitro-openapi 0.0.3 → 0.0.4

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/index.cjs CHANGED
@@ -1,159 +1,7 @@
1
- 'use strict';
2
-
3
- const defu = require('defu');
4
-
5
- function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
6
-
7
- const defu__default = /*#__PURE__*/_interopDefaultCompat(defu);
8
-
9
- function createOpenApiRegister(defaults) {
10
- const { paths = {}, components = {}, security = [], servers = [], info, tags = [] } = defaults;
11
- const defineOperation = (operation) => operation;
12
- function register(route, routeOperation, method = "get") {
13
- const _route = normalizeRoute(route);
14
- paths[_route] = defu__default(
15
- { [method]: routeOperation },
16
- paths[_route]
17
- );
1
+ module.exports = require("C:/Projects/nitro-openapi/node_modules/.pnpm/jiti@1.21.0/node_modules/jiti/lib/index.js")(null, {
2
+ "esmResolve": true,
3
+ "interopDefault": true,
4
+ "alias": {
5
+ "@byyuurin/nitro-openapi": "C:/Projects/nitro-openapi"
18
6
  }
19
- function merge(config) {
20
- return mergeConfig(
21
- config,
22
- {
23
- paths,
24
- components,
25
- security,
26
- servers,
27
- info,
28
- tags
29
- }
30
- );
31
- }
32
- return {
33
- configExtends: {
34
- paths,
35
- components,
36
- security,
37
- servers,
38
- info,
39
- tags
40
- },
41
- defineOperation,
42
- register,
43
- merge
44
- };
45
- }
46
- function normalizeRoute(_route) {
47
- let anonymousCtr = 0;
48
- const route = _route.replace(/:(\w+)/g, (_, name) => `{${name}}`).replace(/\/(\*)\//g, () => `/{param${++anonymousCtr}}/`).replace(/\*\*{/, "{").replace(/\/(\*\*)$/g, () => `/{*param${++anonymousCtr}}`);
49
- return route;
50
- }
51
- function mergeConfig(defaults, appends) {
52
- const methods = /* @__PURE__ */ new Set(["delete", "get", "head", "options", "patch", "post", "put", "trace"]);
53
- const { info } = appends;
54
- const { paths = {} } = defaults;
55
- for (const path in paths) {
56
- const operations = paths[path];
57
- if ("$ref" in operations)
58
- continue;
59
- paths[path] = Object.fromEntries(Object.entries(operations).map(([key, obj]) => {
60
- if (methods.has(key))
61
- return [key, normalizeSchema(obj)];
62
- return [key, obj];
63
- }));
64
- }
65
- return defu__default({ info }, defaults, appends);
66
- }
67
- function normalizeSchema(obj) {
68
- if ("$ref" in obj)
69
- return obj;
70
- const { parameters = [] } = obj;
71
- obj.parameters = parameters.map((p) => {
72
- if ("$ref" in p)
73
- return p;
74
- return defu__default(p, {
75
- schema: { type: "string" }
76
- });
77
- });
78
- return obj;
79
- }
80
-
81
- function resolveSchemaObject(value, options = {}) {
82
- const { allowExample = true, ...defaults } = options || {};
83
- const resolveResult = (obj, example) => {
84
- if (allowExample && example != null)
85
- obj.example = example;
86
- return { ...defaults, ...obj };
87
- };
88
- if (Array.isArray(value)) {
89
- return resolveResult(
90
- {
91
- type: "array",
92
- items: resolveSchemaObject(value[0], { allowExample: false })
93
- },
94
- value
95
- );
96
- }
97
- const _type = typeof value;
98
- switch (_type) {
99
- case "function":
100
- case "symbol":
101
- case "undefined":
102
- return { type: "null" };
103
- case "object":
104
- return resolveResult(
105
- {
106
- type: "object",
107
- properties: Object.fromEntries(Object.entries(value).map(([k, v]) => [
108
- k,
109
- resolveSchemaObject(v, {
110
- allowExample: false
111
- })
112
- ]))
113
- },
114
- value
115
- );
116
- case "bigint":
117
- return resolveResult(
118
- { type: "integer" },
119
- value
120
- );
121
- case "string":
122
- return resolveResult(
123
- { type: "string" },
124
- value || null
125
- );
126
- default:
127
- return resolveResult(
128
- { type: _type },
129
- value
130
- );
131
- }
132
- }
133
- function toExampleSchema(example, description, options) {
134
- if (typeof example !== "object") {
135
- return resolveSchemaObject(
136
- example,
137
- typeof description === "string" ? { ...options, description } : {}
138
- );
139
- }
140
- if (Array.isArray(example)) {
141
- if (typeof description === "string")
142
- return resolveSchemaObject(example, { ...options, description });
143
- const schema2 = resolveSchemaObject(example, { allowExample: false });
144
- schema2.items = toExampleSchema(example[0], description, options);
145
- return schema2;
146
- }
147
- if (typeof description === "string")
148
- return resolveSchemaObject(example, { ...options, description });
149
- const schema = resolveSchemaObject(example, options);
150
- schema.properties = Object.fromEntries(Object.entries(schema.properties).map(([p, item]) => [p, {
151
- ...item,
152
- ...typeof description === "object" ? { description: description?.[p] } : {}
153
- }]));
154
- return schema;
155
- }
156
-
157
- exports.createOpenApiRegister = createOpenApiRegister;
158
- exports.resolveSchemaObject = resolveSchemaObject;
159
- exports.toExampleSchema = toExampleSchema;
7
+ })("C:/Projects/nitro-openapi/src/index.ts")
package/dist/index.d.ts CHANGED
@@ -1,105 +1 @@
1
- import * as openapi_typescript from 'openapi-typescript';
2
- import { SchemaObject, ReferenceObject, PathItemObject, ResponseObject, MediaTypeObject, OperationObject, ParameterObject, RequestBodyObject, SecurityRequirementObject, OpenAPI3 } from 'openapi-typescript';
3
-
4
- type ReferenceRef<T extends OpenApiRegisterConfig> = T extends {
5
- components: infer C;
6
- } ? {
7
- [K in keyof C]: C[K] extends object ? `#/components/${K & string}/${keyof C[K] & string}` : never;
8
- }[keyof C] : string;
9
- type SchemaExtended<T extends string> = SchemaObject | ({
10
- type: 'array';
11
- prefixItems?: MaybeReference<SchemaExtended<T>, T>[];
12
- items?: MaybeReference<SchemaExtended<T>, T> | MaybeReference<SchemaExtended<T>, T>[];
13
- enum?: MaybeReference<SchemaExtended<T>, T>[];
14
- description?: string;
15
- } | {
16
- type: 'object' | ['object', 'null'];
17
- properties?: {
18
- [name: string]: MaybeReference<SchemaExtended<T>, T>;
19
- };
20
- allOf?: MaybeReference<SchemaExtended<T>, T>[];
21
- anyOf?: MaybeReference<SchemaExtended<T>, T>[];
22
- enum?: MaybeReference<SchemaExtended<T>, T>[];
23
- description?: string;
24
- });
25
- type ReferenceExtended<T extends string> = Omit<ReferenceObject, '$ref'> & {
26
- $ref: T;
27
- };
28
- type MaybeReference<T, R extends string = string> = T | ReferenceExtended<R>;
29
- type MaybeValueOrObject<ExampleT, ContentT> = ExampleT extends number | string | boolean ? ContentT : ExampleT extends (infer ArrayT)[] ? ContentT | MaybeValueOrObject<ArrayT, ContentT> : ExampleT extends Record<infer PropertyT, unknown> ? {
30
- [key in PropertyT]?: ContentT;
31
- } | ContentT : ContentT;
32
- type PathOperations = Omit<PathItemObject, 'servers' | 'parameters' | `x-${string}`>;
33
- type PathOperationMethod = keyof PathOperations;
34
- type PathResponse<RefT extends string> = Omit<ResponseObject, 'content'> & {
35
- content?: {
36
- [contentType: string]: Omit<MediaTypeObject, 'schema'> & {
37
- schema?: MaybeReference<SchemaExtended<RefT>, RefT>;
38
- };
39
- };
40
- };
41
- type PathOperationItem<T extends OpenApiRegisterConfig> = Omit<OperationObject, 'tags' | 'parameters' | 'requestBody' | 'responses' | 'security'> & {
42
- tags?: T extends {
43
- tags: infer Tags;
44
- } ? Tags extends ({
45
- name: infer Tag;
46
- })[] ? Tag[] | string[] : string[] : string[];
47
- parameters?: MaybeReference<ParameterObject & {
48
- schema?: SchemaExtended<ReferenceRef<T>>;
49
- }, ReferenceRef<T>>[];
50
- requestBody?: MaybeReference<RequestBodyObject & {
51
- content: {
52
- [contentType: string]: MaybeReference<MediaTypeObject, ReferenceRef<T>>;
53
- };
54
- }, ReferenceRef<T>>;
55
- responses?: {
56
- [responseCode: string]: MaybeReference<PathResponse<ReferenceRef<T>>, ReferenceRef<T>>;
57
- } & {
58
- default?: MaybeReference<PathResponse<ReferenceRef<T>>, ReferenceRef<T>>;
59
- };
60
- security?: T extends {
61
- components: infer C;
62
- } ? C extends {
63
- securitySchemes: infer S;
64
- } ? {
65
- [SecurityName in keyof S]?: string[];
66
- }[] : SecurityRequirementObject[] : SecurityRequirementObject[];
67
- };
68
- type OpenApiRegisterConfig = Pick<Partial<OpenAPI3>, 'paths' | 'components' | 'security' | 'servers' | 'info' | 'tags'>;
69
-
70
- declare function createOpenApiRegister<T extends OpenApiRegisterConfig = OpenApiRegisterConfig>(defaults: T): {
71
- configExtends: T;
72
- defineOperation: (operation: PathOperationItem<T>) => PathOperationItem<T>;
73
- register: (route: string, routeOperation: MaybeReference<PathOperationItem<T>, ReferenceRef<T>>, method?: keyof PathOperations) => void;
74
- merge: (config: Partial<OpenAPI3>) => Partial<OpenAPI3>;
75
- };
76
-
77
- type SchemaObjectOptions = SchemaObject & {
78
- allowExample?: boolean;
79
- };
80
- declare function resolveSchemaObject(value: any, options?: SchemaObjectOptions): SchemaObject;
81
- type ExampleDescription<ExampleT> = MaybeValueOrObject<ExampleT, string>;
82
- declare function toExampleSchema<T = any>(example: T, description?: ExampleDescription<T>, options?: SchemaObject): {
83
- [key: `x-${string}`]: any;
84
- discriminator?: openapi_typescript.DiscriminatorObject | undefined;
85
- xml?: openapi_typescript.XMLObject | undefined;
86
- externalDocs?: openapi_typescript.ExternalDocumentationObject | undefined;
87
- example?: any;
88
- title?: string | undefined;
89
- description?: string | undefined;
90
- $comment?: string | undefined;
91
- deprecated?: boolean | undefined;
92
- readOnly?: boolean | undefined;
93
- writeOnly?: boolean | undefined;
94
- enum?: unknown[] | undefined;
95
- const?: unknown;
96
- default?: unknown;
97
- format?: string | undefined;
98
- nullable?: boolean | undefined;
99
- oneOf?: (SchemaObject | openapi_typescript.ReferenceObject)[] | undefined;
100
- allOf?: (SchemaObject | openapi_typescript.ReferenceObject)[] | undefined;
101
- anyOf?: (SchemaObject | openapi_typescript.ReferenceObject)[] | undefined;
102
- required?: string[] | undefined;
103
- };
104
-
105
- export { type MaybeReference, type MaybeValueOrObject, type OpenApiRegisterConfig, type PathOperationItem, type PathOperationMethod, type PathOperations, type PathResponse, type ReferenceExtended, type ReferenceRef, type SchemaExtended, createOpenApiRegister, resolveSchemaObject, toExampleSchema };
1
+ export * from "C:/Projects/nitro-openapi/src/index";
package/dist/index.mjs CHANGED
@@ -1,151 +1,14 @@
1
- import defu from 'defu';
1
+ import jiti from "file:///C:/Projects/nitro-openapi/node_modules/.pnpm/jiti@1.21.0/node_modules/jiti/lib/index.js";
2
2
 
3
- function createOpenApiRegister(defaults) {
4
- const { paths = {}, components = {}, security = [], servers = [], info, tags = [] } = defaults;
5
- const defineOperation = (operation) => operation;
6
- function register(route, routeOperation, method = "get") {
7
- const _route = normalizeRoute(route);
8
- paths[_route] = defu(
9
- { [method]: routeOperation },
10
- paths[_route]
11
- );
12
- }
13
- function merge(config) {
14
- return mergeConfig(
15
- config,
16
- {
17
- paths,
18
- components,
19
- security,
20
- servers,
21
- info,
22
- tags
23
- }
24
- );
25
- }
26
- return {
27
- configExtends: {
28
- paths,
29
- components,
30
- security,
31
- servers,
32
- info,
33
- tags
34
- },
35
- defineOperation,
36
- register,
37
- merge
38
- };
39
- }
40
- function normalizeRoute(_route) {
41
- let anonymousCtr = 0;
42
- const route = _route.replace(/:(\w+)/g, (_, name) => `{${name}}`).replace(/\/(\*)\//g, () => `/{param${++anonymousCtr}}/`).replace(/\*\*{/, "{").replace(/\/(\*\*)$/g, () => `/{*param${++anonymousCtr}}`);
43
- return route;
44
- }
45
- function mergeConfig(defaults, appends) {
46
- const methods = /* @__PURE__ */ new Set(["delete", "get", "head", "options", "patch", "post", "put", "trace"]);
47
- const { info } = appends;
48
- const { paths = {} } = defaults;
49
- for (const path in paths) {
50
- const operations = paths[path];
51
- if ("$ref" in operations)
52
- continue;
53
- paths[path] = Object.fromEntries(Object.entries(operations).map(([key, obj]) => {
54
- if (methods.has(key))
55
- return [key, normalizeSchema(obj)];
56
- return [key, obj];
57
- }));
58
- }
59
- return defu({ info }, defaults, appends);
60
- }
61
- function normalizeSchema(obj) {
62
- if ("$ref" in obj)
63
- return obj;
64
- const { parameters = [] } = obj;
65
- obj.parameters = parameters.map((p) => {
66
- if ("$ref" in p)
67
- return p;
68
- return defu(p, {
69
- schema: { type: "string" }
70
- });
71
- });
72
- return obj;
73
- }
74
-
75
- function resolveSchemaObject(value, options = {}) {
76
- const { allowExample = true, ...defaults } = options || {};
77
- const resolveResult = (obj, example) => {
78
- if (allowExample && example != null)
79
- obj.example = example;
80
- return { ...defaults, ...obj };
81
- };
82
- if (Array.isArray(value)) {
83
- return resolveResult(
84
- {
85
- type: "array",
86
- items: resolveSchemaObject(value[0], { allowExample: false })
87
- },
88
- value
89
- );
90
- }
91
- const _type = typeof value;
92
- switch (_type) {
93
- case "function":
94
- case "symbol":
95
- case "undefined":
96
- return { type: "null" };
97
- case "object":
98
- return resolveResult(
99
- {
100
- type: "object",
101
- properties: Object.fromEntries(Object.entries(value).map(([k, v]) => [
102
- k,
103
- resolveSchemaObject(v, {
104
- allowExample: false
105
- })
106
- ]))
107
- },
108
- value
109
- );
110
- case "bigint":
111
- return resolveResult(
112
- { type: "integer" },
113
- value
114
- );
115
- case "string":
116
- return resolveResult(
117
- { type: "string" },
118
- value || null
119
- );
120
- default:
121
- return resolveResult(
122
- { type: _type },
123
- value
124
- );
125
- }
126
- }
127
- function toExampleSchema(example, description, options) {
128
- if (typeof example !== "object") {
129
- return resolveSchemaObject(
130
- example,
131
- typeof description === "string" ? { ...options, description } : {}
132
- );
133
- }
134
- if (Array.isArray(example)) {
135
- if (typeof description === "string")
136
- return resolveSchemaObject(example, { ...options, description });
137
- const schema2 = resolveSchemaObject(example, { allowExample: false });
138
- schema2.items = toExampleSchema(example[0], description, options);
139
- return schema2;
140
- }
141
- if (typeof description === "string")
142
- return resolveSchemaObject(example, { ...options, description });
143
- const schema = resolveSchemaObject(example, options);
144
- schema.properties = Object.fromEntries(Object.entries(schema.properties).map(([p, item]) => [p, {
145
- ...item,
146
- ...typeof description === "object" ? { description: description?.[p] } : {}
147
- }]));
148
- return schema;
149
- }
3
+ /** @type {import("C:/Projects/nitro-openapi/src/index")} */
4
+ const _module = jiti(null, {
5
+ "esmResolve": true,
6
+ "interopDefault": true,
7
+ "alias": {
8
+ "@byyuurin/nitro-openapi": "C:/Projects/nitro-openapi"
9
+ }
10
+ })("C:/Projects/nitro-openapi/src/index.ts");
150
11
 
151
- export { createOpenApiRegister, resolveSchemaObject, toExampleSchema };
12
+ export const createOpenApiRegister = _module.createOpenApiRegister;
13
+ export const resolveSchemaObject = _module.resolveSchemaObject;
14
+ export const toExampleSchema = _module.toExampleSchema;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@byyuurin/nitro-openapi",
3
3
  "type": "module",
4
- "version": "0.0.3",
4
+ "version": "0.0.4",
5
5
  "private": false,
6
6
  "license": "MIT",
7
7
  "homepage": "https://github.com/byyuurin/nitro-openapi",
package/dist/index.d.cts DELETED
@@ -1,105 +0,0 @@
1
- import * as openapi_typescript from 'openapi-typescript';
2
- import { SchemaObject, ReferenceObject, PathItemObject, ResponseObject, MediaTypeObject, OperationObject, ParameterObject, RequestBodyObject, SecurityRequirementObject, OpenAPI3 } from 'openapi-typescript';
3
-
4
- type ReferenceRef<T extends OpenApiRegisterConfig> = T extends {
5
- components: infer C;
6
- } ? {
7
- [K in keyof C]: C[K] extends object ? `#/components/${K & string}/${keyof C[K] & string}` : never;
8
- }[keyof C] : string;
9
- type SchemaExtended<T extends string> = SchemaObject | ({
10
- type: 'array';
11
- prefixItems?: MaybeReference<SchemaExtended<T>, T>[];
12
- items?: MaybeReference<SchemaExtended<T>, T> | MaybeReference<SchemaExtended<T>, T>[];
13
- enum?: MaybeReference<SchemaExtended<T>, T>[];
14
- description?: string;
15
- } | {
16
- type: 'object' | ['object', 'null'];
17
- properties?: {
18
- [name: string]: MaybeReference<SchemaExtended<T>, T>;
19
- };
20
- allOf?: MaybeReference<SchemaExtended<T>, T>[];
21
- anyOf?: MaybeReference<SchemaExtended<T>, T>[];
22
- enum?: MaybeReference<SchemaExtended<T>, T>[];
23
- description?: string;
24
- });
25
- type ReferenceExtended<T extends string> = Omit<ReferenceObject, '$ref'> & {
26
- $ref: T;
27
- };
28
- type MaybeReference<T, R extends string = string> = T | ReferenceExtended<R>;
29
- type MaybeValueOrObject<ExampleT, ContentT> = ExampleT extends number | string | boolean ? ContentT : ExampleT extends (infer ArrayT)[] ? ContentT | MaybeValueOrObject<ArrayT, ContentT> : ExampleT extends Record<infer PropertyT, unknown> ? {
30
- [key in PropertyT]?: ContentT;
31
- } | ContentT : ContentT;
32
- type PathOperations = Omit<PathItemObject, 'servers' | 'parameters' | `x-${string}`>;
33
- type PathOperationMethod = keyof PathOperations;
34
- type PathResponse<RefT extends string> = Omit<ResponseObject, 'content'> & {
35
- content?: {
36
- [contentType: string]: Omit<MediaTypeObject, 'schema'> & {
37
- schema?: MaybeReference<SchemaExtended<RefT>, RefT>;
38
- };
39
- };
40
- };
41
- type PathOperationItem<T extends OpenApiRegisterConfig> = Omit<OperationObject, 'tags' | 'parameters' | 'requestBody' | 'responses' | 'security'> & {
42
- tags?: T extends {
43
- tags: infer Tags;
44
- } ? Tags extends ({
45
- name: infer Tag;
46
- })[] ? Tag[] | string[] : string[] : string[];
47
- parameters?: MaybeReference<ParameterObject & {
48
- schema?: SchemaExtended<ReferenceRef<T>>;
49
- }, ReferenceRef<T>>[];
50
- requestBody?: MaybeReference<RequestBodyObject & {
51
- content: {
52
- [contentType: string]: MaybeReference<MediaTypeObject, ReferenceRef<T>>;
53
- };
54
- }, ReferenceRef<T>>;
55
- responses?: {
56
- [responseCode: string]: MaybeReference<PathResponse<ReferenceRef<T>>, ReferenceRef<T>>;
57
- } & {
58
- default?: MaybeReference<PathResponse<ReferenceRef<T>>, ReferenceRef<T>>;
59
- };
60
- security?: T extends {
61
- components: infer C;
62
- } ? C extends {
63
- securitySchemes: infer S;
64
- } ? {
65
- [SecurityName in keyof S]?: string[];
66
- }[] : SecurityRequirementObject[] : SecurityRequirementObject[];
67
- };
68
- type OpenApiRegisterConfig = Pick<Partial<OpenAPI3>, 'paths' | 'components' | 'security' | 'servers' | 'info' | 'tags'>;
69
-
70
- declare function createOpenApiRegister<T extends OpenApiRegisterConfig = OpenApiRegisterConfig>(defaults: T): {
71
- configExtends: T;
72
- defineOperation: (operation: PathOperationItem<T>) => PathOperationItem<T>;
73
- register: (route: string, routeOperation: MaybeReference<PathOperationItem<T>, ReferenceRef<T>>, method?: keyof PathOperations) => void;
74
- merge: (config: Partial<OpenAPI3>) => Partial<OpenAPI3>;
75
- };
76
-
77
- type SchemaObjectOptions = SchemaObject & {
78
- allowExample?: boolean;
79
- };
80
- declare function resolveSchemaObject(value: any, options?: SchemaObjectOptions): SchemaObject;
81
- type ExampleDescription<ExampleT> = MaybeValueOrObject<ExampleT, string>;
82
- declare function toExampleSchema<T = any>(example: T, description?: ExampleDescription<T>, options?: SchemaObject): {
83
- [key: `x-${string}`]: any;
84
- discriminator?: openapi_typescript.DiscriminatorObject | undefined;
85
- xml?: openapi_typescript.XMLObject | undefined;
86
- externalDocs?: openapi_typescript.ExternalDocumentationObject | undefined;
87
- example?: any;
88
- title?: string | undefined;
89
- description?: string | undefined;
90
- $comment?: string | undefined;
91
- deprecated?: boolean | undefined;
92
- readOnly?: boolean | undefined;
93
- writeOnly?: boolean | undefined;
94
- enum?: unknown[] | undefined;
95
- const?: unknown;
96
- default?: unknown;
97
- format?: string | undefined;
98
- nullable?: boolean | undefined;
99
- oneOf?: (SchemaObject | openapi_typescript.ReferenceObject)[] | undefined;
100
- allOf?: (SchemaObject | openapi_typescript.ReferenceObject)[] | undefined;
101
- anyOf?: (SchemaObject | openapi_typescript.ReferenceObject)[] | undefined;
102
- required?: string[] | undefined;
103
- };
104
-
105
- export { type MaybeReference, type MaybeValueOrObject, type OpenApiRegisterConfig, type PathOperationItem, type PathOperationMethod, type PathOperations, type PathResponse, type ReferenceExtended, type ReferenceRef, type SchemaExtended, createOpenApiRegister, resolveSchemaObject, toExampleSchema };
package/dist/index.d.mts DELETED
@@ -1,105 +0,0 @@
1
- import * as openapi_typescript from 'openapi-typescript';
2
- import { SchemaObject, ReferenceObject, PathItemObject, ResponseObject, MediaTypeObject, OperationObject, ParameterObject, RequestBodyObject, SecurityRequirementObject, OpenAPI3 } from 'openapi-typescript';
3
-
4
- type ReferenceRef<T extends OpenApiRegisterConfig> = T extends {
5
- components: infer C;
6
- } ? {
7
- [K in keyof C]: C[K] extends object ? `#/components/${K & string}/${keyof C[K] & string}` : never;
8
- }[keyof C] : string;
9
- type SchemaExtended<T extends string> = SchemaObject | ({
10
- type: 'array';
11
- prefixItems?: MaybeReference<SchemaExtended<T>, T>[];
12
- items?: MaybeReference<SchemaExtended<T>, T> | MaybeReference<SchemaExtended<T>, T>[];
13
- enum?: MaybeReference<SchemaExtended<T>, T>[];
14
- description?: string;
15
- } | {
16
- type: 'object' | ['object', 'null'];
17
- properties?: {
18
- [name: string]: MaybeReference<SchemaExtended<T>, T>;
19
- };
20
- allOf?: MaybeReference<SchemaExtended<T>, T>[];
21
- anyOf?: MaybeReference<SchemaExtended<T>, T>[];
22
- enum?: MaybeReference<SchemaExtended<T>, T>[];
23
- description?: string;
24
- });
25
- type ReferenceExtended<T extends string> = Omit<ReferenceObject, '$ref'> & {
26
- $ref: T;
27
- };
28
- type MaybeReference<T, R extends string = string> = T | ReferenceExtended<R>;
29
- type MaybeValueOrObject<ExampleT, ContentT> = ExampleT extends number | string | boolean ? ContentT : ExampleT extends (infer ArrayT)[] ? ContentT | MaybeValueOrObject<ArrayT, ContentT> : ExampleT extends Record<infer PropertyT, unknown> ? {
30
- [key in PropertyT]?: ContentT;
31
- } | ContentT : ContentT;
32
- type PathOperations = Omit<PathItemObject, 'servers' | 'parameters' | `x-${string}`>;
33
- type PathOperationMethod = keyof PathOperations;
34
- type PathResponse<RefT extends string> = Omit<ResponseObject, 'content'> & {
35
- content?: {
36
- [contentType: string]: Omit<MediaTypeObject, 'schema'> & {
37
- schema?: MaybeReference<SchemaExtended<RefT>, RefT>;
38
- };
39
- };
40
- };
41
- type PathOperationItem<T extends OpenApiRegisterConfig> = Omit<OperationObject, 'tags' | 'parameters' | 'requestBody' | 'responses' | 'security'> & {
42
- tags?: T extends {
43
- tags: infer Tags;
44
- } ? Tags extends ({
45
- name: infer Tag;
46
- })[] ? Tag[] | string[] : string[] : string[];
47
- parameters?: MaybeReference<ParameterObject & {
48
- schema?: SchemaExtended<ReferenceRef<T>>;
49
- }, ReferenceRef<T>>[];
50
- requestBody?: MaybeReference<RequestBodyObject & {
51
- content: {
52
- [contentType: string]: MaybeReference<MediaTypeObject, ReferenceRef<T>>;
53
- };
54
- }, ReferenceRef<T>>;
55
- responses?: {
56
- [responseCode: string]: MaybeReference<PathResponse<ReferenceRef<T>>, ReferenceRef<T>>;
57
- } & {
58
- default?: MaybeReference<PathResponse<ReferenceRef<T>>, ReferenceRef<T>>;
59
- };
60
- security?: T extends {
61
- components: infer C;
62
- } ? C extends {
63
- securitySchemes: infer S;
64
- } ? {
65
- [SecurityName in keyof S]?: string[];
66
- }[] : SecurityRequirementObject[] : SecurityRequirementObject[];
67
- };
68
- type OpenApiRegisterConfig = Pick<Partial<OpenAPI3>, 'paths' | 'components' | 'security' | 'servers' | 'info' | 'tags'>;
69
-
70
- declare function createOpenApiRegister<T extends OpenApiRegisterConfig = OpenApiRegisterConfig>(defaults: T): {
71
- configExtends: T;
72
- defineOperation: (operation: PathOperationItem<T>) => PathOperationItem<T>;
73
- register: (route: string, routeOperation: MaybeReference<PathOperationItem<T>, ReferenceRef<T>>, method?: keyof PathOperations) => void;
74
- merge: (config: Partial<OpenAPI3>) => Partial<OpenAPI3>;
75
- };
76
-
77
- type SchemaObjectOptions = SchemaObject & {
78
- allowExample?: boolean;
79
- };
80
- declare function resolveSchemaObject(value: any, options?: SchemaObjectOptions): SchemaObject;
81
- type ExampleDescription<ExampleT> = MaybeValueOrObject<ExampleT, string>;
82
- declare function toExampleSchema<T = any>(example: T, description?: ExampleDescription<T>, options?: SchemaObject): {
83
- [key: `x-${string}`]: any;
84
- discriminator?: openapi_typescript.DiscriminatorObject | undefined;
85
- xml?: openapi_typescript.XMLObject | undefined;
86
- externalDocs?: openapi_typescript.ExternalDocumentationObject | undefined;
87
- example?: any;
88
- title?: string | undefined;
89
- description?: string | undefined;
90
- $comment?: string | undefined;
91
- deprecated?: boolean | undefined;
92
- readOnly?: boolean | undefined;
93
- writeOnly?: boolean | undefined;
94
- enum?: unknown[] | undefined;
95
- const?: unknown;
96
- default?: unknown;
97
- format?: string | undefined;
98
- nullable?: boolean | undefined;
99
- oneOf?: (SchemaObject | openapi_typescript.ReferenceObject)[] | undefined;
100
- allOf?: (SchemaObject | openapi_typescript.ReferenceObject)[] | undefined;
101
- anyOf?: (SchemaObject | openapi_typescript.ReferenceObject)[] | undefined;
102
- required?: string[] | undefined;
103
- };
104
-
105
- export { type MaybeReference, type MaybeValueOrObject, type OpenApiRegisterConfig, type PathOperationItem, type PathOperationMethod, type PathOperations, type PathResponse, type ReferenceExtended, type ReferenceRef, type SchemaExtended, createOpenApiRegister, resolveSchemaObject, toExampleSchema };