fix(backend): clone schema before converting to OAS schema to avoid mutation (#15294)

* fix(backend): clone schema before converting to OAS schema to avoid mutation

* Update CHANGELOG.md

* fix: use deepClone
This commit is contained in:
zyoshoka
2025-01-18 13:05:33 +09:00
committed by GitHub
parent b16f5a781e
commit 1ef62e9e33
2 changed files with 4 additions and 1 deletions

View File

@@ -3,13 +3,15 @@
* SPDX-License-Identifier: AGPL-3.0-only
*/
import { deepClone } from '@/misc/clone.js';
import type { Schema } from '@/misc/json-schema.js';
import { refs } from '@/misc/json-schema.js';
export function convertSchemaToOpenApiSchema(schema: Schema, type: 'param' | 'res', includeSelfRef: boolean): any {
// optional, nullable, refはスキーマ定義に含まれないので分離しておく
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { optional, nullable, ref, selfRef, ...res }: any = schema;
const { optional, nullable, ref, selfRef, ..._res }: any = schema;
const res = deepClone(_res);
if (schema.type === 'object' && schema.properties) {
if (type === 'res') {