mirror of
https://github.com/zoriya/elysia-swagger.git
synced 2025-12-06 00:36:10 +00:00
🔧 fix: duplicate object reference
This commit is contained in:
@@ -1,3 +1,7 @@
|
||||
# 1.1.14 - 9 Oct 2024
|
||||
Bug fix:
|
||||
- Fix duplicate object reference
|
||||
|
||||
# 1.1.2 - 5 Sep 2024
|
||||
Feature:
|
||||
- add provenance publish
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@elysiajs/swagger",
|
||||
"version": "1.1.3",
|
||||
"version": "1.1.4",
|
||||
"description": "Plugin for Elysia to auto-generate Swagger page",
|
||||
"author": {
|
||||
"name": "saltyAom",
|
||||
@@ -62,7 +62,7 @@
|
||||
"devDependencies": {
|
||||
"@apidevtools/swagger-parser": "^10.1.0",
|
||||
"@types/bun": "1.1.6",
|
||||
"elysia": ">= 1.1.0-rc.2",
|
||||
"elysia": "1.1.18",
|
||||
"eslint": "9.6.0",
|
||||
"tsup": "^8.1.0",
|
||||
"typescript": "^5.5.3"
|
||||
|
||||
23
src/utils.ts
23
src/utils.ts
@@ -69,7 +69,9 @@ const mapTypesResponse = (
|
||||
|
||||
const responses: Record<string, OpenAPIV3.MediaTypeObject> = {}
|
||||
|
||||
for (const type of types)
|
||||
for (const type of types) {
|
||||
// console.log(schema)
|
||||
|
||||
responses[type] = {
|
||||
schema:
|
||||
typeof schema === 'string'
|
||||
@@ -78,6 +80,7 @@ const mapTypesResponse = (
|
||||
}
|
||||
: { ...(schema as any) }
|
||||
}
|
||||
}
|
||||
|
||||
return responses
|
||||
}
|
||||
@@ -101,6 +104,12 @@ export const generateOperationId = (method: string, paths: string) => {
|
||||
return operationId
|
||||
}
|
||||
|
||||
const cloneHook = <T>(hook: T) => {
|
||||
if (!hook) return
|
||||
|
||||
return { ...hook }
|
||||
}
|
||||
|
||||
export const registerSchemaPath = ({
|
||||
schema,
|
||||
path,
|
||||
@@ -126,13 +135,13 @@ export const registerSchemaPath = ({
|
||||
const contentTypes =
|
||||
typeof contentType === 'string'
|
||||
? [contentType]
|
||||
: contentType ?? ['application/json']
|
||||
: (contentType ?? ['application/json'])
|
||||
|
||||
const bodySchema = hook?.body
|
||||
const paramsSchema = hook?.params
|
||||
const headerSchema = hook?.headers
|
||||
const querySchema = hook?.query
|
||||
let responseSchema = hook?.response as unknown as OpenAPIV3.ResponsesObject
|
||||
const bodySchema = cloneHook(hook?.body)
|
||||
const paramsSchema = cloneHook(hook?.params)
|
||||
const headerSchema = cloneHook(hook?.headers)
|
||||
const querySchema = cloneHook(hook?.query)
|
||||
let responseSchema: OpenAPIV3.ResponsesObject = cloneHook(hook?.response)
|
||||
|
||||
if (typeof responseSchema === 'object') {
|
||||
if (Kind in responseSchema) {
|
||||
|
||||
Reference in New Issue
Block a user