@@ -77,40 +77,15 @@ function OpenAPISchemaProperty(
7777 const header = < OpenAPISchemaPresentation id = { id } context = { context } property = { property } /> ;
7878 const content = ( ( ) => {
7979 if ( alternatives ?. schemas ) {
80- const { schemas, discriminator : alternativeDiscriminator , type } = alternatives ;
8180 return (
82- < div className = "openapi-schema-alternatives" >
83- { schemas . map ( ( alternativeSchema , index ) => {
84- // If the alternative has its own discriminator, use it.
85- const effectiveDiscriminator =
86- alternativeDiscriminator ||
87- ( type === 'allOf' ? discriminator : undefined ) ;
88-
89- // If we are inheriting and using parent discriminator, pass down the value.
90- const effectiveDiscriminatorValue =
91- ! alternativeDiscriminator && type === 'allOf'
92- ? discriminatorValue
93- : undefined ;
94-
95- return (
96- < div key = { index } className = "openapi-schema-alternative" >
97- < OpenAPISchemaAlternative
98- schema = { alternativeSchema }
99- discriminator = { effectiveDiscriminator }
100- discriminatorValue = { effectiveDiscriminatorValue }
101- circularRefs = { circularRefs }
102- context = { context }
103- />
104- { index < schemas . length - 1 ? (
105- < OpenAPISchemaAlternativeSeparator
106- schema = { schema }
107- context = { context }
108- />
109- ) : null }
110- </ div >
111- ) ;
112- } ) }
113- </ div >
81+ < OpenAPISchemaAlternatives
82+ alternatives = { alternatives }
83+ schema = { schema }
84+ circularRefs = { circularRefs }
85+ context = { context }
86+ parentDiscriminator = { discriminator }
87+ parentDiscriminatorValue = { discriminatorValue }
88+ />
11489 ) ;
11590 }
11691
@@ -219,36 +194,17 @@ function OpenAPIRootSchema(props: {
219194
220195 // Handle root-level oneOf/allOf/anyOf
221196 if ( alternatives ?. schemas ) {
222- const { schemas, discriminator : alternativeDiscriminator , type } = alternatives ;
223197 return (
224198 < >
225199 { description ? (
226200 < Markdown source = { description } className = "openapi-schema-root-description" />
227201 ) : null }
228- < div className = "openapi-schema-alternatives" >
229- { schemas . map ( ( alternativeSchema , index ) => {
230- // If the alternative has its own discriminator, use it.
231- const effectiveDiscriminator =
232- alternativeDiscriminator || ( type === 'allOf' ? undefined : undefined ) ;
233-
234- return (
235- < div key = { index } className = "openapi-schema-alternative" >
236- < OpenAPISchemaAlternative
237- schema = { alternativeSchema }
238- discriminator = { effectiveDiscriminator }
239- circularRefs = { circularRefs }
240- context = { context }
241- />
242- { index < schemas . length - 1 ? (
243- < OpenAPISchemaAlternativeSeparator
244- schema = { schema }
245- context = { context }
246- />
247- ) : null }
248- </ div >
249- ) ;
250- } ) }
251- </ div >
202+ < OpenAPISchemaAlternatives
203+ alternatives = { alternatives }
204+ schema = { schema }
205+ circularRefs = { circularRefs }
206+ context = { context }
207+ />
252208 </ >
253209 ) ;
254210 }
@@ -340,6 +296,66 @@ function getDiscriminatorValue(
340296 return ;
341297}
342298
299+ /**
300+ * Render alternatives (oneOf/allOf/anyOf) for a schema.
301+ */
302+ function OpenAPISchemaAlternatives ( props : {
303+ alternatives : SchemaAlternatives ;
304+ schema : OpenAPIV3 . SchemaObject ;
305+ circularRefs : CircularRefsIds ;
306+ context : OpenAPIClientContext ;
307+ parentDiscriminator ?: OpenAPIV3 . DiscriminatorObject ;
308+ parentDiscriminatorValue ?: string ;
309+ } ) {
310+ const {
311+ alternatives,
312+ schema,
313+ circularRefs,
314+ context,
315+ parentDiscriminator,
316+ parentDiscriminatorValue,
317+ } = props ;
318+
319+ if ( ! alternatives ?. schemas ) {
320+ return null ;
321+ }
322+
323+ const { schemas, discriminator : alternativeDiscriminator , type } = alternatives ;
324+
325+ return (
326+ < div className = "openapi-schema-alternatives" >
327+ { schemas . map ( ( alternativeSchema , index ) => {
328+ // If the alternative has its own discriminator, use it.
329+ // Otherwise, for allOf, inherit from parent discriminator.
330+ const effectiveDiscriminator =
331+ alternativeDiscriminator ||
332+ ( type === 'allOf' ? parentDiscriminator : undefined ) ;
333+
334+ // If we are inheriting and using parent discriminator, pass down the value.
335+ const effectiveDiscriminatorValue =
336+ ! alternativeDiscriminator && type === 'allOf'
337+ ? parentDiscriminatorValue
338+ : undefined ;
339+
340+ return (
341+ < div key = { index } className = "openapi-schema-alternative" >
342+ < OpenAPISchemaAlternative
343+ schema = { alternativeSchema }
344+ discriminator = { effectiveDiscriminator }
345+ discriminatorValue = { effectiveDiscriminatorValue }
346+ circularRefs = { circularRefs }
347+ context = { context }
348+ />
349+ { index < schemas . length - 1 ? (
350+ < OpenAPISchemaAlternativeSeparator schema = { schema } context = { context } />
351+ ) : null }
352+ </ div >
353+ ) ;
354+ } ) }
355+ </ div >
356+ ) ;
357+ }
358+
343359/**
344360 * Render a tab for an alternative schema.
345361 * It renders directly the properties if relevant;
0 commit comments