mirror of
https://github.com/Redocly/redoc.git
synced 2025-02-13 08:20:34 +03:00
43 lines
1.2 KiB
TypeScript
43 lines
1.2 KiB
TypeScript
|
import { observable, action } from 'mobx';
|
||
|
|
||
|
import { OpenAPIParameter, Referenced } from '../../types';
|
||
|
|
||
|
import { SchemaModel } from './Schema';
|
||
|
import { OpenAPIParser } from '../OpenAPIParser';
|
||
|
|
||
|
/**
|
||
|
* Field or Parameter model ready to be used by components
|
||
|
*/
|
||
|
export class FieldModel {
|
||
|
@observable public expanded: boolean = false;
|
||
|
|
||
|
public schema: SchemaModel;
|
||
|
public name: string;
|
||
|
public required: boolean;
|
||
|
public description: string;
|
||
|
public example?: string;
|
||
|
public deprecated: boolean;
|
||
|
public in?: string;
|
||
|
|
||
|
constructor(parser: OpenAPIParser, infoOrRef: Referenced<OpenAPIParameter>, pointer: string) {
|
||
|
const info = parser.deref(infoOrRef);
|
||
|
|
||
|
this.name = info.name;
|
||
|
this.in = info.in;
|
||
|
this.required = !!info.required;
|
||
|
this.schema = new SchemaModel(parser, info.schema, pointer + '/schema');
|
||
|
this.description =
|
||
|
info.description === undefined ? this.schema.description || '' : info.description;
|
||
|
const example = info.example || this.schema.example;
|
||
|
this.example = example && JSON.stringify(example);
|
||
|
|
||
|
this.deprecated = info.deprecated === undefined ? !!this.schema.deprecated : info.deprecated;
|
||
|
parser.exitRef(infoOrRef);
|
||
|
}
|
||
|
|
||
|
@action
|
||
|
toggle() {
|
||
|
this.expanded = !this.expanded;
|
||
|
}
|
||
|
}
|