mirror of
https://github.com/Redocly/redoc.git
synced 2024-11-22 08:36:33 +03:00
fix: improve openapi 3.1 (#1700)
This commit is contained in:
parent
7eec319195
commit
cd2d6f76e8
|
@ -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:
|
||||||
|
|
|
@ -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
|
||||||
>{' '}
|
>{' '}
|
||||||
</TypeFormat>
|
</TypeFormat>
|
||||||
)}
|
)}
|
||||||
|
{schema.contentEncoding && (
|
||||||
|
<TypeFormat>
|
||||||
|
{' '}<
|
||||||
|
{schema.contentEncoding}
|
||||||
|
>{' '}
|
||||||
|
</TypeFormat>
|
||||||
|
)}
|
||||||
|
{schema.contentMediaType && (
|
||||||
|
<TypeFormat>
|
||||||
|
{' '}<
|
||||||
|
{schema.contentMediaType}
|
||||||
|
>{' '}
|
||||||
|
</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>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,8 @@ import { Schema, SchemaProps } from './Schema';
|
||||||
|
|
||||||
import { ArrayClosingLabel, ArrayOpenningLabel } from '../../common-elements';
|
import { ArrayClosingLabel, ArrayOpenningLabel } from '../../common-elements';
|
||||||
import styled from '../../styled-components';
|
import styled from '../../styled-components';
|
||||||
import {humanizeConstraints} from "../../utils";
|
import { humanizeConstraints } from '../../utils';
|
||||||
|
import { TypeName } from '../../common-elements/fields';
|
||||||
|
|
||||||
const PaddedSchema = styled.div`
|
const PaddedSchema = styled.div`
|
||||||
padding-left: ${({ theme }) => theme.spacing.unit * 2}px;
|
padding-left: ${({ theme }) => theme.spacing.unit * 2}px;
|
||||||
|
@ -13,12 +14,20 @@ const PaddedSchema = styled.div`
|
||||||
export class ArraySchema extends React.PureComponent<SchemaProps> {
|
export class ArraySchema extends React.PureComponent<SchemaProps> {
|
||||||
render() {
|
render() {
|
||||||
const itemsSchema = this.props.schema.items!;
|
const itemsSchema = this.props.schema.items!;
|
||||||
|
const schema = this.props.schema;
|
||||||
|
|
||||||
const itemConstraintSchema = (
|
const itemConstraintSchema = (
|
||||||
min: number | undefined = undefined,
|
min: number | undefined = undefined,
|
||||||
max: number | undefined = undefined,
|
max: number | undefined = undefined,
|
||||||
) => ({ type: 'array', minItems: min, maxItems: max });
|
) => ({ type: 'array', minItems: min, maxItems: max });
|
||||||
|
|
||||||
const minMaxItems = humanizeConstraints(itemConstraintSchema(itemsSchema.schema.minItems, itemsSchema.schema.maxItems));
|
const minMaxItems = humanizeConstraints(itemConstraintSchema(itemsSchema?.schema?.minItems, itemsSchema?.schema?.maxItems));
|
||||||
|
|
||||||
|
if (schema.displayType && !itemsSchema && !minMaxItems.length) {
|
||||||
|
return (<div>
|
||||||
|
<TypeName>{schema.displayType}</TypeName>
|
||||||
|
</div>);
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
|
|
|
@ -20,6 +20,8 @@ exports[`Components SchemaView discriminator should correctly render discriminat
|
||||||
"activeOneOf": 0,
|
"activeOneOf": 0,
|
||||||
"const": "",
|
"const": "",
|
||||||
"constraints": Array [],
|
"constraints": Array [],
|
||||||
|
"contentEncoding": undefined,
|
||||||
|
"contentMediaType": undefined,
|
||||||
"default": undefined,
|
"default": undefined,
|
||||||
"deprecated": false,
|
"deprecated": false,
|
||||||
"description": "",
|
"description": "",
|
||||||
|
@ -71,6 +73,8 @@ exports[`Components SchemaView discriminator should correctly render discriminat
|
||||||
"activeOneOf": 0,
|
"activeOneOf": 0,
|
||||||
"const": "",
|
"const": "",
|
||||||
"constraints": Array [],
|
"constraints": Array [],
|
||||||
|
"contentEncoding": undefined,
|
||||||
|
"contentMediaType": undefined,
|
||||||
"default": undefined,
|
"default": undefined,
|
||||||
"deprecated": false,
|
"deprecated": false,
|
||||||
"description": "",
|
"description": "",
|
||||||
|
|
|
@ -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,10 +122,14 @@ 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 || schema['x-nullable']) {
|
||||||
if (Array.isArray(this.type) && !this.type.includes('null')) {
|
if (Array.isArray(this.type) && !this.type.some((value) => value === null || value === 'null')) {
|
||||||
this.type = [...this.type, 'null'];
|
this.type = [...this.type, 'null'];
|
||||||
|
} else if (!Array.isArray(this.type) && (this.type !== null || this.type !== 'null')) {
|
||||||
|
this.type = [this.type, 'null'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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 {
|
||||||
|
|
|
@ -2187,6 +2187,12 @@ Object {
|
||||||
"id": Object {
|
"id": Object {
|
||||||
"$ref": "#/components/schemas/Id",
|
"$ref": "#/components/schemas/Id",
|
||||||
},
|
},
|
||||||
|
"image": Object {
|
||||||
|
"contentEncoding": "base64",
|
||||||
|
"contentMediaType": "image/png",
|
||||||
|
"description": "User image",
|
||||||
|
"type": "string",
|
||||||
|
},
|
||||||
"lastName": Object {
|
"lastName": Object {
|
||||||
"description": "User last name",
|
"description": "User last name",
|
||||||
"example": "Smith",
|
"example": "Smith",
|
||||||
|
|
|
@ -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',
|
||||||
|
|
Loading…
Reference in New Issue
Block a user