Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ function Accept() {
}

return (
<FormItem label="Accept">
<FormItem>
<FormSelect
label="Accept"
value={value}
options={options}
onChange={(e: any) => dispatch(setAccept(e.target.value))}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,12 @@ function Authorization() {
return (
<div>
{optionKeys.length > 1 && (
<FormItem
label={translate({
id: OPENAPI_AUTH.SECURITY_SCHEME,
message: "Security Scheme",
})}
>
<FormItem>
<FormSelect
label={translate({
id: OPENAPI_AUTH.SECURITY_SCHEME,
message: "Security Scheme",
})}
options={optionKeys}
value={selected}
onChange={(e: React.ChangeEvent<HTMLSelectElement>) => {
Expand All @@ -52,14 +51,12 @@ function Authorization() {
{selectedAuth.map((a: any) => {
if (a.type === "http" && a.scheme === "bearer") {
return (
<FormItem
label={translate({
id: OPENAPI_AUTH.BEARER_TOKEN,
message: "Bearer Token",
})}
key={a.key + "-bearer"}
>
<FormItem key={a.key + "-bearer"}>
<FormTextInput
label={translate({
id: OPENAPI_AUTH.BEARER_TOKEN,
message: "Bearer Token",
})}
placeholder={translate({
id: OPENAPI_AUTH.BEARER_TOKEN,
message: "Bearer Token",
Expand All @@ -83,14 +80,12 @@ function Authorization() {

if (a.type === "oauth2") {
return (
<FormItem
label={translate({
id: OPENAPI_AUTH.BEARER_TOKEN,
message: "Bearer Token",
})}
key={a.key + "-oauth2"}
>
<FormItem key={a.key + "-oauth2"}>
<FormTextInput
label={translate({
id: OPENAPI_AUTH.BEARER_TOKEN,
message: "Bearer Token",
})}
placeholder={translate({
id: OPENAPI_AUTH.BEARER_TOKEN,
message: "Bearer Token",
Expand All @@ -115,13 +110,12 @@ function Authorization() {
if (a.type === "http" && a.scheme === "basic") {
return (
<React.Fragment key={a.key + "-basic"}>
<FormItem
label={translate({
id: OPENAPI_AUTH.USERNAME,
message: "Username",
})}
>
<FormItem>
<FormTextInput
label={translate({
id: OPENAPI_AUTH.USERNAME,
message: "Username",
})}
placeholder={translate({
id: OPENAPI_AUTH.USERNAME,
message: "Username",
Expand All @@ -139,13 +133,12 @@ function Authorization() {
}}
/>
</FormItem>
<FormItem
label={translate({
id: OPENAPI_AUTH.PASSWORD,
message: "Password",
})}
>
<FormItem>
<FormTextInput
label={translate({
id: OPENAPI_AUTH.PASSWORD,
message: "Password",
})}
placeholder={translate({
id: OPENAPI_AUTH.PASSWORD,
message: "Password",
Expand All @@ -170,8 +163,9 @@ function Authorization() {

if (a.type === "apiKey") {
return (
<FormItem label={`${a.key}`} key={a.key + "-apikey"}>
<FormItem key={a.key + "-apikey"}>
<FormTextInput
label={`${a.key}`}
placeholder={`${a.key}`}
password
value={data[a.key].apiKey ?? ""}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import React from "react";

import FormFileUpload from "@theme/ApiExplorer/FormFileUpload";
import FormLabel from "@theme/ApiExplorer/FormLabel";
import FormSelect from "@theme/ApiExplorer/FormSelect";
import FormTextInput from "@theme/ApiExplorer/FormTextInput";
import LiveApp from "@theme/ApiExplorer/LiveEditor";
Expand All @@ -21,12 +22,16 @@ interface FormBodyItemProps {
schemaObject: SchemaObject;
id: string;
schema: SchemaObject;
label?: string;
required?: boolean;
}

export default function FormBodyItem({
schemaObject,
id,
schema,
label,
required,
}: FormBodyItemProps): React.JSX.Element {
const dispatch = useTypedDispatch();

Expand All @@ -35,30 +40,36 @@ export default function FormBodyItem({
schemaObject.items?.format === "binary"
) {
return (
<FileArrayFormBodyItem id={id} description={schemaObject.description} />
<>
{label && <FormLabel label={label} required={required} />}
<FileArrayFormBodyItem id={id} description={schemaObject.description} />
</>
);
}

if (schemaObject.format === "binary") {
return (
<FormFileUpload
placeholder={schemaObject.description || id}
onChange={(file: any) => {
if (file === undefined) {
dispatch(clearFormBodyKey(id));
return;
}
dispatch(
setFileFormBody({
key: id,
value: {
src: `/path/to/${file.name}`,
content: file,
},
})
);
}}
/>
<>
{label && <FormLabel label={label} required={required} />}
<FormFileUpload
placeholder={schemaObject.description || id}
onChange={(file: any) => {
if (file === undefined) {
dispatch(clearFormBodyKey(id));
return;
}
dispatch(
setFileFormBody({
key: id,
value: {
src: `/path/to/${file.name}`,
content: file,
},
})
);
}}
/>
</>
);
}

Expand All @@ -73,13 +84,16 @@ export default function FormBodyItem({
);

return (
<LiveApp
action={(code: string) =>
dispatch(setStringFormBody({ key: id, value: code }))
}
>
{objectExample}
</LiveApp>
<>
{label && <FormLabel label={label} required={required} />}
<LiveApp
action={(code: string) =>
dispatch(setStringFormBody({ key: id, value: code }))
}
>
{objectExample}
</LiveApp>
</>
);
}

Expand All @@ -89,6 +103,8 @@ export default function FormBodyItem({
) {
return (
<FormSelect
label={label}
required={required}
options={["---", ...schemaObject.enum]}
onChange={(e: React.ChangeEvent<HTMLSelectElement>) => {
const val = e.target.value;
Expand All @@ -109,6 +125,8 @@ export default function FormBodyItem({
// TODO: support all the other types.
return (
<FormTextInput
label={label}
required={required}
paramName={id}
isRequired={
Array.isArray(schema.required) && schema.required.includes(id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,18 +318,17 @@ function Body({
<FormItem className="openapi-explorer__form-item-body-container">
{Object.entries(schema.properties ?? {}).map(([key, val]: any) => {
return (
<FormItem
key={key}
label={key}
required={
Array.isArray(schema.required) && schema.required.includes(key)
}
>
<FormItem key={key}>
<FormBodyItem
schemaObject={val}
id={key}
schema={schema}
></FormBodyItem>
label={key}
required={
Array.isArray(schema.required) &&
schema.required.includes(key)
}
/>
</FormItem>
);
})}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ function ContentType() {
}

return (
<FormItem label="Content-Type">
<FormItem>
<FormSelect
label="Content-Type"
value={value}
options={options}
onChange={(e: React.ChangeEvent<HTMLSelectElement>) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,3 @@
.openapi-explorer__form-item-body-container {
padding: 0;
}

.openapi-explorer__form-item-label {
font-family: var(--ifm-font-family-monospace);
font-weight: bold;
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,17 @@

import React from "react";

import { translate } from "@docusaurus/Translate";
import { OPENAPI_SCHEMA_ITEM } from "@theme/translationIds";
import clsx from "clsx";

export interface Props {
label?: string;
type?: string;
required?: boolean | undefined;
children?: React.ReactNode;
className?: string;
}

function FormItem({ label, type, required, children, className }: Props) {
function FormItem({ children, className }: Props) {
return (
<div className={clsx("openapi-explorer__form-item", className)}>
{label && (
<label className="openapi-explorer__form-item-label">{label}</label>
)}
{type && <span style={{ opacity: 0.6 }}> — {type}</span>}
{required && (
<span className="openapi-schema__required">
{translate({ id: OPENAPI_SCHEMA_ITEM.REQUIRED, message: "required" })}
</span>
)}
<div>{children}</div>
{children}
</div>
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.openapi-explorer__form-item-label {
font-family: var(--ifm-font-family-monospace);
font-weight: bold;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/* ============================================================================
* 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 from "react";

import { translate } from "@docusaurus/Translate";
import { OPENAPI_SCHEMA_ITEM } from "@theme/translationIds";

export interface Props {
htmlFor?: string;
label: string;
type?: string;
required?: boolean;
}

function FormLabel({ htmlFor, label, type, required }: Props) {
return (
<>
{htmlFor ? (
<label className="openapi-explorer__form-item-label" htmlFor={htmlFor}>
{label}
</label>
) : (
<span className="openapi-explorer__form-item-label">{label}</span>
)}
{type && <span style={{ opacity: 0.6 }}> — {type}</span>}
{required && (
<span className="openapi-schema__required">
{translate({
id: OPENAPI_SCHEMA_ITEM.REQUIRED,
message: "required",
})}
</span>
)}
</>
);
}

export default FormLabel;
Loading
Loading