/* ============================================================================
* 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 (