🔧 fix: duplicate object reference

This commit is contained in:
saltyaom
2024-10-09 02:00:59 +07:00
parent 90816d9720
commit 8c4634ad07
4 changed files with 46 additions and 33 deletions

View File

@@ -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

BIN
bun.lockb

Binary file not shown.

View File

@@ -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"

View File

@@ -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) {