diff --git a/src/components/APIDoc/SchemaPropertyView.tsx b/src/components/APIDoc/SchemaPropertyView.tsx index 379fbf67..e2bae457 100644 --- a/src/components/APIDoc/SchemaPropertyView.tsx +++ b/src/components/APIDoc/SchemaPropertyView.tsx @@ -1,7 +1,18 @@ -import React, {ReactNode} from 'react'; -import { Text, TextContent, TextVariants, Flex, FlexItem, Label, LabelGroup } from '@patternfly/react-core'; -import { OpenAPIV3 } from 'openapi-types'; - +import React, { ReactNode } from "react"; +import { + Text, + TextContent, + TextVariants, + Flex, + FlexItem, + Label, + LabelGroup, + Level, + ExpandableSection, + CodeBlock, + CodeBlockCode, +} from "@patternfly/react-core"; +import { OpenAPIV3 } from "openapi-types"; interface PropertyViewComponentProps { propSchema?: OpenAPIV3.ReferenceObject | OpenAPIV3.SchemaObject; @@ -10,10 +21,17 @@ interface PropertyViewComponentProps { required: boolean | undefined; } -export const PropertyView:React.FunctionComponent = ({propSchema, propName, propertyType, required}) => { +export const PropertyView: React.FunctionComponent< + PropertyViewComponentProps +> = ({ propSchema, propName, propertyType, required }) => { let extraProps; - if (propSchema && !('$ref' in propSchema) ) { - extraProps = + let extraExample; + if (propSchema && !("$ref" in propSchema)) { + extraProps = ; + if(propSchema.example) { + extraExample = + } + } return ( @@ -24,74 +42,124 @@ export const PropertyView:React.FunctionComponent = {propName} - {required && "*"} + + {required && "*"} + + + + + {propertyType} + + + + + + {extraExample} - - - - {propertyType} - - - - - {extraProps} - + {extraProps} - ) + ); +}; + +interface ExtraExampleViewProps { + propSchema: OpenAPIV3.SchemaObject; } +export const ExtraExampleView: React.FunctionComponent< + ExtraExampleViewProps +> = ({ propSchema }) => { + return ( + <> + {propSchema.description && ( + + {propSchema.description} + + )} + + + + {propSchema.example} + + + + ) +} + interface ExtraPropertyViewProps { propSchema: OpenAPIV3.SchemaObject; } -export const ExtraPropertyView:React.FunctionComponent = ({propSchema}) => { +export const ExtraPropertyView: React.FunctionComponent< + ExtraPropertyViewProps +> = ({ propSchema }) => { let maxMin: string | undefined; if (propSchema.maximum && propSchema.minimum) { - maxMin = (propSchema.exclusiveMinimum ? '>': '≥') + ` ${propSchema.minimum} and ` - maxMin += (propSchema.exclusiveMaximum ? '<' : '≤') + ` ${propSchema.maximum}` + maxMin = + (propSchema.exclusiveMinimum ? ">" : "≥") + ` ${propSchema.minimum} and `; + maxMin += + (propSchema.exclusiveMaximum ? "<" : "≤") + ` ${propSchema.maximum}`; } else if (propSchema.maximum) { - maxMin = (propSchema.exclusiveMaximum ? '<' : '≤') + ` ${propSchema.maximum}` + maxMin = + (propSchema.exclusiveMaximum ? "<" : "≤") + ` ${propSchema.maximum}`; } else if (propSchema.minimum) { - maxMin = (propSchema.exclusiveMinimum ? '>' : '≥') + ` ${propSchema.minimum}` + maxMin = + (propSchema.exclusiveMinimum ? ">" : "≥") + ` ${propSchema.minimum}`; } let maxMinChar: string | undefined; if (propSchema.maxLength && propSchema.minLength) { - maxMinChar = `${propSchema.minLength} to ${propSchema.maxLength} chars` + maxMinChar = `${propSchema.minLength} to ${propSchema.maxLength} chars`; } else if (propSchema.maxLength) { - maxMinChar = `max ${propSchema.maxLength} chars` + maxMinChar = `max ${propSchema.maxLength} chars`; } else if (propSchema.minLength) { - maxMinChar = `min ${propSchema.minLength} chars` + maxMinChar = `min ${propSchema.minLength} chars`; } let maxMinItems: string | undefined; if (propSchema.maxItems && propSchema.minItems) { - maxMinItems = `${propSchema.minItems} to ${propSchema.maxItems} items` + maxMinItems = `${propSchema.minItems} to ${propSchema.maxItems} items`; } else if (propSchema.maxItems) { - maxMinItems = `max ${propSchema.maxItems} items` + maxMinItems = `max ${propSchema.maxItems} items`; } else if (propSchema.minItems) { - maxMinItems = `min ${propSchema.minItems} items` + maxMinItems = `min ${propSchema.minItems} items`; } let maxMinProps: string | undefined; if (propSchema.maxProperties && propSchema.minProperties) { - maxMinProps = `${propSchema.minProperties} to ${propSchema.maxProperties} properties` + maxMinProps = `${propSchema.minProperties} to ${propSchema.maxProperties} properties`; } else if (propSchema.maxProperties) { - maxMinProps = `max ${propSchema.maxProperties} properties` + maxMinProps = `max ${propSchema.maxProperties} properties`; } else if (propSchema.minItems) { - maxMinProps = `min ${propSchema.minProperties} properties` + maxMinProps = `min ${propSchema.minProperties} properties`; } - - return( + return ( {propSchema.format && } - {propSchema.default && } - {propSchema.enum && {propSchema.enum.map(e => )}} - {propSchema.pattern && } - {propSchema.multipleOf && } + {propSchema.default && ( + + )} + {propSchema.enum && ( + + {propSchema.enum.map((e) => ( + + ))} + + )} + {propSchema.pattern && ( + + )} + {propSchema.multipleOf && ( + + )} {maxMin && } {maxMinChar && } {maxMinItems && } @@ -102,5 +170,5 @@ export const ExtraPropertyView:React.FunctionComponent = {propSchema.writeOnly && } {propSchema.deprecated && } - ) -} + ); +};