refactor(packages): flatten branches and keep helpers private

This commit is contained in:
Hampus committed 2026-10-24 20:55:15 +02:00
1 parent 9e64398ab7
commit 243dce38b8
7 files changed
+45 -31

No files matched your search

@@ -88,11 +88,14 @@ function toPascalCase(value: string): string {
function branchNamePrefix(discriminator: core.JSONSchema._JSONSchema | undefined): string | undefined {
if (typeof discriminator !== 'object') return undefined;
const enumNames = discriminator['x-enumNames'];
const value = Array.isArray(enumNames)
? enumNames[0]
: discriminator.enum?.length === 1
? discriminator.enum[0]
: discriminator.const;
let value: unknown;
if (Array.isArray(enumNames)) {
value = enumNames[0];
} else if (discriminator.enum?.length === 1) {
value = discriminator.enum[0];
} else {
value = discriminator.const;
}
return typeof value === 'string' ? toPascalCase(value) : undefined;
}
@@ -156,7 +156,12 @@ export class OpenAPIOperationBuilder {
}
const required = new Set(schema.required ?? []);
for (const [name, property] of Object.entries(schema.properties)) {
const propertySchema: OpenAPISchema = typeof property === 'boolean' ? (property ? {} : {not: {}}) : property;
let propertySchema: OpenAPISchema;
if (typeof property === 'boolean') {
propertySchema = property ? {} : {not: {}};
} else {
propertySchema = property;
}
const key = `${location}:${name}`;
if (parameters.has(key)) throw new Error(`Duplicate parameter ${key} for ${route.method} ${route.path}`);
parameters.set(key, {