feat(json-schema-2020-12): add support for patternProperties keyword

Refs #8513
This commit is contained in:
Vladimir Gorej
2023-04-24 15:10:55 +02:00
committed by Vladimír Gorej
parent 31a1fed11e
commit a9dc6b0b05
10 changed files with 90 additions and 14 deletions

View File

@@ -53,6 +53,7 @@ const JSONSchema = ({ schema, name }) => {
const KeywordItems = useComponent("KeywordItems") const KeywordItems = useComponent("KeywordItems")
const KeywordContains = useComponent("KeywordContains") const KeywordContains = useComponent("KeywordContains")
const KeywordProperties = useComponent("KeywordProperties") const KeywordProperties = useComponent("KeywordProperties")
const KeywordPatternProperties = useComponent("KeywordPatternProperties")
const KeywordType = useComponent("KeywordType") const KeywordType = useComponent("KeywordType")
const KeywordFormat = useComponent("KeywordFormat") const KeywordFormat = useComponent("KeywordFormat")
const KeywordTitle = useComponent("KeywordTitle") const KeywordTitle = useComponent("KeywordTitle")
@@ -114,7 +115,10 @@ const JSONSchema = ({ schema, name }) => {
<div className="json-schema-2020-12-body"> <div className="json-schema-2020-12-body">
<KeywordDescription schema={schema} /> <KeywordDescription schema={schema} />
{!isCircular && isExpandable && ( {!isCircular && isExpandable && (
<KeywordProperties schema={schema} /> <>
<KeywordProperties schema={schema} />
<KeywordPatternProperties schema={schema} />
</>
)} )}
<KeywordAllOf schema={schema} /> <KeywordAllOf schema={schema} />
<KeywordAnyOf schema={schema} /> <KeywordAnyOf schema={schema} />

View File

@@ -0,0 +1,38 @@
/**
* @prettier
*/
import React from "react"
import { schema } from "../../../prop-types"
import { useComponent } from "../../../hooks"
const PatternProperties = ({ schema }) => {
const patternProperties = schema?.patternProperties || {}
if (Object.keys(patternProperties).length === 0) {
return null
}
const JSONSchema = useComponent("JSONSchema")
return (
<div className="json-schema-2020-12-keyword json-schema-2020-12-keyword--patternProperties">
<ul>
{Object.entries(patternProperties).map(([propertyName, schema]) => (
<li
key={propertyName}
className="json-schema-2020-12-property json-schema-2020-12-property"
>
<JSONSchema name={propertyName} schema={schema} />
</li>
))}
</ul>
</div>
)
}
PatternProperties.propTypes = {
schema: schema.isRequired,
}
export default PatternProperties

View File

@@ -0,0 +1,19 @@
.json-schema-2020-12 {
&-keyword--patternProperties {
ul {
margin: 0;
padding: 0;
border: none;
}
.json-schema-2020-12__title:first-of-type::before {
color: $prop-type-font-color;
content: "/";
}
.json-schema-2020-12__title:first-of-type::after {
color: $prop-type-font-color;
content: "/";
}
}
}

View File

@@ -16,13 +16,15 @@ const Properties = ({ schema }) => {
const JSONSchema = useComponent("JSONSchema") const JSONSchema = useComponent("JSONSchema")
return ( return (
<ul className="json-schema-2020-12__properties"> <div className="json-schema-2020-12-keyword json-schema-2020-12-keyword--properties">
{Object.entries(properties).map(([propertyName, schema]) => ( <ul>
<li key={propertyName} className="json-schema-2020-12-property"> {Object.entries(properties).map(([propertyName, schema]) => (
<JSONSchema name={propertyName} schema={schema} /> <li key={propertyName} className="json-schema-2020-12-property">
</li> <JSONSchema name={propertyName} schema={schema} />
))} </li>
</ul> ))}
</ul>
</div>
) )
} }

View File

@@ -1,7 +1,10 @@
.json-schema-2020-12 { .json-schema-2020-12 {
&__properties { &-keyword--properties {
margin: 0; ul {
padding: 0; margin: 0;
padding: 0;
border: none;
}
} }
&-property { &-property {

View File

@@ -49,3 +49,4 @@
@import './Description/description'; @import './Description/description';
@import './Title/title'; @import './Title/title';
@import './Properties/properties'; @import './Properties/properties';
@import './PatternProperties/pattern-properties';

View File

@@ -144,7 +144,8 @@ export const isExpandable = (schema) => {
schema?.prefixItems || schema?.prefixItems ||
schema?.items || schema?.items ||
schema?.contains || schema?.contains ||
schema?.description || schema?.properties ||
schema?.properties schema?.patternProperties ||
schema?.description
) )
} }

View File

@@ -25,6 +25,7 @@ import KeywordPrefixItems from "./components/keywords/PrefixItems"
import KeywordItems from "./components/keywords/Items" import KeywordItems from "./components/keywords/Items"
import KeywordContains from "./components/keywords/Contains" import KeywordContains from "./components/keywords/Contains"
import KeywordProperties from "./components/keywords/Properties/Properties" import KeywordProperties from "./components/keywords/Properties/Properties"
import KeywordPatternProperties from "./components/keywords/PatternProperties/PatternProperties"
import KeywordType from "./components/keywords/Type/Type" import KeywordType from "./components/keywords/Type/Type"
import KeywordFormat from "./components/keywords/Format/Format" import KeywordFormat from "./components/keywords/Format/Format"
import KeywordTitle from "./components/keywords/Title/Title" import KeywordTitle from "./components/keywords/Title/Title"
@@ -66,6 +67,7 @@ export const withJSONSchemaContext = (Component, overrides = {}) => {
KeywordItems, KeywordItems,
KeywordContains, KeywordContains,
KeywordProperties, KeywordProperties,
KeywordPatternProperties,
KeywordType, KeywordType,
KeywordFormat, KeywordFormat,
KeywordTitle, KeywordTitle,

View File

@@ -2,7 +2,6 @@
* @prettier * @prettier
*/ */
import JSONSchema from "./components/JSONSchema/JSONSchema" import JSONSchema from "./components/JSONSchema/JSONSchema"
import KeywordProperties from "./components/keywords/Properties/Properties"
import Keyword$schema from "./components/keywords/$schema" import Keyword$schema from "./components/keywords/$schema"
import Keyword$vocabulary from "./components/keywords/$vocabulary/$vocabulary" import Keyword$vocabulary from "./components/keywords/$vocabulary/$vocabulary"
import Keyword$id from "./components/keywords/$id" import Keyword$id from "./components/keywords/$id"
@@ -23,6 +22,8 @@ import KeywordDependentSchemas from "./components/keywords/DependentSchemas"
import KeywordPrefixItems from "./components/keywords/PrefixItems" import KeywordPrefixItems from "./components/keywords/PrefixItems"
import KeywordItems from "./components/keywords/Items" import KeywordItems from "./components/keywords/Items"
import KeywordContains from "./components/keywords/Contains" import KeywordContains from "./components/keywords/Contains"
import KeywordProperties from "./components/keywords/Properties/Properties"
import KeywordPatternProperties from "./components/keywords/PatternProperties/PatternProperties"
import KeywordType from "./components/keywords/Type/Type" import KeywordType from "./components/keywords/Type/Type"
import KeywordFormat from "./components/keywords/Format/Format" import KeywordFormat from "./components/keywords/Format/Format"
import KeywordTitle from "./components/keywords/Title/Title" import KeywordTitle from "./components/keywords/Title/Title"
@@ -57,6 +58,7 @@ const JSONSchema202012Plugin = () => ({
JSONSchema202012KeywordItems: KeywordItems, JSONSchema202012KeywordItems: KeywordItems,
JSONSchema202012KeywordContains: KeywordContains, JSONSchema202012KeywordContains: KeywordContains,
JSONSchema202012KeywordProperties: KeywordProperties, JSONSchema202012KeywordProperties: KeywordProperties,
JSONSchema202012KeywordPatternProperties: KeywordPatternProperties,
JSONSchema202012KeywordType: KeywordType, JSONSchema202012KeywordType: KeywordType,
JSONSchema202012KeywordFormat: KeywordFormat, JSONSchema202012KeywordFormat: KeywordFormat,
JSONSchema202012KeywordTitle: KeywordTitle, JSONSchema202012KeywordTitle: KeywordTitle,

View File

@@ -34,6 +34,9 @@ const ModelsWrapper = createOnlyOAS31ComponentWrapper(({ getSystem }) => {
const KeywordItems = getComponent("JSONSchema202012KeywordItems") const KeywordItems = getComponent("JSONSchema202012KeywordItems")
const KeywordContains = getComponent("JSONSchema202012KeywordContains") const KeywordContains = getComponent("JSONSchema202012KeywordContains")
const KeywordProperties = getComponent("JSONSchema202012KeywordProperties") const KeywordProperties = getComponent("JSONSchema202012KeywordProperties")
const KeywordPatternProperties = getComponent(
"JSONSchema202012KeywordPatternProperties"
)
const KeywordType = getComponent("JSONSchema202012KeywordType") const KeywordType = getComponent("JSONSchema202012KeywordType")
const KeywordFormat = getComponent("JSONSchema202012KeywordFormat") const KeywordFormat = getComponent("JSONSchema202012KeywordFormat")
const KeywordTitle = getComponent("JSONSchema202012KeywordTitle") const KeywordTitle = getComponent("JSONSchema202012KeywordTitle")
@@ -73,6 +76,7 @@ const ModelsWrapper = createOnlyOAS31ComponentWrapper(({ getSystem }) => {
KeywordItems, KeywordItems,
KeywordContains, KeywordContains,
KeywordProperties, KeywordProperties,
KeywordPatternProperties,
KeywordType, KeywordType,
KeywordFormat, KeywordFormat,
KeywordTitle, KeywordTitle,