Skip to content

Commit

Permalink
feat(json-schema-2020-12): add support for comment keyword
Browse files Browse the repository at this point in the history
Refs #8513
  • Loading branch information
char0n committed Apr 26, 2023
1 parent daa0506 commit 2f08f64
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const JSONSchema = ({ schema, name }) => {
const Keyword$ref = useComponent("Keyword$ref")
const Keyword$dynamicRef = useComponent("Keyword$dynamicRef")
const Keyword$defs = useComponent("Keyword$defs")
const Keyword$comment = useComponent("Keyword$comment")
const KeywordProperties = useComponent("KeywordProperties")
const KeywordType = useComponent("KeywordType")
const KeywordFormat = useComponent("KeywordFormat")
Expand Down Expand Up @@ -111,6 +112,7 @@ const JSONSchema = ({ schema, name }) => {
<Keyword$ref schema={schema} />
<Keyword$dynamicRef schema={schema} />
<Keyword$defs schema={schema} />
<Keyword$comment schema={schema} />
</div>
)}
</article>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* @prettier
*/
import React from "react"

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

const $comment = ({ schema }) => {
if (!schema?.$comment) return null

return (
<div className="json-schema-2020-12__$comment">
<span className="json-schema-2020-12-core-keyword">$comment</span>
<span className="json-schema-2020-12-core-keyword__value">
{schema.$comment}
</span>
</div>
)
}

$comment.propTypes = {
schema: schema.isRequired,
}

export default $comment
1 change: 1 addition & 0 deletions src/core/plugins/json-schema-2020-12/fn.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ export const isExpandable = (schema) => {
schema?.$ref ||
schema?.$dynamicRef ||
schema?.$defs ||
schema?.$comment ||
schema?.description ||
schema?.properties
)
Expand Down
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 @@ -12,6 +12,7 @@ import Keyword$dynamicAnchor from "./components/keywords/$dynamicAnchor"
import Keyword$ref from "./components/keywords/$ref"
import Keyword$dynamicRef from "./components/keywords/$dynamicRef"
import Keyword$defs from "./components/keywords/$defs/$defs"
import Keyword$comment from "./components/keywords/$comment"
import KeywordProperties from "./components/keywords/Properties/Properties"
import KeywordType from "./components/keywords/Type/Type"
import KeywordFormat from "./components/keywords/Format/Format"
Expand Down Expand Up @@ -41,6 +42,7 @@ export const withJSONSchemaContext = (Component, overrides = {}) => {
Keyword$ref,
Keyword$dynamicRef,
Keyword$defs,
Keyword$comment,
KeywordProperties,
KeywordType,
KeywordFormat,
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 @@ -11,6 +11,7 @@ import Keyword$dynamicAnchor from "./components/keywords/$dynamicAnchor"
import Keyword$ref from "./components/keywords/$ref"
import Keyword$dynamicRef from "./components/keywords/$dynamicRef"
import Keyword$defs from "./components/keywords/$defs/$defs"
import Keyword$comment from "./components/keywords/$comment"
import KeywordType from "./components/keywords/Type/Type"
import KeywordFormat from "./components/keywords/Format/Format"
import KeywordTitle from "./components/keywords/Title/Title"
Expand All @@ -32,6 +33,7 @@ const JSONSchema202012Plugin = () => ({
JSONSchema202012Keyword$ref: Keyword$ref,
JSONSchema202012Keyword$dynamicRef: Keyword$dynamicRef,
JSONSchema202012Keyword$defs: Keyword$defs,
JSONSchema202012Keyword$comment: Keyword$comment,
JSONSchema202012KeywordProperties: KeywordProperties,
JSONSchema202012KeywordType: KeywordType,
JSONSchema202012KeywordFormat: KeywordFormat,
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 @@ -19,6 +19,7 @@ const ModelsWrapper = createOnlyOAS31ComponentWrapper(({ getSystem }) => {
const Keyword$ref = getComponent("JSONSchema202012Keyword$ref")
const Keyword$dynamicRef = getComponent("JSONSchema202012Keyword$dynamicRef")
const Keyword$defs = getComponent("JSONSchema202012Keyword$defs")
const Keyword$comment = getComponent("JSONSchema202012Keyword$comment")
const KeywordProperties = getComponent("JSONSchema202012KeywordProperties")
const KeywordType = getComponent("JSONSchema202012KeywordType")
const KeywordFormat = getComponent("JSONSchema202012KeywordFormat")
Expand Down Expand Up @@ -46,6 +47,7 @@ const ModelsWrapper = createOnlyOAS31ComponentWrapper(({ getSystem }) => {
Keyword$ref,
Keyword$dynamicRef,
Keyword$defs,
Keyword$comment,
KeywordProperties,
KeywordType,
KeywordFormat,
Expand Down

0 comments on commit 2f08f64

Please sign in to comment.