mirror of
https://github.com/Redocly/redoc.git
synced 2025-02-08 22:10:33 +03:00
* add the option to render vendor extensions * refactor Extensions, move Redoc extension list to utils file * feat: new option showExtensions (support list of extensions)
56 lines
1.6 KiB
TypeScript
56 lines
1.6 KiB
TypeScript
import { action, observable } from 'mobx';
|
|
|
|
import { OpenAPIParameter, Referenced } from '../../types';
|
|
import { RedocNormalizedOptions } from '../RedocNormalizedOptions';
|
|
|
|
import { extractExtensions } from '../../utils/openapi';
|
|
import { OpenAPIParser } from '../OpenAPIParser';
|
|
import { SchemaModel } from './Schema';
|
|
|
|
/**
|
|
* Field or Parameter model ready to be used by components
|
|
*/
|
|
export class FieldModel {
|
|
@observable
|
|
expanded: boolean = false;
|
|
|
|
schema: SchemaModel;
|
|
name: string;
|
|
required: boolean;
|
|
description: string;
|
|
example?: string;
|
|
deprecated: boolean;
|
|
in?: string;
|
|
kind: string;
|
|
extensions?: Dict<any>;
|
|
|
|
constructor(
|
|
parser: OpenAPIParser,
|
|
infoOrRef: Referenced<OpenAPIParameter> & { name?: string; kind?: string },
|
|
pointer: string,
|
|
options: RedocNormalizedOptions,
|
|
) {
|
|
const info = parser.deref<OpenAPIParameter>(infoOrRef);
|
|
this.kind = infoOrRef.kind || 'field';
|
|
this.name = infoOrRef.name || info.name;
|
|
this.in = info.in;
|
|
this.required = !!info.required;
|
|
this.schema = new SchemaModel(parser, info.schema || {}, pointer, options);
|
|
this.description =
|
|
info.description === undefined ? this.schema.description || '' : info.description;
|
|
this.example = info.example || this.schema.example;
|
|
|
|
this.deprecated = info.deprecated === undefined ? !!this.schema.deprecated : info.deprecated;
|
|
parser.exitRef(infoOrRef);
|
|
|
|
if (options.showExtensions) {
|
|
this.extensions = extractExtensions(info, options.showExtensions);
|
|
}
|
|
}
|
|
|
|
@action
|
|
toggle() {
|
|
this.expanded = !this.expanded;
|
|
}
|
|
}
|