bxo 0.0.5-dev.71 → 0.0.5-dev.72
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/package.json +1 -1
- package/plugins/openapi.ts +20 -19
package/package.json
CHANGED
package/plugins/openapi.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import BXO, { z } from "../src";
|
|
2
|
-
import { createDocument, type CreateDocumentOptions, type ZodOpenApiPathsObject, type ZodOpenApiSecuritySchemeObject } from "zod-openapi";
|
|
2
|
+
import { createDocument, type CreateDocumentOptions, type ZodOpenApiPathItemObject, type ZodOpenApiPathsObject, type ZodOpenApiSecuritySchemeObject } from "zod-openapi";
|
|
3
3
|
|
|
4
4
|
interface SecurityScheme extends ZodOpenApiSecuritySchemeObject {
|
|
5
5
|
type: "http" | "apiKey" | "oauth2" | "openIdConnect";
|
|
@@ -40,24 +40,24 @@ const createOpenApiPaths = (app: BXO, config?: OpenApiPluginConfig): ZodOpenApiP
|
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
// Extract tags from route metadata
|
|
43
|
-
const tags = route.schema?.detail?.tags ||
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
43
|
+
const tags = route.schema?.detail?.tags ||
|
|
44
|
+
route.schema?.detail?.tag ||
|
|
45
|
+
config?.defaultTags ||
|
|
46
|
+
[]
|
|
47
47
|
|
|
48
48
|
// Extract security requirements from route metadata
|
|
49
|
-
const routeSecurity = route.schema?.detail?.security ||
|
|
50
|
-
|
|
51
|
-
|
|
49
|
+
const routeSecurity = route.schema?.detail?.security ||
|
|
50
|
+
route.schema?.detail?.auth ||
|
|
51
|
+
undefined
|
|
52
52
|
|
|
53
53
|
// Extract operation summary and description
|
|
54
|
-
const summary = route.schema?.detail?.summary ||
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
const description = route.schema?.detail?.description ||
|
|
59
|
-
|
|
60
|
-
|
|
54
|
+
const summary = route.schema?.detail?.summary ||
|
|
55
|
+
route.schema?.detail?.title ||
|
|
56
|
+
`${method.toUpperCase()} ${route.path}`
|
|
57
|
+
|
|
58
|
+
const description = route.schema?.detail?.description ||
|
|
59
|
+
route.schema?.detail?.docs ||
|
|
60
|
+
undefined
|
|
61
61
|
|
|
62
62
|
// Extract parameters from route path
|
|
63
63
|
const parameters = []
|
|
@@ -76,15 +76,16 @@ const createOpenApiPaths = (app: BXO, config?: OpenApiPluginConfig): ZodOpenApiP
|
|
|
76
76
|
}
|
|
77
77
|
|
|
78
78
|
// Add query parameters if defined
|
|
79
|
-
if (route.schema?.
|
|
80
|
-
const querySchema = route.schema?.
|
|
79
|
+
if (route.schema?.query) {
|
|
80
|
+
const querySchema = route.schema?.query
|
|
81
81
|
if (querySchema && typeof querySchema === 'object' && 'shape' in querySchema) {
|
|
82
82
|
const queryShape = (querySchema as any).shape
|
|
83
83
|
for (const [key, schema] of Object.entries(queryShape)) {
|
|
84
|
+
const isOptional = schema instanceof z.ZodOptional
|
|
84
85
|
parameters.push({
|
|
85
86
|
name: key,
|
|
86
87
|
in: "query",
|
|
87
|
-
required:
|
|
88
|
+
required: !isOptional, // Query params are typically optional
|
|
88
89
|
schema: schema as any
|
|
89
90
|
})
|
|
90
91
|
}
|
|
@@ -138,7 +139,7 @@ const createOpenApiPaths = (app: BXO, config?: OpenApiPluginConfig): ZodOpenApiP
|
|
|
138
139
|
}
|
|
139
140
|
}
|
|
140
141
|
}
|
|
141
|
-
}
|
|
142
|
+
} satisfies ZodOpenApiPathItemObject
|
|
142
143
|
}
|
|
143
144
|
return paths
|
|
144
145
|
}
|