-
Notifications
You must be signed in to change notification settings - Fork 9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(json-schema-2020-12): add support for dependentSchemas keyword
Refs #8513
- Loading branch information
Showing
11 changed files
with
77 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
...ore/plugins/json-schema-2020-12/components/keywords/DependentSchemas/DependentSchemas.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/** | ||
* @prettier | ||
*/ | ||
import React, { useCallback, useState } from "react" | ||
|
||
import { schema } from "../../../prop-types" | ||
import { useComponent, useIsExpandedDeeply } from "../../../hooks" | ||
|
||
const DependentSchemas = ({ schema }) => { | ||
const dependentSchemas = schema?.dependentSchemas || [] | ||
|
||
if (typeof dependentSchemas !== "object") return null | ||
if (Object.keys(dependentSchemas).length === 0) return null | ||
|
||
const isExpandedDeeply = useIsExpandedDeeply() | ||
const [expanded, setExpanded] = useState(isExpandedDeeply) | ||
const Accordion = useComponent("Accordion") | ||
const JSONSchema = useComponent("JSONSchema") | ||
|
||
const handleExpansion = useCallback(() => { | ||
setExpanded((prev) => !prev) | ||
}, []) | ||
|
||
return ( | ||
<div className="json-schema-2020-12__dependentSchemas"> | ||
<Accordion expanded={expanded} onChange={handleExpansion}> | ||
<span className="json-schema-2020-12-core-keyword json-schema-2020-12-core-keyword--dependentSchemas"> | ||
Dependent schemas | ||
</span> | ||
<span className="json-schema-2020-12__type">object</span> | ||
</Accordion> | ||
{expanded && ( | ||
<ul> | ||
{Object.entries(dependentSchemas).map(([schemaName, schema]) => ( | ||
<li key={schemaName} className="json-schema-2020-12-property"> | ||
<JSONSchema name={schemaName} schema={schema} /> | ||
</li> | ||
))} | ||
</ul> | ||
)} | ||
</div> | ||
) | ||
} | ||
|
||
DependentSchemas.propTypes = { | ||
schema: schema.isRequired, | ||
} | ||
|
||
export default DependentSchemas |
13 changes: 13 additions & 0 deletions
13
.../plugins/json-schema-2020-12/components/keywords/DependentSchemas/_dependent-schemas.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
.json-schema-2020-12 { | ||
&__dependentSchemas { | ||
@extend .json-schema-2020-12__allOf; | ||
} | ||
|
||
&-core-keyword { | ||
&--dependentSchemas { | ||
@extend .json-schema-2020-12-core-keyword--allOf; | ||
} | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters