import * as QMS from "@theme/JSONSchemaViewer/utils/QualifierMessages" import { hasUnresolvedRefs, isArrayNotEmpty } from "../detectTypes" import type { JSX } from "react" import type { JSONSchema, JSONSchemaNS } from "@theme/JSONSchemaViewer/types" import type { JSVOptions } from "@theme/JSONSchemaViewer/contexts" type Props = { schema: Exclude options: JSVOptions nullable?: boolean } // To generify the addition of qualifier messages in the future interface CheckInfo { // To check if qualifier message should be invoked match: (props: Props) => boolean // To render the component when asked Component: (props: Props) => JSX.Element } // What are the possible checks for user export type CheckKey = | "nullable" | "deprecated" | "readOnly" | "writeOnly" | "enum" | "stringLength" | "objectProperties" | "no-extra-properties" | "arrayItems" | "arrayContains" | "no-extra-items" | "number-range" | "pattern" | "multipleOf" | "uniqueItems" | "default" | "const" | "examples" | "contentMediaType" | "contentEncoding" | "contentSchema" | "unsolvedRefs" // Available qualifier message const CHECKS_MAP: Record = { nullable: { match: ({ nullable }) => nullable === true, Component: () => , }, deprecated: { match: ({ schema }) => (schema as JSONSchemaNS.Object).deprecated === true, Component: () => , }, readOnly: { match: ({ schema }) => (schema as JSONSchemaNS.Object).readOnly === true, Component: () => , }, writeOnly: { match: ({ schema }) => (schema as JSONSchemaNS.Object).writeOnly === true, Component: () => , }, enum: { match: ({ schema }) => isArrayNotEmpty(schema.enum), Component: ({ schema }) => , }, stringLength: { match: ({ schema }) => schema.minLength !== undefined || schema.maxLength !== undefined, Component: ({ schema }) => ( ), }, objectProperties: { match: ({ schema }) => schema.minProperties !== undefined || schema.maxProperties !== undefined, Component: ({ schema }) => ( ), }, "no-extra-properties": { match: ({ schema }) => schema.additionalProperties === false || (schema as JSONSchemaNS.Object).unevaluatedProperties === false, Component: () => , }, arrayItems: { match: ({ schema }) => schema.minItems !== undefined || schema.maxItems !== undefined, Component: ({ schema }) => ( ), }, arrayContains: { match: ({ schema }) => (schema as JSONSchemaNS.Array).minContains !== undefined || (schema as JSONSchemaNS.Array).maxContains !== undefined, Component: ({ schema }) => ( ), }, "no-extra-items": { match: ({ schema }) => (schema as JSONSchemaNS.Array).unevaluatedItems === false || schema.items === false || schema.additionalItems === false, Component: () => , }, "number-range": { match: ({ schema }) => schema.minimum !== undefined || schema.exclusiveMinimum !== undefined || schema.maximum !== undefined || schema.exclusiveMaximum !== undefined, Component: ({ schema }) => ( ), }, pattern: { match: ({ schema }) => schema.pattern !== undefined, Component: ({ schema }) => ( ), }, multipleOf: { match: ({ schema }) => schema.multipleOf !== undefined, Component: ({ schema }) => ( ), }, uniqueItems: { match: ({ schema }) => schema.uniqueItems !== undefined && schema.uniqueItems === true, Component: () => , }, default: { match: ({ schema }) => schema.default !== undefined, Component: ({ schema }) => ( ), }, const: { match: ({ schema }) => schema.const !== undefined, Component: ({ schema }) => , }, examples: { match: ({ schema, options }) => options.showExamples === true && isArrayNotEmpty(schema.examples), Component: ({ schema }) => ( ), }, contentMediaType: { match: ({ schema }) => schema.contentMediaType !== undefined, Component: ({ schema }) => ( ), }, contentEncoding: { match: ({ schema }) => schema.contentEncoding !== undefined, Component: ({ schema }) => ( ), }, contentSchema: { match: ({ schema }) => (schema as JSONSchemaNS.String).contentSchema !== undefined, Component: ({ schema }) => ( ), }, unsolvedRefs: { match: ({ schema }) => hasUnresolvedRefs(schema), Component: (props) => ( ), }, } // Default order I assume const DEFAULT_ORDER: CheckKey[] = [ "nullable", "deprecated", "readOnly", "writeOnly", "enum", "stringLength", "objectProperties", "no-extra-properties", "arrayItems", "arrayContains", "no-extra-items", "number-range", "pattern", "multipleOf", "uniqueItems", "contentEncoding", "contentMediaType", "contentSchema", "default", "const", "examples", "unsolvedRefs", ] export { CHECKS_MAP, DEFAULT_ORDER }