@byyuurin/nitro-openapi 0.0.4 → 0.0.6

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,7 +1,159 @@
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"
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(options) {
10
+ const { paths = {}, components = {}, security = [], servers = [], info, tags = [] } = options;
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
+ );
6
18
  }
7
- })("C:/Projects/nitro-openapi/src/index.ts")
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;
@@ -0,0 +1,72 @@
1
+ import * as openapi_typescript from 'openapi-typescript';
2
+ import { ReferenceObject, SchemaObject, PathItemObject, OperationObject, SecurityRequirementObject, OpenAPI3 } from 'openapi-typescript';
3
+
4
+ type ReferenceType<T extends ApiRegisterOptions> = 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 ReplaceRef<T, RefT> = T extends ReferenceObject ? Omit<T, '$ref'> & {
10
+ $ref: RefT;
11
+ } : T extends object ? {
12
+ [K in keyof T]: ReplaceRef<T[K], RefT>;
13
+ } : T;
14
+ type WithTypedRef<T, RefT> = ReplaceRef<T, RefT>;
15
+ type SchemaType<RefT extends string> = ReplaceRef<SchemaObject, RefT>;
16
+ type MaybeReference<T, RefT = string> = T | ReplaceRef<ReferenceObject, RefT>;
17
+ type MaybeValueOrObject<ExampleT, ContentT> = ExampleT extends number | string | boolean ? ContentT : ExampleT extends (infer ArrayT)[] ? ContentT | MaybeValueOrObject<ArrayT, ContentT> : ExampleT extends object ? {
18
+ [key in keyof ExampleT]?: ContentT;
19
+ } | ContentT : unknown;
20
+ type PathOperation = Omit<PathItemObject, 'servers' | 'parameters' | `x-${string}`>;
21
+ type OperationType<T extends ApiRegisterOptions> = Omit<ReplaceRef<OperationObject, ReferenceType<T>>, 'tags' | 'security'> & {
22
+ tags?: T extends {
23
+ tags: infer Tags;
24
+ } ? Tags extends ({
25
+ name: infer Tag;
26
+ })[] ? Tag[] | string[] : string[] : string[];
27
+ security?: T extends {
28
+ components: infer C;
29
+ } ? C extends {
30
+ securitySchemes: infer S;
31
+ } ? {
32
+ [SecurityName in keyof S]?: string[];
33
+ }[] : SecurityRequirementObject[] : SecurityRequirementObject[];
34
+ };
35
+ type ApiRegisterOptions = Pick<Partial<OpenAPI3>, 'paths' | 'components' | 'security' | 'servers' | 'info' | 'tags'>;
36
+
37
+ declare function createOpenApiRegister<T extends ApiRegisterOptions = ApiRegisterOptions>(options: T): {
38
+ configExtends: T;
39
+ defineOperation: (operation: OperationType<T>) => OperationType<T>;
40
+ register: (route: string, routeOperation: OperationType<T>, method?: keyof PathOperation) => void;
41
+ merge: (config: Partial<OpenAPI3>) => Partial<OpenAPI3>;
42
+ };
43
+
44
+ type SchemaObjectOptions = SchemaObject & {
45
+ allowExample?: boolean;
46
+ };
47
+ declare function resolveSchemaObject(value: any, options?: SchemaObjectOptions): SchemaObject;
48
+ type ExampleDescription<ExampleT> = MaybeValueOrObject<ExampleT, string>;
49
+ declare function toExampleSchema<T = any>(example: T, description?: ExampleDescription<T>, options?: SchemaObject): {
50
+ [key: `x-${string}`]: any;
51
+ discriminator?: openapi_typescript.DiscriminatorObject | undefined;
52
+ xml?: openapi_typescript.XMLObject | undefined;
53
+ externalDocs?: openapi_typescript.ExternalDocumentationObject | undefined;
54
+ example?: any;
55
+ title?: string | undefined;
56
+ description?: string | undefined;
57
+ $comment?: string | undefined;
58
+ deprecated?: boolean | undefined;
59
+ readOnly?: boolean | undefined;
60
+ writeOnly?: boolean | undefined;
61
+ enum?: unknown[] | undefined;
62
+ const?: unknown;
63
+ default?: unknown;
64
+ format?: string | undefined;
65
+ nullable?: boolean | undefined;
66
+ oneOf?: (openapi_typescript.ReferenceObject | SchemaObject)[] | undefined;
67
+ allOf?: (openapi_typescript.ReferenceObject | SchemaObject)[] | undefined;
68
+ anyOf?: (openapi_typescript.ReferenceObject | SchemaObject)[] | undefined;
69
+ required?: string[] | undefined;
70
+ };
71
+
72
+ export { type ApiRegisterOptions, type MaybeReference, type MaybeValueOrObject, type OperationType, type PathOperation, type ReferenceType, type ReplaceRef, type SchemaType, type WithTypedRef, createOpenApiRegister, resolveSchemaObject, toExampleSchema };
@@ -0,0 +1,72 @@
1
+ import * as openapi_typescript from 'openapi-typescript';
2
+ import { ReferenceObject, SchemaObject, PathItemObject, OperationObject, SecurityRequirementObject, OpenAPI3 } from 'openapi-typescript';
3
+
4
+ type ReferenceType<T extends ApiRegisterOptions> = 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 ReplaceRef<T, RefT> = T extends ReferenceObject ? Omit<T, '$ref'> & {
10
+ $ref: RefT;
11
+ } : T extends object ? {
12
+ [K in keyof T]: ReplaceRef<T[K], RefT>;
13
+ } : T;
14
+ type WithTypedRef<T, RefT> = ReplaceRef<T, RefT>;
15
+ type SchemaType<RefT extends string> = ReplaceRef<SchemaObject, RefT>;
16
+ type MaybeReference<T, RefT = string> = T | ReplaceRef<ReferenceObject, RefT>;
17
+ type MaybeValueOrObject<ExampleT, ContentT> = ExampleT extends number | string | boolean ? ContentT : ExampleT extends (infer ArrayT)[] ? ContentT | MaybeValueOrObject<ArrayT, ContentT> : ExampleT extends object ? {
18
+ [key in keyof ExampleT]?: ContentT;
19
+ } | ContentT : unknown;
20
+ type PathOperation = Omit<PathItemObject, 'servers' | 'parameters' | `x-${string}`>;
21
+ type OperationType<T extends ApiRegisterOptions> = Omit<ReplaceRef<OperationObject, ReferenceType<T>>, 'tags' | 'security'> & {
22
+ tags?: T extends {
23
+ tags: infer Tags;
24
+ } ? Tags extends ({
25
+ name: infer Tag;
26
+ })[] ? Tag[] | string[] : string[] : string[];
27
+ security?: T extends {
28
+ components: infer C;
29
+ } ? C extends {
30
+ securitySchemes: infer S;
31
+ } ? {
32
+ [SecurityName in keyof S]?: string[];
33
+ }[] : SecurityRequirementObject[] : SecurityRequirementObject[];
34
+ };
35
+ type ApiRegisterOptions = Pick<Partial<OpenAPI3>, 'paths' | 'components' | 'security' | 'servers' | 'info' | 'tags'>;
36
+
37
+ declare function createOpenApiRegister<T extends ApiRegisterOptions = ApiRegisterOptions>(options: T): {
38
+ configExtends: T;
39
+ defineOperation: (operation: OperationType<T>) => OperationType<T>;
40
+ register: (route: string, routeOperation: OperationType<T>, method?: keyof PathOperation) => void;
41
+ merge: (config: Partial<OpenAPI3>) => Partial<OpenAPI3>;
42
+ };
43
+
44
+ type SchemaObjectOptions = SchemaObject & {
45
+ allowExample?: boolean;
46
+ };
47
+ declare function resolveSchemaObject(value: any, options?: SchemaObjectOptions): SchemaObject;
48
+ type ExampleDescription<ExampleT> = MaybeValueOrObject<ExampleT, string>;
49
+ declare function toExampleSchema<T = any>(example: T, description?: ExampleDescription<T>, options?: SchemaObject): {
50
+ [key: `x-${string}`]: any;
51
+ discriminator?: openapi_typescript.DiscriminatorObject | undefined;
52
+ xml?: openapi_typescript.XMLObject | undefined;
53
+ externalDocs?: openapi_typescript.ExternalDocumentationObject | undefined;
54
+ example?: any;
55
+ title?: string | undefined;
56
+ description?: string | undefined;
57
+ $comment?: string | undefined;
58
+ deprecated?: boolean | undefined;
59
+ readOnly?: boolean | undefined;
60
+ writeOnly?: boolean | undefined;
61
+ enum?: unknown[] | undefined;
62
+ const?: unknown;
63
+ default?: unknown;
64
+ format?: string | undefined;
65
+ nullable?: boolean | undefined;
66
+ oneOf?: (openapi_typescript.ReferenceObject | SchemaObject)[] | undefined;
67
+ allOf?: (openapi_typescript.ReferenceObject | SchemaObject)[] | undefined;
68
+ anyOf?: (openapi_typescript.ReferenceObject | SchemaObject)[] | undefined;
69
+ required?: string[] | undefined;
70
+ };
71
+
72
+ export { type ApiRegisterOptions, type MaybeReference, type MaybeValueOrObject, type OperationType, type PathOperation, type ReferenceType, type ReplaceRef, type SchemaType, type WithTypedRef, createOpenApiRegister, resolveSchemaObject, toExampleSchema };
package/dist/index.d.ts CHANGED
@@ -1 +1,72 @@
1
- export * from "C:/Projects/nitro-openapi/src/index";
1
+ import * as openapi_typescript from 'openapi-typescript';
2
+ import { ReferenceObject, SchemaObject, PathItemObject, OperationObject, SecurityRequirementObject, OpenAPI3 } from 'openapi-typescript';
3
+
4
+ type ReferenceType<T extends ApiRegisterOptions> = 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 ReplaceRef<T, RefT> = T extends ReferenceObject ? Omit<T, '$ref'> & {
10
+ $ref: RefT;
11
+ } : T extends object ? {
12
+ [K in keyof T]: ReplaceRef<T[K], RefT>;
13
+ } : T;
14
+ type WithTypedRef<T, RefT> = ReplaceRef<T, RefT>;
15
+ type SchemaType<RefT extends string> = ReplaceRef<SchemaObject, RefT>;
16
+ type MaybeReference<T, RefT = string> = T | ReplaceRef<ReferenceObject, RefT>;
17
+ type MaybeValueOrObject<ExampleT, ContentT> = ExampleT extends number | string | boolean ? ContentT : ExampleT extends (infer ArrayT)[] ? ContentT | MaybeValueOrObject<ArrayT, ContentT> : ExampleT extends object ? {
18
+ [key in keyof ExampleT]?: ContentT;
19
+ } | ContentT : unknown;
20
+ type PathOperation = Omit<PathItemObject, 'servers' | 'parameters' | `x-${string}`>;
21
+ type OperationType<T extends ApiRegisterOptions> = Omit<ReplaceRef<OperationObject, ReferenceType<T>>, 'tags' | 'security'> & {
22
+ tags?: T extends {
23
+ tags: infer Tags;
24
+ } ? Tags extends ({
25
+ name: infer Tag;
26
+ })[] ? Tag[] | string[] : string[] : string[];
27
+ security?: T extends {
28
+ components: infer C;
29
+ } ? C extends {
30
+ securitySchemes: infer S;
31
+ } ? {
32
+ [SecurityName in keyof S]?: string[];
33
+ }[] : SecurityRequirementObject[] : SecurityRequirementObject[];
34
+ };
35
+ type ApiRegisterOptions = Pick<Partial<OpenAPI3>, 'paths' | 'components' | 'security' | 'servers' | 'info' | 'tags'>;
36
+
37
+ declare function createOpenApiRegister<T extends ApiRegisterOptions = ApiRegisterOptions>(options: T): {
38
+ configExtends: T;
39
+ defineOperation: (operation: OperationType<T>) => OperationType<T>;
40
+ register: (route: string, routeOperation: OperationType<T>, method?: keyof PathOperation) => void;
41
+ merge: (config: Partial<OpenAPI3>) => Partial<OpenAPI3>;
42
+ };
43
+
44
+ type SchemaObjectOptions = SchemaObject & {
45
+ allowExample?: boolean;
46
+ };
47
+ declare function resolveSchemaObject(value: any, options?: SchemaObjectOptions): SchemaObject;
48
+ type ExampleDescription<ExampleT> = MaybeValueOrObject<ExampleT, string>;
49
+ declare function toExampleSchema<T = any>(example: T, description?: ExampleDescription<T>, options?: SchemaObject): {
50
+ [key: `x-${string}`]: any;
51
+ discriminator?: openapi_typescript.DiscriminatorObject | undefined;
52
+ xml?: openapi_typescript.XMLObject | undefined;
53
+ externalDocs?: openapi_typescript.ExternalDocumentationObject | undefined;
54
+ example?: any;
55
+ title?: string | undefined;
56
+ description?: string | undefined;
57
+ $comment?: string | undefined;
58
+ deprecated?: boolean | undefined;
59
+ readOnly?: boolean | undefined;
60
+ writeOnly?: boolean | undefined;
61
+ enum?: unknown[] | undefined;
62
+ const?: unknown;
63
+ default?: unknown;
64
+ format?: string | undefined;
65
+ nullable?: boolean | undefined;
66
+ oneOf?: (openapi_typescript.ReferenceObject | SchemaObject)[] | undefined;
67
+ allOf?: (openapi_typescript.ReferenceObject | SchemaObject)[] | undefined;
68
+ anyOf?: (openapi_typescript.ReferenceObject | SchemaObject)[] | undefined;
69
+ required?: string[] | undefined;
70
+ };
71
+
72
+ export { type ApiRegisterOptions, type MaybeReference, type MaybeValueOrObject, type OperationType, type PathOperation, type ReferenceType, type ReplaceRef, type SchemaType, type WithTypedRef, createOpenApiRegister, resolveSchemaObject, toExampleSchema };
package/dist/index.mjs CHANGED
@@ -1,14 +1,151 @@
1
- import jiti from "file:///C:/Projects/nitro-openapi/node_modules/.pnpm/jiti@1.21.0/node_modules/jiti/lib/index.js";
1
+ import defu from 'defu';
2
2
 
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");
3
+ function createOpenApiRegister(options) {
4
+ const { paths = {}, components = {}, security = [], servers = [], info, tags = [] } = options;
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
+ }
11
150
 
12
- export const createOpenApiRegister = _module.createOpenApiRegister;
13
- export const resolveSchemaObject = _module.resolveSchemaObject;
14
- export const toExampleSchema = _module.toExampleSchema;
151
+ export { createOpenApiRegister, resolveSchemaObject, 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.4",
4
+ "version": "0.0.6",
5
5
  "private": false,
6
6
  "license": "MIT",
7
7
  "homepage": "https://github.com/byyuurin/nitro-openapi",
@@ -24,14 +24,15 @@
24
24
  ],
25
25
  "dependencies": {
26
26
  "defu": "^6.1.4",
27
- "openapi-typescript": "^6.7.4"
27
+ "openapi-typescript": "^6.7.6"
28
28
  },
29
29
  "devDependencies": {
30
- "@byyuurin/eslint-config": "^1.0.2",
31
- "bumpp": "^9.3.1",
32
- "nitropack": "latest",
30
+ "@byyuurin/eslint-config": "^1.2.0",
31
+ "bumpp": "^9.4.1",
32
+ "eslint-plugin-format": "^0.1.1",
33
+ "nitropack": "^2.9.6",
33
34
  "unbuild": "^2.0.0",
34
- "vitest": "^1.3.1"
35
+ "vitest": "^1.6.0"
35
36
  },
36
37
  "resolutions": {
37
38
  "@byyuurin/nitro-openapi": "link:."