55 * LICENSE file in the root directory of this source tree.
66 * ========================================================================== */
77
8- import { Map , MediaTypeObject , SchemaObject } from "../types" ;
8+ import { MediaTypeObject , SchemaObject } from "../openapi /types" ;
99import { createDescription } from "./createDescription" ;
1010import { createFullWidthTable } from "./createFullWidthTable" ;
1111import { getSchemaName } from "./schema" ;
@@ -64,11 +64,13 @@ function createRows({ schema }: RowsProps): string | undefined {
6464 marginBottom : "0px" ,
6565 } ,
6666 children : create ( "tbody" , {
67- children : Object . keys ( schema . properties ) . map ( ( key ) =>
67+ children : Object . entries ( schema . properties ) . map ( ( [ key , val ] ) =>
6868 createRow ( {
6969 name : key ,
70- schema : schema . properties [ key ] ,
71- required : schema . required ?. includes ( key ) ,
70+ schema : val ,
71+ required : Array . isArray ( schema . required )
72+ ? schema . required . includes ( key )
73+ : false ,
7274 } )
7375 ) ,
7476 } ) ,
@@ -91,11 +93,13 @@ interface RowsRootProps {
9193function createRowsRoot ( { schema } : RowsRootProps ) {
9294 // object
9395 if ( schema . properties !== undefined ) {
94- return Object . keys ( schema . properties ) . map ( ( key ) =>
96+ return Object . entries ( schema . properties ) . map ( ( [ key , val ] ) =>
9597 createRow ( {
9698 name : key ,
97- schema : schema . properties [ key ] ,
98- required : schema . required ?. includes ( key ) ,
99+ schema : val ,
100+ required : Array . isArray ( schema . required )
101+ ? schema . required . includes ( key )
102+ : false ,
99103 } )
100104 ) ;
101105 }
@@ -128,7 +132,9 @@ interface Props {
128132 style ?: any ;
129133 title : string ;
130134 body : {
131- content : Map < MediaTypeObject > ;
135+ content : {
136+ [ key : string ] : MediaTypeObject ;
137+ } ;
132138 description ?: string ;
133139 required ?: boolean ;
134140 } ;
@@ -144,7 +150,11 @@ export function createSchemaTable({ title, body, ...rest }: Props) {
144150
145151 const randomFirstKey = Object . keys ( body . content ) [ 0 ] ;
146152
147- const firstBody = body . content [ randomFirstKey ] . schema as SchemaObject ;
153+ const firstBody = body . content [ randomFirstKey ] . schema ;
154+
155+ if ( firstBody === undefined ) {
156+ return undefined ;
157+ }
148158
149159 // we don't show the table if there is no properties to show
150160 if ( Object . keys ( firstBody . properties ?? { } ) . length === 0 ) {
0 commit comments