feat: add const keyword

This commit is contained in:
Alex Varchuk 2021-05-26 11:50:47 +03:00
parent 24c02e3c52
commit aef48a18c8
5 changed files with 10 additions and 0 deletions

View File

@ -110,6 +110,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={'Value:'} value={field.const}/>) || null}
</div> </div>
); );
} }

View File

@ -9,6 +9,7 @@ export interface LabelsConfig {
recursive: string; recursive: string;
arrayOf: string; arrayOf: string;
webhook: string; webhook: string;
const: string;
} }
export type LabelsConfigRaw = Partial<LabelsConfig>; export type LabelsConfigRaw = Partial<LabelsConfig>;
@ -24,6 +25,7 @@ const labels: LabelsConfig = {
recursive: 'Recursive', recursive: 'Recursive',
arrayOf: 'Array of ', arrayOf: 'Array of ',
webhook: 'Event', webhook: 'Event',
const: 'Value',
}; };
export function setRedocLabels(_labels?: LabelsConfigRaw) { export function setRedocLabels(_labels?: LabelsConfigRaw) {

View File

@ -55,6 +55,7 @@ export class FieldModel {
extensions?: Record<string, any>; extensions?: Record<string, any>;
explode: boolean; explode: boolean;
style?: OpenAPIParameterStyle; style?: OpenAPIParameterStyle;
const?: any;
serializationMime?: string; serializationMime?: string;
@ -111,6 +112,8 @@ export class FieldModel {
if (options.showExtensions) { if (options.showExtensions) {
this.extensions = extractExtensions(info, options.showExtensions); this.extensions = extractExtensions(info, options.showExtensions);
} }
this.const = this.schema?.const || info?.const || '';
} }
@action @action

View File

@ -60,6 +60,7 @@ export class SchemaModel {
rawSchema: OpenAPISchema; rawSchema: OpenAPISchema;
schema: MergedOpenAPISchema; schema: MergedOpenAPISchema;
extensions?: Record<string, any>; extensions?: Record<string, any>;
const: any;
/** /**
* @param isChild if schema discriminator Child * @param isChild if schema discriminator Child
@ -119,6 +120,7 @@ export class SchemaModel {
this.default = schema.default; this.default = schema.default;
this.readOnly = !!schema.readOnly; this.readOnly = !!schema.readOnly;
this.writeOnly = !!schema.writeOnly; this.writeOnly = !!schema.writeOnly;
this.const = schema.const || '';
if (!!schema.nullable) { if (!!schema.nullable) {
if (Array.isArray(this.type)) this.type.push('null'); if (Array.isArray(this.type)) this.type.push('null');

View File

@ -99,6 +99,7 @@ export interface OpenAPIParameter {
examples?: { [media: string]: Referenced<OpenAPIExample> }; examples?: { [media: string]: Referenced<OpenAPIExample> };
content?: { [media: string]: OpenAPIMediaType }; content?: { [media: string]: OpenAPIMediaType };
encoding?: Record<string, OpenAPIEncoding>; encoding?: Record<string, OpenAPIEncoding>;
const?: any;
} }
export interface OpenAPIExample { export interface OpenAPIExample {
@ -145,6 +146,7 @@ export interface OpenAPISchema {
minProperties?: number; minProperties?: number;
enum?: any[]; enum?: any[];
example?: any; example?: any;
const?: string;
} }
export interface OpenAPIDiscriminator { export interface OpenAPIDiscriminator {