mirror of
https://github.com/Redocly/redoc.git
synced 2025-08-08 22:24:54 +03:00
Implement 'const' as synonym for single valued 'enum'; when type is defined, don't aggregate types from oneOf variants
This commit is contained in:
parent
18590ccc60
commit
99f845731b
|
@ -53,6 +53,9 @@ export class FieldDetails extends React.PureComponent<FieldProps> {
|
||||||
)}
|
)}
|
||||||
<FieldDetail label={l('default') + ':'} value={schema.default} />
|
<FieldDetail label={l('default') + ':'} value={schema.default} />
|
||||||
{!renderDiscriminatorSwitch && <EnumValues type={schema.type} values={schema.enum} />}{' '}
|
{!renderDiscriminatorSwitch && <EnumValues type={schema.type} values={schema.enum} />}{' '}
|
||||||
|
|
||||||
|
{schema.const && <FieldDetail label={l('enumSingleValue') + ':'} value={schema.const} />}
|
||||||
|
|
||||||
{showExamples && <FieldDetail label={l('example') + ':'} value={example} />}
|
{showExamples && <FieldDetail label={l('example') + ':'} value={example} />}
|
||||||
{<Extensions extensions={{ ...field.extensions, ...schema.extensions }} />}
|
{<Extensions extensions={{ ...field.extensions, ...schema.extensions }} />}
|
||||||
<div>
|
<div>
|
||||||
|
|
|
@ -20,6 +20,7 @@ import {
|
||||||
} from '../../utils/';
|
} from '../../utils/';
|
||||||
|
|
||||||
import { l } from '../Labels';
|
import { l } from '../Labels';
|
||||||
|
import { Schema } from '../../components';
|
||||||
|
|
||||||
// TODO: refactor this model, maybe use getters instead of copying all the values
|
// TODO: refactor this model, maybe use getters instead of copying all the values
|
||||||
export class SchemaModel {
|
export class SchemaModel {
|
||||||
|
@ -42,6 +43,7 @@ export class SchemaModel {
|
||||||
pattern?: string;
|
pattern?: string;
|
||||||
example?: any;
|
example?: any;
|
||||||
enum: any[];
|
enum: any[];
|
||||||
|
const: any;
|
||||||
default?: any;
|
default?: any;
|
||||||
readOnly: boolean;
|
readOnly: boolean;
|
||||||
writeOnly: boolean;
|
writeOnly: boolean;
|
||||||
|
@ -105,6 +107,7 @@ export class SchemaModel {
|
||||||
this.format = schema.format;
|
this.format = schema.format;
|
||||||
this.nullable = !!schema.nullable;
|
this.nullable = !!schema.nullable;
|
||||||
this.enum = schema.enum || [];
|
this.enum = schema.enum || [];
|
||||||
|
this.const = schema.const;
|
||||||
this.example = schema.example;
|
this.example = schema.example;
|
||||||
this.deprecated = !!schema.deprecated;
|
this.deprecated = !!schema.deprecated;
|
||||||
this.pattern = schema.pattern;
|
this.pattern = schema.pattern;
|
||||||
|
@ -195,17 +198,21 @@ export class SchemaModel {
|
||||||
return schema;
|
return schema;
|
||||||
});
|
});
|
||||||
|
|
||||||
this.displayType = this.oneOf
|
// If the displayType hasn't been defined, then assemble an aggregate
|
||||||
.map(schema => {
|
// displayType from all the oneOf variants
|
||||||
let name =
|
if (this.displayType == 'any') {
|
||||||
schema.typePrefix +
|
this.displayType = this.oneOf
|
||||||
(schema.title ? `${schema.title} (${schema.displayType})` : schema.displayType);
|
.map(schema => {
|
||||||
if (name.indexOf(' or ') > -1) {
|
let name =
|
||||||
name = `(${name})`;
|
schema.typePrefix +
|
||||||
}
|
(schema.title ? `${schema.title} (${schema.displayType})` : schema.displayType);
|
||||||
return name;
|
if (name.indexOf(' or ') > -1) {
|
||||||
})
|
name = `(${name})`;
|
||||||
.join(' or ');
|
}
|
||||||
|
return name;
|
||||||
|
})
|
||||||
|
.join(' or ');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private initDiscriminator(
|
private initDiscriminator(
|
||||||
|
|
1
src/types/open-api.d.ts
vendored
1
src/types/open-api.d.ts
vendored
|
@ -138,6 +138,7 @@ export interface OpenAPISchema {
|
||||||
maxProperties?: number;
|
maxProperties?: number;
|
||||||
minProperties?: number;
|
minProperties?: number;
|
||||||
enum?: any[];
|
enum?: any[];
|
||||||
|
const?: any;
|
||||||
example?: any;
|
example?: any;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user