diff --git a/src/components/Fields/FieldDetails.tsx b/src/components/Fields/FieldDetails.tsx index 04672726..10c212e7 100644 --- a/src/components/Fields/FieldDetails.tsx +++ b/src/components/Fields/FieldDetails.tsx @@ -53,6 +53,9 @@ export class FieldDetails extends React.PureComponent { )} {!renderDiscriminatorSwitch && }{' '} + + {schema.const && } + {showExamples && } {}
diff --git a/src/services/models/Schema.ts b/src/services/models/Schema.ts index fe904a23..fabfb093 100644 --- a/src/services/models/Schema.ts +++ b/src/services/models/Schema.ts @@ -20,6 +20,7 @@ import { } from '../../utils/'; import { l } from '../Labels'; +import { Schema } from '../../components'; // TODO: refactor this model, maybe use getters instead of copying all the values export class SchemaModel { @@ -42,6 +43,7 @@ export class SchemaModel { pattern?: string; example?: any; enum: any[]; + const: any; default?: any; readOnly: boolean; writeOnly: boolean; @@ -105,6 +107,7 @@ export class SchemaModel { this.format = schema.format; this.nullable = !!schema.nullable; this.enum = schema.enum || []; + this.const = schema.const; this.example = schema.example; this.deprecated = !!schema.deprecated; this.pattern = schema.pattern; @@ -195,17 +198,21 @@ export class SchemaModel { return schema; }); - this.displayType = this.oneOf - .map(schema => { - let name = - schema.typePrefix + - (schema.title ? `${schema.title} (${schema.displayType})` : schema.displayType); - if (name.indexOf(' or ') > -1) { - name = `(${name})`; - } - return name; - }) - .join(' or '); + // If the displayType hasn't been defined, then assemble an aggregate + // displayType from all the oneOf variants + if (this.displayType == 'any') { + this.displayType = this.oneOf + .map(schema => { + let name = + schema.typePrefix + + (schema.title ? `${schema.title} (${schema.displayType})` : schema.displayType); + if (name.indexOf(' or ') > -1) { + name = `(${name})`; + } + return name; + }) + .join(' or '); + } } private initDiscriminator( diff --git a/src/types/open-api.d.ts b/src/types/open-api.d.ts index 4fb04a83..9ed1ebc1 100644 --- a/src/types/open-api.d.ts +++ b/src/types/open-api.d.ts @@ -138,6 +138,7 @@ export interface OpenAPISchema { maxProperties?: number; minProperties?: number; enum?: any[]; + const?: any; example?: any; }