-
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 allOf keyword
Refs #8513
- Loading branch information
Showing
8 changed files
with
87 additions
and
1 deletion.
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
56 changes: 56 additions & 0 deletions
56
src/core/plugins/json-schema-2020-12/components/keywords/AllOf/AllOf.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,56 @@ | ||
/** | ||
* @prettier | ||
*/ | ||
import React, { useCallback, useState } from "react" | ||
|
||
import { schema } from "../../../prop-types" | ||
import { useFn, useComponent, useIsExpandedDeeply } from "../../../hooks" | ||
|
||
const AllOf = ({ schema }) => { | ||
const allOf = schema?.allOf || [] | ||
|
||
if (!Array.isArray(allOf) || allOf.length === 0) { | ||
return null | ||
} | ||
|
||
const fn = useFn() | ||
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__allOf"> | ||
<Accordion expanded={expanded} onChange={handleExpansion}> | ||
<span className="json-schema-2020-12-core-keyword json-schema-2020-12-core-keyword--allOf"> | ||
AllOf | ||
</span> | ||
<span className="json-schema-2020-12__type"> | ||
{fn.getType({ allOf })} | ||
</span> | ||
</Accordion> | ||
{expanded && ( | ||
<ul> | ||
{allOf.map((schema, index) => ( | ||
<li key={`#${index}`} className="json-schema-2020-12-property"> | ||
<JSONSchema | ||
name={`#${index} ${fn.getTitle(schema)}`} | ||
schema={schema} | ||
/> | ||
</li> | ||
))} | ||
</ul> | ||
)} | ||
</div> | ||
) | ||
} | ||
|
||
AllOf.propTypes = { | ||
schema: schema.isRequired, | ||
} | ||
|
||
export default AllOf |
18 changes: 18 additions & 0 deletions
18
src/core/plugins/json-schema-2020-12/components/keywords/AllOf/_all-of.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,18 @@ | ||
.json-schema-2020-12 { | ||
&__allOf { | ||
& ul { | ||
padding: 0; | ||
margin: 0 0 0 20px; | ||
border-left: 1px dashed rgba($section-models-model-container-background-color, 0.1); | ||
} | ||
} | ||
|
||
&-core-keyword { | ||
&--allOf { | ||
color: $text-code-default-font-color; | ||
font-style: normal; | ||
} | ||
} | ||
} | ||
|
||
|
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