@@ -34,6 +34,21 @@ export interface OpenAPIRefProps {
3434 collectRefs ?: boolean
3535}
3636
37+ export const get$Ref = (
38+ obj : OpenAPIV3_1 . ReferenceObject | OpenAPIV3_1 . SchemaObject ,
39+ ) => {
40+ if ( '$ref' in obj && obj . $ref ) {
41+ return obj . $ref
42+ }
43+ if ( 'allOf' in obj && Array . isArray ( obj . allOf ) ) {
44+ for ( const item of obj . allOf ) {
45+ if ( '$ref' in item && item . $ref ) {
46+ return item . $ref
47+ }
48+ }
49+ }
50+ }
51+
3752export const OpenAPIProperty = ( {
3853 name,
3954 property,
@@ -43,53 +58,74 @@ export const OpenAPIProperty = ({
4358 property : OpenAPIV3_1 . ReferenceObject | OpenAPIV3_1 . SchemaObject
4459 openapi : OpenAPIV3_1 . Document
4560} ) => {
46- const propObj =
47- '$ref' in property ? resolveRef ( openapi , property . $ref ) : property
61+ const prop$Ref = get$Ref ( property )
62+
63+ const propObj = prop$Ref
64+ ? resolveRef ( openapi , prop$Ref )
65+ : ( property as OpenAPIV3_1 . SchemaObject )
66+
4867 const type = propObj . type
68+
4969 let typeNode : ReactNode
5070 let extraNode : ReactNode
71+
5172 if ( type === 'array' ) {
5273 const { items } = propObj
53- const itemsObj = '$ref' in items ? resolveRef ( openapi , items . $ref ) : items
74+ const items$Ref = get$Ref ( items )
75+ const itemsObj = items$Ref
76+ ? resolveRef ( openapi , items$Ref )
77+ : ( items as OpenAPIV3_1 . SchemaObject )
5478 const itemsType = itemsObj . type
5579 typeNode = (
5680 < code >
5781 []
58- { '$ref' in items ? < RefLink $ref = { items . $ref } /> : itemsType }
82+ { items$Ref ? < RefLink $ref = { items$Ref } /> : itemsType }
5983 </ code >
6084 )
6185 } else if ( type === 'object' ) {
62- if ( 'properties' in property && property . properties ) {
63- extraNode = (
64- < div className = "my-4" >
65- < em > Properties:</ em >
66- < OpenAPIProperties
67- properties = { property . properties }
68- openapi = { openapi }
69- />
70- </ div >
71- )
86+ if ( prop$Ref ) {
87+ typeNode = < RefLink $ref = { prop$Ref } />
7288 }
89+
7390 if ( typeof propObj . additionalProperties === 'object' ) {
7491 const props = propObj . additionalProperties
75- const propsObj = '$ref' in props ? resolveRef ( openapi , props . $ref ) : props
92+ const props$Ref = get$Ref ( props )
93+ const propsObj = props$Ref
94+ ? resolveRef ( openapi , props$Ref )
95+ : ( props as OpenAPIV3_1 . SchemaObject )
7696 const propsType = propsObj . type
7797 typeNode = (
78- < code >
79- map[string]
80- { typeof propsType === 'string'
81- ? propsType
82- : '$ref' in props && < RefLink $ref = { props . $ref } /> }
83- </ code >
98+ < >
99+ { typeNode }
100+ < code >
101+ map[string]
102+ { typeof propsType === 'string'
103+ ? propsType
104+ : props$Ref && < RefLink $ref = { props$Ref } /> }
105+ </ code >
106+ </ >
84107 )
85- } else {
108+
109+ if ( 'properties' in property && property . properties ) {
110+ extraNode = (
111+ < div className = "my-4" >
112+ < em > Properties:</ em >
113+ < OpenAPIProperties
114+ properties = { property . properties }
115+ openapi = { openapi }
116+ />
117+ </ div >
118+ )
119+ }
120+ } else if ( ! prop$Ref ) {
86121 typeNode = < code > { type } </ code >
87122 }
88123 } else if ( typeof type === 'string' ) {
89124 typeNode = < code > { type } </ code >
90- } else if ( '$ref' in property ) {
91- typeNode = < RefLink $ref = { property . $ref } />
125+ } else if ( prop$Ref ) {
126+ typeNode = < RefLink $ref = { prop$Ref } />
92127 }
128+
93129 return (
94130 < >
95131 { name && (
0 commit comments