/* ============================================================================ * Copyright (c) Palo Alto Networks * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * ========================================================================== */ import React, { useState, useId } from "react"; import { translate } from "@docusaurus/Translate"; import FormItem from "@theme/ApiExplorer/FormItem"; import ParamArrayFormItem from "@theme/ApiExplorer/ParamOptions/ParamFormItems/ParamArrayFormItem"; import ParamBooleanFormItem from "@theme/ApiExplorer/ParamOptions/ParamFormItems/ParamBooleanFormItem"; import ParamMultiSelectFormItem from "@theme/ApiExplorer/ParamOptions/ParamFormItems/ParamMultiSelectFormItem"; import ParamSelectFormItem from "@theme/ApiExplorer/ParamOptions/ParamFormItems/ParamSelectFormItem"; import ParamTextFormItem from "@theme/ApiExplorer/ParamOptions/ParamFormItems/ParamTextFormItem"; import { useTypedSelector } from "@theme/ApiItem/hooks"; import { OPENAPI_PARAM_OPTIONS } from "@theme/translationIds"; import { Param } from "./slice"; export interface LabelProps { label?: string; type?: string; required?: boolean; } export interface ParamProps { param: Param; } /** * Extracts enum values from a schema, including when wrapped in allOf. * This handles cases where an enum is referenced via allOf for composition. */ export function getSchemaEnum(schema: any): any[] | undefined { // Direct enum on schema if (schema?.enum) { return schema.enum; } // Enum inside allOf - check each item if (schema?.allOf && Array.isArray(schema.allOf)) { for (const item of schema.allOf) { if (item.enum) { return item.enum; } } } // const is semantically a single-value enum if (schema?.const !== undefined) { return [schema.const]; } return undefined; } function ParamOption({ param, label, type, required, }: ParamProps & LabelProps) { const schemaEnum = getSchemaEnum(param.schema); const itemsEnum = getSchemaEnum(param.schema?.items); if (param.schema?.type === "array" && itemsEnum) { return ( ); } if (param.schema?.type === "array") { return ( ); } if (schemaEnum) { return ( ); } if (param.schema?.type === "boolean") { return ( ); } // integer, number, string, int32, int64, float, double, object, byte, binary, // date-time, date, password return ( ); } function ParamOptionWrapper({ param }: ParamProps) { return ( ); } function ParamOptions() { const [showOptional, setShowOptional] = useState(false); const optionalId = useId(); const pathParams = useTypedSelector((state: any) => state.params.path); const queryParams = useTypedSelector((state: any) => state.params.query); const cookieParams = useTypedSelector((state: any) => state.params.cookie); const headerParams = useTypedSelector((state: any) => state.params.header); const allParams = [ ...pathParams, ...queryParams, ...cookieParams, ...headerParams, ]; const requiredParams = allParams.filter((p) => p.required); const optionalParams = allParams.filter((p) => !p.required); return ( <> {/* Required Parameters */} {requiredParams.map((param) => ( ))} {/* Optional Parameters */} {optionalParams.length > 0 && ( <>
{optionalParams.map((param) => ( ))}
)} ); } export default ParamOptions;