@@ -69,6 +69,29 @@ const renderProperties = (
6969 ) ) ;
7070} ;
7171
72+ const renderAdditionalProperties = (
73+ schema : Schema ,
74+ treeSpace : number ,
75+ ) : React . ReactNode => {
76+ const additionalProperties = schema . additionalProperties ;
77+
78+ if ( ! additionalProperties || typeof additionalProperties === 'boolean' ) {
79+ return null ;
80+ }
81+
82+ return (
83+ < div >
84+ < SchemaPropertiesComponent
85+ key = "property-name"
86+ name = "(property name)"
87+ hasDynamicName
88+ properties = { additionalProperties as Schema }
89+ treeSpace = { treeSpace }
90+ />
91+ </ div >
92+ ) ;
93+ } ;
94+
7295const renderOf = ( treeSpace : number , schemas ?: Schema [ ] ) : React . ReactNode => {
7396 if ( ! schemas ) {
7497 return null ;
@@ -90,6 +113,7 @@ const renderOf = (treeSpace: number, schemas?: Schema[]): React.ReactNode => {
90113
91114interface Props {
92115 name : string ;
116+ hasDynamicName ?: boolean ;
93117 properties : Schema ;
94118 treeSpace : number ;
95119 description ?: React . ReactNode ;
@@ -130,6 +154,7 @@ const renderPropertyDescription = (el: SchemaElement): React.ReactNode => {
130154
131155export const SchemaPropertiesComponent : React . FunctionComponent < Props > = ( {
132156 name,
157+ hasDynamicName = false ,
133158 properties,
134159 treeSpace,
135160} ) => {
@@ -146,7 +171,9 @@ export const SchemaPropertiesComponent: React.FunctionComponent<Props> = ({
146171 return (
147172 < div >
148173 < div className = "flex py-2" >
149- < div className = "flex-1" > { renderPropertyName ( element ) } </ div >
174+ < div className = { `flex-1 ${ hasDynamicName && 'font-italic' } ` } >
175+ { renderPropertyName ( element ) }
176+ </ div >
150177 < div className = "flex-1" >
151178 < span className = "capitalize text-sm text-teal font-bold" >
152179 { element . schema . content . type }
@@ -176,12 +203,124 @@ export const SchemaPropertiesComponent: React.FunctionComponent<Props> = ({
176203 must match { element . schema . content . pattern }
177204 </ span >
178205 ) }
206+ { element . schema . content . uniqueItems && (
207+ < span
208+ className = "bg-red-700 font-bold no-underline text-white rounded lowercase ml-2"
209+ style = { { height : '20px' , fontSize : '11px' , padding : '3px' } }
210+ >
211+ Unique
212+ </ span >
213+ ) }
214+ { element . schema . content . minItems && (
215+ < span
216+ className = "bg-purple-dark font-bold no-underline text-white rounded lowercase ml-2"
217+ style = { { height : '20px' , fontSize : '11px' , padding : '3px' } }
218+ title = { `At least ${ element . schema . content . minItems } items` }
219+ >
220+ >= { element . schema . content . minItems } items
221+ </ span >
222+ ) }
223+ { element . schema . content . maxItems && (
224+ < span
225+ className = "bg-purple-dark font-bold no-underline text-white rounded lowercase ml-2"
226+ style = { { height : '20px' , fontSize : '11px' , padding : '3px' } }
227+ title = { `At most ${ element . schema . content . maxItems } items` }
228+ >
229+ <= { element . schema . content . maxItems } items
230+ </ span >
231+ ) }
232+ { element . schema . content . minLength && (
233+ < span
234+ className = "bg-purple-dark font-bold no-underline text-white rounded lowercase ml-2"
235+ style = { { height : '20px' , fontSize : '11px' , padding : '3px' } }
236+ title = { `At least ${ element . schema . content . minLength } characters long` }
237+ >
238+ length >= { element . schema . content . minLength }
239+ </ span >
240+ ) }
241+ { element . schema . content . maxLength && (
242+ < span
243+ className = "bg-purple-dark font-bold no-underline text-white rounded lowercase ml-2"
244+ style = { { height : '20px' , fontSize : '11px' , padding : '3px' } }
245+ title = { `At most ${ element . schema . content . maxLength } characters long` }
246+ >
247+ length <= { element . schema . content . maxLength }
248+ </ span >
249+ ) }
250+ { element . schema . content . minimum && (
251+ < span
252+ className = "bg-purple-dark font-bold no-underline text-white rounded lowercase ml-2"
253+ style = { { height : '20px' , fontSize : '11px' , padding : '3px' } }
254+ title = { `At least ${ element . schema . content . minimum } ` }
255+ >
256+ >= { element . schema . content . minimum }
257+ </ span >
258+ ) }
259+ { element . schema . content . maximum && (
260+ < span
261+ className = "bg-purple-dark font-bold no-underline text-white rounded lowercase ml-2"
262+ style = { { height : '20px' , fontSize : '11px' , padding : '3px' } }
263+ title = { `At most ${ element . schema . content . maximum } ` }
264+ >
265+ <= { element . schema . content . maximum }
266+ </ span >
267+ ) }
268+ { element . schema . content . exclusiveMinimum && (
269+ < span
270+ className = "bg-purple-dark font-bold no-underline text-white rounded lowercase ml-2"
271+ style = { { height : '20px' , fontSize : '11px' , padding : '3px' } }
272+ title = { `Greater than ${ element . schema . content . exclusiveMinimum } ` }
273+ >
274+ > { element . schema . content . exclusiveMinimum }
275+ </ span >
276+ ) }
277+ { element . schema . content . exclusiveMaximum && (
278+ < span
279+ className = "bg-purple-dark font-bold no-underline text-white rounded lowercase ml-2"
280+ style = { { height : '20px' , fontSize : '11px' , padding : '3px' } }
281+ title = { `Less than ${ element . schema . content . exclusiveMaximum } ` }
282+ >
283+ < { element . schema . content . exclusiveMaximum }
284+ </ span >
285+ ) }
179286 < div className = "py-2" > { renderPropertyDescription ( element ) } </ div >
287+ { element . schema . content . type === 'object' && (
288+ < div className = "font-italic text-gray-600 text-sm" >
289+ { ( ! element . schema . content . additionalProperties ||
290+ typeof element . schema . content . additionalProperties ===
291+ 'boolean' ) && (
292+ < p className = "my-0" >
293+ Additional properties are{ ' ' }
294+ { element . schema . content . additionalProperties === false &&
295+ 'NOT' } { ' ' }
296+ allowed.
297+ </ p >
298+ ) }
299+ { element . schema . content . additionalProperties &&
300+ typeof element . schema . content . additionalProperties ===
301+ 'object' && (
302+ < p className = "my-0" >
303+ Additional properties must adhere to the following schema.
304+ </ p >
305+ ) }
306+ </ div >
307+ ) }
308+ { element . schema . content . items && (
309+ < div className = "font-italic text-gray-600 text-sm" >
310+ { element . schema . content . items &&
311+ typeof element . schema . content . items === 'object' && (
312+ < p className = "my-0" >
313+ Array items must adhere to the following schema.
314+ </ p >
315+ ) }
316+ </ div >
317+ ) }
180318 </ div >
181319 </ div >
182320 { renderOf ( space , alteredProperties . anyOf ) }
183321 { renderOf ( space , alteredProperties . oneOf ) }
184322 { renderProperties ( alteredProperties , space ) }
323+ { renderAdditionalProperties ( alteredProperties , space ) }
185324 { renderItems ( alteredProperties , space ) }
186325 </ div >
187326 ) ;
0 commit comments