Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: [AH-781]: Support allOf, oneOf keys along with properties key and update join condition for allOf and oneOf #37

Merged
merged 2 commits into from
Dec 13, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 21 additions & 20 deletions packages/cli/src/codegen.mts
Original file line number Diff line number Diff line change
Expand Up @@ -199,46 +199,47 @@ export function createObject(
originalRef: string,
components: IComponentsObject = {},
): ICodeWithMetadata {
const code: string[] = [];
const dependencies: string[] = [];
const imports: string[] = [];

if (isReferenceObject(item)) {
return createReferenceNode(item.$ref, originalRef);
}

if (Array.isArray(item.allOf)) {
const code: string[] = [];
const dependencies: string[] = [];
const imports: string[] = [];

if (Array.isArray(item.allOf) && item.allOf.length) {
const allOfCode: string[] = []
item.allOf.forEach((entry) => {
const resolvedValue = resolveValue(entry, originalRef);
code.push(resolvedValue.code);
allOfCode.push(resolvedValue.code);
dependencies.push(...resolvedValue.dependencies);
imports.push(...resolvedValue.imports);
});

return { code: code.join(' | '), dependencies, imports: uniq(imports) };
code.push(`(${allOfCode.join(' & ')})`);
}

if (Array.isArray(item.oneOf)) {
const code: string[] = [];
const dependencies: string[] = [];
const imports: string[] = [];

if (Array.isArray(item.oneOf) && item.oneOf.length) {
const oneOfCode: string[] = []
item.oneOf.forEach((entry) => {
const resolvedValue = resolveValue(entry, originalRef);
code.push(resolvedValue.code);
oneOfCode.push(resolvedValue.code);
dependencies.push(...resolvedValue.dependencies);
imports.push(...resolvedValue.imports);
});

return { code: code.join(' & '), dependencies, imports: uniq(imports) };
code.push(`(${oneOfCode.join(' | ')})`);
}

const props = createObjectProperties(item, originalRef, components);
if (item.type || has(item, 'properties') || has(item, 'additionalProperties')) {
const props = createObjectProperties(item, originalRef, components);
code.push(liquid.renderSync(OBJECT_TEMPLATE, { props }))
dependencies.push(... props.flatMap((p) => p.dependencies))
imports.push(...props.flatMap((p) => p.imports))
}

return {
code: liquid.renderSync(OBJECT_TEMPLATE, { props }),
imports: uniq(props.flatMap((p) => p.imports)),
dependencies: uniq(props.flatMap((p) => p.dependencies)),
code: code.join(' & '),
imports: uniq(imports),
dependencies: uniq(dependencies),
};
}

Expand Down
Loading