Skip to content

Commit

Permalink
feat(json-schema-2020-12): add support for writeOnly keyword (#8650)
Browse files Browse the repository at this point in the history
Refs #8513
  • Loading branch information
char0n committed May 11, 2023
1 parent 964a11a commit d7b489c
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ const JSONSchema = forwardRef(
const KeywordDefault = useComponent("KeywordDefault")
const KeywordDeprecated = useComponent("KeywordDeprecated")
const KeywordReadOnly = useComponent("KeywordReadOnly")
const KeywordWriteOnly = useComponent("KeywordWriteOnly")
const ExpandDeepButton = useComponent("ExpandDeepButton")

/**
Expand Down Expand Up @@ -136,6 +137,7 @@ const JSONSchema = forwardRef(
)}
<KeywordDeprecated schema={schema} />
<KeywordReadOnly schema={schema} />
<KeywordWriteOnly schema={schema} />
<KeywordType schema={schema} isCircular={isCircular} />
{constraints.length > 0 &&
constraints.map((constraint) => (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { schema } from "../../../prop-types"
const ReadOnly = ({ schema }) => {
if (schema?.readOnly !== true) return null

return <span className="json-schema-2020-12__readonly">read-only</span>
return <span className="json-schema-2020-12__readOnly">read-only</span>
}

ReadOnly.propTypes = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.json-schema-2020-12 {
&__readonly {
&__readOnly {
@extend .json-schema-2020-12__deprecated;
color: gray;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* @prettier
*/
import React from "react"

import { schema } from "../../../prop-types"

const WriteOnly = ({ schema }) => {
if (schema?.writeOnly !== true) return null

return <span className="json-schema-2020-12__writeOnly">write-only</span>
}

WriteOnly.propTypes = {
schema: schema.isRequired,
}

export default WriteOnly
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.json-schema-2020-12 {
&__writeOnly {
@extend .json-schema-2020-12__readOnly;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,4 @@
@import './DependentRequired/dependent-required';
@import './Deprecated/deprecated';
@import './ReadOnly/read-only';
@import './WriteOnly/write-only';
2 changes: 2 additions & 0 deletions src/core/plugins/json-schema-2020-12/hoc.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import KeywordDescription from "./components/keywords/Description/Description"
import KeywordDefault from "./components/keywords/Default"
import KeywordDeprecated from "./components/keywords/Deprecated/Deprecated"
import KeywordReadOnly from "./components/keywords/ReadOnly/ReadOnly"
import KeywordWriteOnly from "./components/keywords/WriteOnly/WriteOnly"
import Accordion from "./components/Accordion/Accordion"
import ExpandDeepButton from "./components/ExpandDeepButton/ExpandDeepButton"
import ChevronRightIcon from "./components/icons/ChevronRight"
Expand Down Expand Up @@ -98,6 +99,7 @@ export const withJSONSchemaContext = (Component, overrides = {}) => {
KeywordDefault,
KeywordDeprecated,
KeywordReadOnly,
KeywordWriteOnly,
Accordion,
ExpandDeepButton,
ChevronRightIcon,
Expand Down
2 changes: 2 additions & 0 deletions src/core/plugins/json-schema-2020-12/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import KeywordDescription from "./components/keywords/Description/Description"
import KeywordDefault from "./components/keywords/Default"
import KeywordDeprecated from "./components/keywords/Deprecated/Deprecated"
import KeywordReadOnly from "./components/keywords/ReadOnly/ReadOnly"
import KeywordWriteOnly from "./components/keywords/WriteOnly/WriteOnly"
import Accordion from "./components/Accordion/Accordion"
import ExpandDeepButton from "./components/ExpandDeepButton/ExpandDeepButton"
import ChevronRightIcon from "./components/icons/ChevronRight"
Expand Down Expand Up @@ -85,6 +86,7 @@ const JSONSchema202012Plugin = () => ({
JSONSchema202012KeywordDefault: KeywordDefault,
JSONSchema202012KeywordDeprecated: KeywordDeprecated,
JSONSchema202012KeywordReadOnly: KeywordReadOnly,
JSONSchema202012KeywordWriteOnly: KeywordWriteOnly,
JSONSchema202012Accordion: Accordion,
JSONSchema202012ExpandDeepButton: ExpandDeepButton,
JSONSchema202012ChevronRightIcon: ChevronRightIcon,
Expand Down
2 changes: 2 additions & 0 deletions src/core/plugins/oas31/wrap-components/models.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ const ModelsWrapper = createOnlyOAS31ComponentWrapper(({ getSystem }) => {
const KeywordDefault = getComponent("JSONSchema202012KeywordDefault")
const KeywordDeprecated = getComponent("JSONSchema202012KeywordDeprecated")
const KeywordReadOnly = getComponent("JSONSchema202012KeywordReadOnly")
const KeywordWriteOnly = getComponent("JSONSchema202012KeywordWriteOnly")
const Accordion = getComponent("JSONSchema202012Accordion")
const ExpandDeepButton = getComponent("JSONSchema202012ExpandDeepButton")
const ChevronRightIcon = getComponent("JSONSchema202012ChevronRightIcon")
Expand Down Expand Up @@ -122,6 +123,7 @@ const ModelsWrapper = createOnlyOAS31ComponentWrapper(({ getSystem }) => {
KeywordDefault,
KeywordDeprecated,
KeywordReadOnly,
KeywordWriteOnly,
Accordion,
ExpandDeepButton,
ChevronRightIcon,
Expand Down

0 comments on commit d7b489c

Please sign in to comment.