From 79e0c4e096d8cb69cd1c21a4fec8ab9790076b57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Gorej?= Date: Mon, 15 May 2023 14:20:59 +0200 Subject: [PATCH] feat(oas31): prepare to render JSON Schema 2020-12 in Operations and Webhooks (#8670) Refs #8513 --- src/core/plugins/oas31/index.js | 4 + .../components/keywords/Description.jsx | 2 +- .../keywords/Discriminator/Discriminator.jsx | 2 +- .../components/keywords/Example.jsx | 2 +- .../components/keywords/ExternalDocs.jsx | 2 +- .../components/keywords/Xml.jsx | 2 +- .../plugins/oas31/wrap-components/models.jsx | 10 +- .../oas31/wrap-components/operations.jsx | 147 ++++++++++++++++++ .../oas31/wrap-components/webhooks.jsx | 141 +++++++++++++++++ 9 files changed, 302 insertions(+), 10 deletions(-) create mode 100644 src/core/plugins/oas31/wrap-components/operations.jsx create mode 100644 src/core/plugins/oas31/wrap-components/webhooks.jsx diff --git a/src/core/plugins/oas31/index.js b/src/core/plugins/oas31/index.js index e2f6bc0303d..3a25dfab591 100644 --- a/src/core/plugins/oas31/index.js +++ b/src/core/plugins/oas31/index.js @@ -12,6 +12,8 @@ import LicenseWrapper from "./wrap-components/license" import ContactWrapper from "./wrap-components/contact" import InfoWrapper from "./wrap-components/info" import ModelsWrapper from "./wrap-components/models" +import OperationsWrapper from "./wrap-components/operations" +import WebhooksWrapper from "./wrap-components/webhooks" import VersionPragmaFilterWrapper from "./wrap-components/version-pragma-filter" import VersionStampWrapper from "./wrap-components/version-stamp" import { @@ -98,6 +100,8 @@ const OAS31Plugin = ({ getSystem }) => { VersionPragmaFilter: VersionPragmaFilterWrapper, VersionStamp: VersionStampWrapper, Models: ModelsWrapper, + Operations: OperationsWrapper, + Webhooks: WebhooksWrapper, JSONSchema202012KeywordDescription: JSONSchema202012KeywordDescriptionWrapper, JSONSchema202012KeywordDefault: JSONSchema202012KeywordDefaultWrapper, diff --git a/src/core/plugins/oas31/json-schema-2020-12-extensions/components/keywords/Description.jsx b/src/core/plugins/oas31/json-schema-2020-12-extensions/components/keywords/Description.jsx index bc00d2690bc..36c171a4eac 100644 --- a/src/core/plugins/oas31/json-schema-2020-12-extensions/components/keywords/Description.jsx +++ b/src/core/plugins/oas31/json-schema-2020-12-extensions/components/keywords/Description.jsx @@ -20,7 +20,7 @@ const Description = ({ schema, getSystem }) => { } Description.propTypes = { - schema: PropTypes.oneOfType([PropTypes.object, PropTypes.bool]), + schema: PropTypes.oneOfType([PropTypes.object, PropTypes.bool]).isRequired, getSystem: PropTypes.func.isRequired, } diff --git a/src/core/plugins/oas31/json-schema-2020-12-extensions/components/keywords/Discriminator/Discriminator.jsx b/src/core/plugins/oas31/json-schema-2020-12-extensions/components/keywords/Discriminator/Discriminator.jsx index 7cf2270f7db..c848d082c9a 100644 --- a/src/core/plugins/oas31/json-schema-2020-12-extensions/components/keywords/Discriminator/Discriminator.jsx +++ b/src/core/plugins/oas31/json-schema-2020-12-extensions/components/keywords/Discriminator/Discriminator.jsx @@ -85,7 +85,7 @@ const Discriminator = ({ schema, getSystem }) => { } Discriminator.propTypes = { - schema: PropTypes.oneOfType([PropTypes.object, PropTypes.bool]), + schema: PropTypes.oneOfType([PropTypes.object, PropTypes.bool]).isRequired, getSystem: PropTypes.func.isRequired, } diff --git a/src/core/plugins/oas31/json-schema-2020-12-extensions/components/keywords/Example.jsx b/src/core/plugins/oas31/json-schema-2020-12-extensions/components/keywords/Example.jsx index 9cc126f60c0..67d96e17423 100644 --- a/src/core/plugins/oas31/json-schema-2020-12-extensions/components/keywords/Example.jsx +++ b/src/core/plugins/oas31/json-schema-2020-12-extensions/components/keywords/Example.jsx @@ -23,7 +23,7 @@ const Example = ({ schema, getSystem }) => { } Example.propTypes = { - schema: PropTypes.oneOfType([PropTypes.object, PropTypes.bool]), + schema: PropTypes.oneOfType([PropTypes.object, PropTypes.bool]).isRequired, getSystem: PropTypes.func.isRequired, } diff --git a/src/core/plugins/oas31/json-schema-2020-12-extensions/components/keywords/ExternalDocs.jsx b/src/core/plugins/oas31/json-schema-2020-12-extensions/components/keywords/ExternalDocs.jsx index 0308f2ec528..443bc51261f 100644 --- a/src/core/plugins/oas31/json-schema-2020-12-extensions/components/keywords/ExternalDocs.jsx +++ b/src/core/plugins/oas31/json-schema-2020-12-extensions/components/keywords/ExternalDocs.jsx @@ -106,7 +106,7 @@ const ExternalDocs = ({ schema, getSystem }) => { } ExternalDocs.propTypes = { - schema: PropTypes.oneOfType([PropTypes.object, PropTypes.bool]), + schema: PropTypes.oneOfType([PropTypes.object, PropTypes.bool]).isRequired, getSystem: PropTypes.func.isRequired, } diff --git a/src/core/plugins/oas31/json-schema-2020-12-extensions/components/keywords/Xml.jsx b/src/core/plugins/oas31/json-schema-2020-12-extensions/components/keywords/Xml.jsx index 2ddba20ee9c..90d1d736d2b 100644 --- a/src/core/plugins/oas31/json-schema-2020-12-extensions/components/keywords/Xml.jsx +++ b/src/core/plugins/oas31/json-schema-2020-12-extensions/components/keywords/Xml.jsx @@ -124,7 +124,7 @@ const Xml = ({ schema, getSystem }) => { } Xml.propTypes = { - schema: PropTypes.oneOfType([PropTypes.object, PropTypes.bool]), + schema: PropTypes.oneOfType([PropTypes.object, PropTypes.bool]).isRequired, getSystem: PropTypes.func.isRequired, } diff --git a/src/core/plugins/oas31/wrap-components/models.jsx b/src/core/plugins/oas31/wrap-components/models.jsx index 7577b65d749..c5b939c03b2 100644 --- a/src/core/plugins/oas31/wrap-components/models.jsx +++ b/src/core/plugins/oas31/wrap-components/models.jsx @@ -11,8 +11,8 @@ const ModelsWrapper = createOnlyOAS31ComponentWrapper(({ getSystem }) => { const { getComponent, fn, getConfigs } = system const configs = getConfigs() - if (ModelsWrapper.ModelsWithJSONContext) { - return + if (ModelsWrapper.ModelsWithJSONSchemaContext) { + return } const Models = getComponent("OAS31Models", true) @@ -78,7 +78,7 @@ const ModelsWrapper = createOnlyOAS31ComponentWrapper(({ getSystem }) => { const ChevronRightIcon = getComponent("JSONSchema202012ChevronRightIcon") const withSchemaContext = getComponent("withJSONSchema202012Context") - ModelsWrapper.ModelsWithJSONContext = withSchemaContext(Models, { + ModelsWrapper.ModelsWithJSONSchemaContext = withSchemaContext(Models, { config: { default$schema: "https://spec.openapis.org/oas/3.1/dialect/base", defaultExpandedLevels: configs.defaultModelsExpandDepth - 1, @@ -133,9 +133,9 @@ const ModelsWrapper = createOnlyOAS31ComponentWrapper(({ getSystem }) => { }, }) - return + return }) -ModelsWrapper.ModelsWithJSONContext = null +ModelsWrapper.ModelsWithJSONSchemaContext = null export default ModelsWrapper diff --git a/src/core/plugins/oas31/wrap-components/operations.jsx b/src/core/plugins/oas31/wrap-components/operations.jsx new file mode 100644 index 00000000000..5708a0567ba --- /dev/null +++ b/src/core/plugins/oas31/wrap-components/operations.jsx @@ -0,0 +1,147 @@ +/** + * @prettier + */ +import React from "react" + +import { createOnlyOAS31ComponentWrapper } from "../fn" +import { makeIsExpandable } from "../json-schema-2020-12-extensions/fn" + +const OperationsWrapper = createOnlyOAS31ComponentWrapper(({ getSystem }) => { + const system = getSystem() + const { getComponent, fn, getConfigs } = system + const configs = getConfigs() + + if (OperationsWrapper.OperationsWithJSONSchemaContext) { + return + } + + const Operations = getComponent("operations", true) + const JSONSchema = getComponent("JSONSchema202012") + 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 Keyword$dynamicAnchor = getComponent( + "JSONSchema202012Keyword$dynamicAnchor" + ) + 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 KeywordAllOf = getComponent("JSONSchema202012KeywordAllOf") + const KeywordAnyOf = getComponent("JSONSchema202012KeywordAnyOf") + const KeywordOneOf = getComponent("JSONSchema202012KeywordOneOf") + const KeywordNot = getComponent("JSONSchema202012KeywordNot") + const KeywordIf = getComponent("JSONSchema202012KeywordIf") + const KeywordThen = getComponent("JSONSchema202012KeywordThen") + const KeywordElse = getComponent("JSONSchema202012KeywordElse") + const KeywordDependentSchemas = getComponent( + "JSONSchema202012KeywordDependentSchemas" + ) + const KeywordPrefixItems = getComponent("JSONSchema202012KeywordPrefixItems") + const KeywordItems = getComponent("JSONSchema202012KeywordItems") + const KeywordContains = getComponent("JSONSchema202012KeywordContains") + const KeywordProperties = getComponent("JSONSchema202012KeywordProperties") + const KeywordPatternProperties = getComponent( + "JSONSchema202012KeywordPatternProperties" + ) + const KeywordAdditionalProperties = getComponent( + "JSONSchema202012KeywordAdditionalProperties" + ) + const KeywordPropertyNames = getComponent( + "JSONSchema202012KeywordPropertyNames" + ) + const KeywordUnevaluatedItems = getComponent( + "JSONSchema202012KeywordUnevaluatedItems" + ) + const KeywordUnevaluatedProperties = getComponent( + "JSONSchema202012KeywordUnevaluatedProperties" + ) + const KeywordType = getComponent("JSONSchema202012KeywordType") + const KeywordEnum = getComponent("JSONSchema202012KeywordEnum") + const KeywordConst = getComponent("JSONSchema202012KeywordConst") + const KeywordConstraint = getComponent("JSONSchema202012KeywordConstraint") + const KeywordDependentRequired = getComponent( + "JSONSchema202012KeywordDependentRequired" + ) + const KeywordContentSchema = getComponent( + "JSONSchema202012KeywordContentSchema" + ) + const KeywordTitle = getComponent("JSONSchema202012KeywordTitle") + const KeywordDescription = getComponent("JSONSchema202012KeywordDescription") + 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") + const withSchemaContext = getComponent("withJSONSchema202012Context") + + OperationsWrapper.OperationsWithJSONSchemaContext = withSchemaContext( + Operations, + { + config: { + default$schema: "https://spec.openapis.org/oas/3.1/dialect/base", + defaultExpandedLevels: configs.defaultModelExpandDepth - 1, + }, + components: { + JSONSchema, + Keyword$schema, + Keyword$vocabulary, + Keyword$id, + Keyword$anchor, + Keyword$dynamicAnchor, + Keyword$ref, + Keyword$dynamicRef, + Keyword$defs, + Keyword$comment, + KeywordAllOf, + KeywordAnyOf, + KeywordOneOf, + KeywordNot, + KeywordIf, + KeywordThen, + KeywordElse, + KeywordDependentSchemas, + KeywordPrefixItems, + KeywordItems, + KeywordContains, + KeywordProperties, + KeywordPatternProperties, + KeywordAdditionalProperties, + KeywordPropertyNames, + KeywordUnevaluatedItems, + KeywordUnevaluatedProperties, + KeywordType, + KeywordEnum, + KeywordConst, + KeywordConstraint, + KeywordDependentRequired, + KeywordContentSchema, + KeywordTitle, + KeywordDescription, + KeywordDefault, + KeywordDeprecated, + KeywordReadOnly, + KeywordWriteOnly, + Accordion, + ExpandDeepButton, + ChevronRightIcon, + }, + fn: { + upperFirst: fn.upperFirst, + isExpandable: makeIsExpandable( + fn.jsonSchema202012.isExpandable, + system + ), + }, + } + ) + + return +}) + +OperationsWrapper.OperationsWithJSONSchemaContext = null + +export default OperationsWrapper diff --git a/src/core/plugins/oas31/wrap-components/webhooks.jsx b/src/core/plugins/oas31/wrap-components/webhooks.jsx new file mode 100644 index 00000000000..e2e848dfcaf --- /dev/null +++ b/src/core/plugins/oas31/wrap-components/webhooks.jsx @@ -0,0 +1,141 @@ +/** + * @prettier + */ +import React from "react" + +import { createOnlyOAS31ComponentWrapper } from "../fn" +import { makeIsExpandable } from "../json-schema-2020-12-extensions/fn" + +const WebhooksWrapper = createOnlyOAS31ComponentWrapper(({ getSystem }) => { + const system = getSystem() + const { getComponent, fn, getConfigs } = system + const configs = getConfigs() + + if (WebhooksWrapper.WebhooksWithJSONSchemaContext) { + return + } + + const Webhooks = getComponent("Webhooks", true) + const JSONSchema = getComponent("JSONSchema202012") + 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 Keyword$dynamicAnchor = getComponent( + "JSONSchema202012Keyword$dynamicAnchor" + ) + 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 KeywordAllOf = getComponent("JSONSchema202012KeywordAllOf") + const KeywordAnyOf = getComponent("JSONSchema202012KeywordAnyOf") + const KeywordOneOf = getComponent("JSONSchema202012KeywordOneOf") + const KeywordNot = getComponent("JSONSchema202012KeywordNot") + const KeywordIf = getComponent("JSONSchema202012KeywordIf") + const KeywordThen = getComponent("JSONSchema202012KeywordThen") + const KeywordElse = getComponent("JSONSchema202012KeywordElse") + const KeywordDependentSchemas = getComponent( + "JSONSchema202012KeywordDependentSchemas" + ) + const KeywordPrefixItems = getComponent("JSONSchema202012KeywordPrefixItems") + const KeywordItems = getComponent("JSONSchema202012KeywordItems") + const KeywordContains = getComponent("JSONSchema202012KeywordContains") + const KeywordProperties = getComponent("JSONSchema202012KeywordProperties") + const KeywordPatternProperties = getComponent( + "JSONSchema202012KeywordPatternProperties" + ) + const KeywordAdditionalProperties = getComponent( + "JSONSchema202012KeywordAdditionalProperties" + ) + const KeywordPropertyNames = getComponent( + "JSONSchema202012KeywordPropertyNames" + ) + const KeywordUnevaluatedItems = getComponent( + "JSONSchema202012KeywordUnevaluatedItems" + ) + const KeywordUnevaluatedProperties = getComponent( + "JSONSchema202012KeywordUnevaluatedProperties" + ) + const KeywordType = getComponent("JSONSchema202012KeywordType") + const KeywordEnum = getComponent("JSONSchema202012KeywordEnum") + const KeywordConst = getComponent("JSONSchema202012KeywordConst") + const KeywordConstraint = getComponent("JSONSchema202012KeywordConstraint") + const KeywordDependentRequired = getComponent( + "JSONSchema202012KeywordDependentRequired" + ) + const KeywordContentSchema = getComponent( + "JSONSchema202012KeywordContentSchema" + ) + const KeywordTitle = getComponent("JSONSchema202012KeywordTitle") + const KeywordDescription = getComponent("JSONSchema202012KeywordDescription") + 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") + const withSchemaContext = getComponent("withJSONSchema202012Context") + + WebhooksWrapper.WebhooksWithJSONSchemaContext = withSchemaContext(Webhooks, { + config: { + default$schema: "https://spec.openapis.org/oas/3.1/dialect/base", + defaultExpandedLevels: configs.defaultModelExpandDepth - 1, + }, + components: { + JSONSchema, + Keyword$schema, + Keyword$vocabulary, + Keyword$id, + Keyword$anchor, + Keyword$dynamicAnchor, + Keyword$ref, + Keyword$dynamicRef, + Keyword$defs, + Keyword$comment, + KeywordAllOf, + KeywordAnyOf, + KeywordOneOf, + KeywordNot, + KeywordIf, + KeywordThen, + KeywordElse, + KeywordDependentSchemas, + KeywordPrefixItems, + KeywordItems, + KeywordContains, + KeywordProperties, + KeywordPatternProperties, + KeywordAdditionalProperties, + KeywordPropertyNames, + KeywordUnevaluatedItems, + KeywordUnevaluatedProperties, + KeywordType, + KeywordEnum, + KeywordConst, + KeywordConstraint, + KeywordDependentRequired, + KeywordContentSchema, + KeywordTitle, + KeywordDescription, + KeywordDefault, + KeywordDeprecated, + KeywordReadOnly, + KeywordWriteOnly, + Accordion, + ExpandDeepButton, + ChevronRightIcon, + }, + fn: { + upperFirst: fn.upperFirst, + isExpandable: makeIsExpandable(fn.jsonSchema202012.isExpandable, system), + }, + }) + + return +}) + +WebhooksWrapper.WebhooksWithJSONSchemaContext = null + +export default WebhooksWrapper