diff --git a/src/includer/traverse/tables.ts b/src/includer/traverse/tables.ts index e08aa94..46206b6 100644 --- a/src/includer/traverse/tables.ts +++ b/src/includer/traverse/tables.ts @@ -346,6 +346,8 @@ function prepareSampleElement( return 'c3073b9d-edd0-49f2-a28d-b7ded8ff9a8b'; case 'date-time': return '2022-12-29T18:02:01Z'; + case 'binary': + return null; default: return 'string'; } diff --git a/src/includer/ui/endpoint.ts b/src/includer/ui/endpoint.ts index a81eb78..25409d5 100644 --- a/src/includer/ui/endpoint.ts +++ b/src/includer/ui/endpoint.ts @@ -110,7 +110,8 @@ function sandbox({ const searchParams = params?.filter((param: Parameter) => param.in === 'query'); const headers = params?.filter((param: Parameter) => param.in === 'header'); let bodyStr: null | string = null; - if (requestBody?.type === 'application/json') { + + if (requestBody?.type === 'application/json' || requestBody?.type === 'multipart/form-data') { bodyStr = JSON.stringify(prepareSampleObject(requestBody?.schema ?? {}), null, 2); } @@ -119,6 +120,8 @@ function sandbox({ searchParams, headers, body: bodyStr, + schema: requestBody?.schema ?? {}, + bodyType: requestBody?.type, method, security, path: path, diff --git a/src/runtime/components/BodyFormData.tsx b/src/runtime/components/BodyFormData.tsx new file mode 100644 index 0000000..505f386 --- /dev/null +++ b/src/runtime/components/BodyFormData.tsx @@ -0,0 +1,158 @@ +import React from 'react'; +import {Text, TextArea} from '@gravity-ui/uikit'; +import {JSONSchema6Definition} from 'json-schema'; + +import {Text as TextEnum} from '../../plugin/constants'; +import {OpenJSONSchema} from '../../includer/models'; + +import type {Field, Nullable} from '../types'; +import {Column} from './Column'; +import {FileInputArray} from './FileInputArray'; + +type Props = { + example: Nullable; + schema: OpenJSONSchema | undefined; + bodyType?: string; +}; + +type State = { + error: Nullable; +}; + +export class BodyFormData extends React.Component implements Field { + private formValue: FormData; + constructor(props: Props) { + super(props); + this.formValue = new FormData(); + + this.state = { + error: null, + }; + } + + renderInput(key: string) { + return ( + + {key}: + { + this.createOnChange(key)(event.target.files?.[0]); + }} + /> + + ); + } + + renderFileInput(key: string) { + return ( + + {key}: + + + ); + } + + renderTextArea(key: string, property: OpenJSONSchema) { + const example = JSON.parse(this.props.example ?? '{}'); + + const exampleValue = + property.type === 'string' ? example[key] : JSON.stringify(example[key], null, 2); + + const rows = property.type === 'string' ? 1 : 3; + + return ( + + {key}: +