feat(json-schema-2020-12): add support for required keyword (#8628)

Refs #8513
This commit is contained in:
Vladimír Gorej
2023-05-08 13:20:33 +02:00
committed by GitHub
parent 38ba00d15b
commit 03a561f1d9
2 changed files with 17 additions and 1 deletions

View File

@@ -2,12 +2,14 @@
* @prettier * @prettier
*/ */
import React from "react" import React from "react"
import classNames from "classnames"
import { schema } from "../../../prop-types" import { schema } from "../../../prop-types"
import { useComponent } from "../../../hooks" import { useComponent } from "../../../hooks"
const Properties = ({ schema }) => { const Properties = ({ schema }) => {
const properties = schema?.properties || {} const properties = schema?.properties || {}
const required = Array.isArray(schema?.required) ? schema.required : []
const JSONSchema = useComponent("JSONSchema") const JSONSchema = useComponent("JSONSchema")
/** /**
@@ -21,7 +23,13 @@ const Properties = ({ schema }) => {
<div className="json-schema-2020-12-keyword json-schema-2020-12-keyword--properties"> <div className="json-schema-2020-12-keyword json-schema-2020-12-keyword--properties">
<ul> <ul>
{Object.entries(properties).map(([propertyName, schema]) => ( {Object.entries(properties).map(([propertyName, schema]) => (
<li key={propertyName} className="json-schema-2020-12-property"> <li
key={propertyName}
className={classNames("json-schema-2020-12-property", {
"json-schema-2020-12-property--required":
required.includes(propertyName),
})}
>
<JSONSchema name={propertyName} schema={schema} /> <JSONSchema name={propertyName} schema={schema} />
</li> </li>
))} ))}

View File

@@ -9,5 +9,13 @@
&-property { &-property {
list-style-type: none; list-style-type: none;
&--required {
.json-schema-2020-12__title:after {
content: '*';
color: red;
font-weight: bold;
}
}
} }
} }