Skip to content

Commit

Permalink
fix(schema): use allOf when $ref and type exists on the same schema l…
Browse files Browse the repository at this point in the history
…evel
  • Loading branch information
Romakita committed Dec 6, 2024
1 parent 35a5ff7 commit 9af17c3
Show file tree
Hide file tree
Showing 3 changed files with 2,034 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,23 @@ import {JsonSchemaOptions} from "../../interfaces/JsonSchemaOptions.js";
import {execMapper, registerJsonSchemaMapper} from "../../registries/JsonSchemaMapperContainer.js";
import {getInheritedStores} from "../../utils/getInheritedStores.js";

function alterMerge(_: string, obj: any) {
if (obj?.type && obj?.$ref) {
const {$ref, ...schema} = obj;

obj = {
allOf: [
{
$ref
},
schema
]
};
}

return obj;
}

/**
* @ignore
*/
Expand All @@ -12,10 +29,9 @@ export function inheritedClassMapper(obj: any, {target, ...options}: JsonSchemaO

if (stores.length) {
const schema = stores.reduce((obj, [, store]) => {
return deepMerge(obj, execMapper("schema", [store.schema], options));
return deepMerge(obj, execMapper("schema", [store.schema], options), {alter: alterMerge});
}, {});

obj = deepMerge(schema, obj);
obj = deepMerge(schema, obj, {alter: alterMerge});
}

return obj;
Expand Down
Loading

0 comments on commit 9af17c3

Please sign in to comment.