diff --git a/__tests__/JSONSchemaViewer/__snapshots__/constructor.test.tsx.snap b/__tests__/JSONSchemaViewer/__snapshots__/constructor.test.tsx.snap index 69525c28..0d5e85a9 100644 --- a/__tests__/JSONSchemaViewer/__snapshots__/constructor.test.tsx.snap +++ b/__tests__/JSONSchemaViewer/__snapshots__/constructor.test.tsx.snap @@ -435,6 +435,10 @@ exports[`JSONSchemaViewer - constructor Overwrite default ValueComponent value 1 > object +   + + constant +
diff --git a/__tests__/JSONSchemaViewer/__snapshots__/generateFriendlyName.test.tsx.snap b/__tests__/JSONSchemaViewer/__snapshots__/generateFriendlyName.test.tsx.snap index 4ca81f22..06ce896d 100644 --- a/__tests__/JSONSchemaViewer/__snapshots__/generateFriendlyName.test.tsx.snap +++ b/__tests__/JSONSchemaViewer/__snapshots__/generateFriendlyName.test.tsx.snap @@ -2229,6 +2229,10 @@ exports[`JSONSchemaViewer - generateFriendlyName cases test Prefer title 1`] = ` > string +   + + constant +
diff --git a/__tests__/JSONSchemaViewer/__snapshots__/generic_keywords.test.tsx.snap b/__tests__/JSONSchemaViewer/__snapshots__/generic_keywords.test.tsx.snap index 34e77071..ccda6866 100644 --- a/__tests__/JSONSchemaViewer/__snapshots__/generic_keywords.test.tsx.snap +++ b/__tests__/JSONSchemaViewer/__snapshots__/generic_keywords.test.tsx.snap @@ -174,6 +174,10 @@ exports[`JSONSchemaViewer - Generic keywords test const 1`] = ` > string +   + + constant +
diff --git a/__tests__/JSONSchemaViewer/__snapshots__/schema_conditionally.test.tsx.snap b/__tests__/JSONSchemaViewer/__snapshots__/schema_conditionally.test.tsx.snap index 4bc2ff93..908fd6ee 100644 --- a/__tests__/JSONSchemaViewer/__snapshots__/schema_conditionally.test.tsx.snap +++ b/__tests__/JSONSchemaViewer/__snapshots__/schema_conditionally.test.tsx.snap @@ -339,6 +339,10 @@ exports[`JSONSchemaViewer - schema conditionally test If Then Else (multiple) 1` > string +   + + constant +
@@ -602,6 +606,10 @@ exports[`JSONSchemaViewer - schema conditionally test If Then Else (multiple) 1` required +   + + constant +
@@ -865,6 +873,10 @@ exports[`JSONSchemaViewer - schema conditionally test If Then Else (multiple) 1` required +   + + constant +
@@ -1262,6 +1274,10 @@ exports[`JSONSchemaViewer - schema conditionally test If Then Else 1`] = ` > string +   + + constant +
diff --git a/src/theme/JSONSchemaViewer/components/SchemaItem/SchemaItem.tsx b/src/theme/JSONSchemaViewer/components/SchemaItem/SchemaItem.tsx index d9d47764..7ffb416e 100644 --- a/src/theme/JSONSchemaViewer/components/SchemaItem/SchemaItem.tsx +++ b/src/theme/JSONSchemaViewer/components/SchemaItem/SchemaItem.tsx @@ -8,6 +8,7 @@ import { DeprecatedLabel, WriteOnlyLabel, ReadOnlyLabel, + ConstantLabel } from "@theme/JSONSchemaViewer/labels" import { GenerateFriendlyName } from "@theme/JSONSchemaViewer/utils" @@ -43,6 +44,10 @@ export default function SchemaItem({ typeof typedSchema !== "boolean" && typedSchema.readOnly === true let isWriteOnly = typeof typedSchema !== "boolean" && typedSchema.writeOnly === true + let isConstant = + typeof typedSchema !== "boolean" && + (typedSchema.const !== undefined || + (Array.isArray(typedSchema.enum) && typedSchema.enum.length === 1)) let isRequired = !isDeprecated && required // Header @@ -58,6 +63,8 @@ export default function SchemaItem({ {isReadOnly && } {isWriteOnly && <> } {isWriteOnly && } + {isConstant && <> } + {isConstant && } ) diff --git a/src/theme/JSONSchemaViewer/labels/Constant/Constant.tsx b/src/theme/JSONSchemaViewer/labels/Constant/Constant.tsx new file mode 100644 index 00000000..d0a8c87e --- /dev/null +++ b/src/theme/JSONSchemaViewer/labels/Constant/Constant.tsx @@ -0,0 +1,18 @@ +import React from "react" +import Translate from "@docusaurus/Translate" + +import styles from "./styles.module.css" + +export default function ConstantLabel(): JSX.Element { + return ( + + + {"constant"} + + + ) + } \ No newline at end of file diff --git a/src/theme/JSONSchemaViewer/labels/Constant/styles.module.css b/src/theme/JSONSchemaViewer/labels/Constant/styles.module.css new file mode 100644 index 00000000..f0f789b2 --- /dev/null +++ b/src/theme/JSONSchemaViewer/labels/Constant/styles.module.css @@ -0,0 +1,4 @@ +.constant { + font-size: var(--ifm-code-font-size); + color: var(--ifm-color-secondary-darkest); +} \ No newline at end of file diff --git a/src/theme/JSONSchemaViewer/labels/index.ts b/src/theme/JSONSchemaViewer/labels/index.ts index 0522de29..9bd32f92 100644 --- a/src/theme/JSONSchemaViewer/labels/index.ts +++ b/src/theme/JSONSchemaViewer/labels/index.ts @@ -22,3 +22,4 @@ export { default as AndLabel } from "@theme/JSONSchemaViewer/labels/And" export { default as OrLabel } from "@theme/JSONSchemaViewer/labels/Or" export { default as NotLabel } from "@theme/JSONSchemaViewer/labels/Not" export { default as XorLabel } from "@theme/JSONSchemaViewer/labels/Xor" +export { default as ConstantLabel } from "@theme/JSONSchemaViewer/labels/Constant/Constant" \ No newline at end of file