(
typeName: string,
propName: string,
schemas: JSONSchema7[],
ctx: GoCodegenCtx
)
| 2291 | } |
| 2292 | |
| 2293 | function mergeGoFlattenedPropertySchema( |
| 2294 | typeName: string, |
| 2295 | propName: string, |
| 2296 | schemas: JSONSchema7[], |
| 2297 | ctx: GoCodegenCtx |
| 2298 | ): JSONSchema7 { |
| 2299 | if (schemas.length === 1) return schemas[0]; |
| 2300 | |
| 2301 | const enumValues = schemas.map((schema) => goStringEnumValues(schema, ctx)); |
| 2302 | if (enumValues.every((values): values is string[] => values !== undefined)) { |
| 2303 | return { |
| 2304 | type: "string", |
| 2305 | enum: [...new Set(enumValues.flat())], |
| 2306 | title: typeName + toGoFieldName(propName), |
| 2307 | }; |
| 2308 | } |
| 2309 | |
| 2310 | const booleanValues = schemas.map((schema) => goBooleanValues(schema, ctx)); |
| 2311 | if (booleanValues.every((values): values is boolean[] => values !== undefined)) { |
| 2312 | return { type: "boolean" }; |
| 2313 | } |
| 2314 | |
| 2315 | const firstSchemaKey = stableStringify(resolveSchema(schemas[0], ctx.definitions) ?? schemas[0]); |
| 2316 | if (schemas.every((schema) => stableStringify(resolveSchema(schema, ctx.definitions) ?? schema) === firstSchemaKey)) { |
| 2317 | return schemas[0]; |
| 2318 | } |
| 2319 | |
| 2320 | const unionSchema = { anyOf: dedupeGoSchemasForMatch(schemas, ctx) }; |
| 2321 | const definitionRef = goDefinitionRefForEquivalentSchema(unionSchema, ctx); |
| 2322 | if (definitionRef) return { $ref: definitionRef }; |
| 2323 | |
| 2324 | return unionSchema; |
| 2325 | } |
| 2326 | |
| 2327 | function emitGoFlattenedObjectUnion( |
| 2328 | typeName: string, |
no test coverage detected
searching dependent graphs…