From 986f6e02f21d02d175aa1f237677eaaaf2ce8e93 Mon Sep 17 00:00:00 2001 From: Vladimir Gorej Date: Wed, 19 Apr 2023 20:20:34 +0200 Subject: [PATCH] feat(json-schema-2020-12): add support for anchor keyword Refs #8513 --- .../components/JSONSchema/JSONSchema.jsx | 2 ++ .../components/JSONSchema/_json-schema.scss | 4 +++ .../components/keywords/$anchor.jsx | 25 +++++++++++++++++++ .../components/keywords/$id.jsx | 2 +- .../components/keywords/$schema.jsx | 2 +- .../components/keywords/Format/_format.scss | 2 +- src/core/plugins/json-schema-2020-12/fn.js | 1 + src/core/plugins/json-schema-2020-12/hoc.jsx | 2 ++ src/core/plugins/json-schema-2020-12/index.js | 2 ++ .../plugins/oas31/wrap-components/models.jsx | 2 ++ 10 files changed, 41 insertions(+), 3 deletions(-) create mode 100644 src/core/plugins/json-schema-2020-12/components/keywords/$anchor.jsx diff --git a/src/core/plugins/json-schema-2020-12/components/JSONSchema/JSONSchema.jsx b/src/core/plugins/json-schema-2020-12/components/JSONSchema/JSONSchema.jsx index a4a5a116bac..9f35fb86b66 100644 --- a/src/core/plugins/json-schema-2020-12/components/JSONSchema/JSONSchema.jsx +++ b/src/core/plugins/json-schema-2020-12/components/JSONSchema/JSONSchema.jsx @@ -35,6 +35,7 @@ const JSONSchema = ({ schema, name }) => { const Keyword$schema = useComponent("Keyword$schema") const Keyword$vocabulary = useComponent("Keyword$vocabulary") const Keyword$id = useComponent("Keyword$id") + const Keyword$anchor = useComponent("Keyword$anchor") const KeywordProperties = useComponent("KeywordProperties") const KeywordType = useComponent("KeywordType") const KeywordFormat = useComponent("KeywordFormat") @@ -101,6 +102,7 @@ const JSONSchema = ({ schema, name }) => { + )} diff --git a/src/core/plugins/json-schema-2020-12/components/JSONSchema/_json-schema.scss b/src/core/plugins/json-schema-2020-12/components/JSONSchema/_json-schema.scss index 9bedb2e5dbd..bb9ffffe775 100644 --- a/src/core/plugins/json-schema-2020-12/components/JSONSchema/_json-schema.scss +++ b/src/core/plugins/json-schema-2020-12/components/JSONSchema/_json-schema.scss @@ -55,4 +55,8 @@ //} } +.json-schema-2020-12-core-keyword + .json-schema-2020-12-core-keyword__value::before { + content: '=' +} + diff --git a/src/core/plugins/json-schema-2020-12/components/keywords/$anchor.jsx b/src/core/plugins/json-schema-2020-12/components/keywords/$anchor.jsx new file mode 100644 index 00000000000..8bc3046eada --- /dev/null +++ b/src/core/plugins/json-schema-2020-12/components/keywords/$anchor.jsx @@ -0,0 +1,25 @@ +/** + * @prettier + */ +import React from "react" + +import { schema } from "../../prop-types" + +const $anchor = ({ schema }) => { + if (!schema?.$anchor) return null + + return ( +
+ $anchor + + {schema.$anchor} + +
+ ) +} + +$anchor.propTypes = { + schema: schema.isRequired, +} + +export default $anchor diff --git a/src/core/plugins/json-schema-2020-12/components/keywords/$id.jsx b/src/core/plugins/json-schema-2020-12/components/keywords/$id.jsx index 4b49a818f55..fb701fc0ed6 100644 --- a/src/core/plugins/json-schema-2020-12/components/keywords/$id.jsx +++ b/src/core/plugins/json-schema-2020-12/components/keywords/$id.jsx @@ -12,7 +12,7 @@ const $id = ({ schema }) => {
$id - ={schema.$id} + {schema.$id}
) diff --git a/src/core/plugins/json-schema-2020-12/components/keywords/$schema.jsx b/src/core/plugins/json-schema-2020-12/components/keywords/$schema.jsx index 7aefa5accc0..b0b419a9537 100644 --- a/src/core/plugins/json-schema-2020-12/components/keywords/$schema.jsx +++ b/src/core/plugins/json-schema-2020-12/components/keywords/$schema.jsx @@ -12,7 +12,7 @@ const $schema = ({ schema }) => {
$schema - ={schema.$schema} + {schema.$schema}
) diff --git a/src/core/plugins/json-schema-2020-12/components/keywords/Format/_format.scss b/src/core/plugins/json-schema-2020-12/components/keywords/Format/_format.scss index 027a27c4d74..0dc12cfbcc2 100644 --- a/src/core/plugins/json-schema-2020-12/components/keywords/Format/_format.scss +++ b/src/core/plugins/json-schema-2020-12/components/keywords/Format/_format.scss @@ -8,7 +8,7 @@ border-radius: 4px; text-transform: lowercase; - &:before { + &::before { content: "format: "; } } diff --git a/src/core/plugins/json-schema-2020-12/fn.js b/src/core/plugins/json-schema-2020-12/fn.js index 191e264e3a9..223e4dfcb1a 100644 --- a/src/core/plugins/json-schema-2020-12/fn.js +++ b/src/core/plugins/json-schema-2020-12/fn.js @@ -116,6 +116,7 @@ export const isExpandable = (schema) => { schema?.$schema || schema?.$vocabulary || schema?.$id || + schema?.$anchor || schema?.description || schema?.properties ) diff --git a/src/core/plugins/json-schema-2020-12/hoc.jsx b/src/core/plugins/json-schema-2020-12/hoc.jsx index 0c0299faff3..19cb7bd3e8d 100644 --- a/src/core/plugins/json-schema-2020-12/hoc.jsx +++ b/src/core/plugins/json-schema-2020-12/hoc.jsx @@ -7,6 +7,7 @@ import JSONSchema from "./components/JSONSchema/JSONSchema" import Keyword$schema from "./components/keywords/$schema" import Keyword$vocabulary from "./components/keywords/$vocabulary/$vocabulary" import Keyword$id from "./components/keywords/$id" +import Keyword$anchor from "./components/keywords/$anchor" import KeywordProperties from "./components/keywords/Properties" import KeywordType from "./components/keywords/Type/Type" import KeywordFormat from "./components/keywords/Format/Format" @@ -31,6 +32,7 @@ export const withJSONSchemaContext = (Component, overrides = {}) => { Keyword$schema, Keyword$vocabulary, Keyword$id, + Keyword$anchor, KeywordProperties, KeywordType, KeywordFormat, diff --git a/src/core/plugins/json-schema-2020-12/index.js b/src/core/plugins/json-schema-2020-12/index.js index 8bef0c2aee8..a5c7c9508f3 100644 --- a/src/core/plugins/json-schema-2020-12/index.js +++ b/src/core/plugins/json-schema-2020-12/index.js @@ -6,6 +6,7 @@ import KeywordProperties from "./components/keywords/Properties" import Keyword$schema from "./components/keywords/$schema" import Keyword$vocabulary from "./components/keywords/$vocabulary/$vocabulary" import Keyword$id from "./components/keywords/$id" +import Keyword$anchor from "./components/keywords/$anchor" import KeywordType from "./components/keywords/Type/Type" import KeywordFormat from "./components/keywords/Format/Format" import KeywordTitle from "./components/keywords/Title/Title" @@ -22,6 +23,7 @@ const JSONSchema202012Plugin = () => ({ JSONSchema202012Keyword$schema: Keyword$schema, JSONSchema202012Keyword$vocabulary: Keyword$vocabulary, JSONSchema202012Keyword$id: Keyword$id, + JSONSchema202012Keyword$anchor: Keyword$anchor, JSONSchema202012KeywordProperties: KeywordProperties, JSONSchema202012KeywordType: KeywordType, JSONSchema202012KeywordFormat: KeywordFormat, diff --git a/src/core/plugins/oas31/wrap-components/models.jsx b/src/core/plugins/oas31/wrap-components/models.jsx index 5f560e50d56..1e7008f7cc0 100644 --- a/src/core/plugins/oas31/wrap-components/models.jsx +++ b/src/core/plugins/oas31/wrap-components/models.jsx @@ -12,6 +12,7 @@ const ModelsWrapper = createOnlyOAS31ComponentWrapper(({ getSystem }) => { const Keyword$schema = getComponent("JSONSchema202012Keyword$schema") const Keyword$vocabulary = getComponent("JSONSchema202012Keyword$vocabulary") const Keyword$id = getComponent("JSONSchema202012Keyword$id") + const Keyword$anchor = getComponent("JSONSchema202012Keyword$anchor") const KeywordProperties = getComponent("JSONSchema202012KeywordProperties") const KeywordType = getComponent("JSONSchema202012KeywordType") const KeywordFormat = getComponent("JSONSchema202012KeywordFormat") @@ -34,6 +35,7 @@ const ModelsWrapper = createOnlyOAS31ComponentWrapper(({ getSystem }) => { Keyword$schema, Keyword$vocabulary, Keyword$id, + Keyword$anchor, KeywordProperties, KeywordType, KeywordFormat,