feat: add contentMediaType and contentEncoding

This commit is contained in:
Alex Varchuk 2021-07-21 20:08:22 +03:00
parent 79ca769f32
commit ba3b2c52e4
5 changed files with 29 additions and 2 deletions

View File

@ -1166,6 +1166,11 @@ components:
description: User status description: User status
type: integer type: integer
format: int32 format: int32
image:
description: User image
type: string
contentEncoding: base64
contentMediaType: image/png
xml: xml:
name: User name: User
requestBodies: requestBodies:

View File

@ -59,7 +59,7 @@ export class FieldDetails extends React.PureComponent<FieldProps, { patternShown
} else { } else {
const label = l('example') + ':'; const label = l('example') + ':';
const raw = !!field.in; const raw = !!field.in;
renderedExamples = <FieldDetail label={label} value={getSerializedValue(field, field.example)} raw={raw} />; renderedExamples = <FieldDetail label={label} value={getSerializedValue(field, field.example)} raw={raw} />;
} }
} }
@ -76,6 +76,20 @@ export class FieldDetails extends React.PureComponent<FieldProps, { patternShown
&gt;{' '} &gt;{' '}
</TypeFormat> </TypeFormat>
)} )}
{schema.contentEncoding && (
<TypeFormat>
{' '}&lt;
{schema.contentEncoding}
&gt;{' '}
</TypeFormat>
)}
{schema.contentMediaType && (
<TypeFormat>
{' '}&lt;
{schema.contentMediaType}
&gt;{' '}
</TypeFormat>
)}
{schema.title && !hideSchemaTitles && <TypeTitle> ({schema.title}) </TypeTitle>} {schema.title && !hideSchemaTitles && <TypeTitle> ({schema.title}) </TypeTitle>}
<ConstraintsView constraints={schema.constraints} /> <ConstraintsView constraints={schema.constraints} />
{schema.pattern && !hideSchemaPattern && ( {schema.pattern && !hideSchemaPattern && (
@ -110,7 +124,7 @@ export class FieldDetails extends React.PureComponent<FieldProps, { patternShown
<ExternalDocumentation externalDocs={schema.externalDocs} compact={true} /> <ExternalDocumentation externalDocs={schema.externalDocs} compact={true} />
)} )}
{(renderDiscriminatorSwitch && renderDiscriminatorSwitch(this.props)) || null} {(renderDiscriminatorSwitch && renderDiscriminatorSwitch(this.props)) || null}
{field.const && (<FieldDetail label={l('const') + ':'} value={field.const}/>) || null} {field.const && (<FieldDetail label={l('const') + ':'} value={field.const} />) || null}
</div> </div>
); );
} }

View File

@ -61,6 +61,8 @@ export class SchemaModel {
schema: MergedOpenAPISchema; schema: MergedOpenAPISchema;
extensions?: Record<string, any>; extensions?: Record<string, any>;
const: any; const: any;
contentEncoding?: string;
contentMediaType?: string;
/** /**
* @param isChild if schema discriminator Child * @param isChild if schema discriminator Child
@ -120,6 +122,8 @@ export class SchemaModel {
this.readOnly = !!schema.readOnly; this.readOnly = !!schema.readOnly;
this.writeOnly = !!schema.writeOnly; this.writeOnly = !!schema.writeOnly;
this.const = schema.const || ''; this.const = schema.const || '';
this.contentEncoding = schema.contentEncoding;
this.contentMediaType = schema.contentMediaType;
if (!!schema.nullable) { if (!!schema.nullable) {
if (Array.isArray(this.type) && !this.type.includes('null')) { if (Array.isArray(this.type) && !this.type.includes('null')) {

View File

@ -147,6 +147,8 @@ export interface OpenAPISchema {
enum?: any[]; enum?: any[];
example?: any; example?: any;
const?: string; const?: string;
contentEncoding?: string;
contentMediaType?: string;
} }
export interface OpenAPIDiscriminator { export interface OpenAPIDiscriminator {

View File

@ -83,6 +83,8 @@ const schemaKeywordTypes = {
maxLength: 'string', maxLength: 'string',
minLength: 'string', minLength: 'string',
pattern: 'string', pattern: 'string',
contentEncoding: 'string',
contentMediaType: 'string',
items: 'array', items: 'array',
maxItems: 'array', maxItems: 'array',