mirror of
https://github.com/Redocly/redoc.git
synced 2025-02-09 22:40:33 +03:00
48 lines
1.4 KiB
TypeScript
48 lines
1.4 KiB
TypeScript
import { action, observable } from 'mobx';
|
|
|
|
import { OpenAPIParameter, Referenced } from '../../types';
|
|
import { RedocNormalizedOptions } from '../RedocNormalizedOptions';
|
|
|
|
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;
|
|
|
|
constructor(
|
|
parser: OpenAPIParser,
|
|
infoOrRef: Referenced<OpenAPIParameter> & { name?: string },
|
|
pointer: string,
|
|
options: RedocNormalizedOptions,
|
|
) {
|
|
const info = parser.deref<OpenAPIParameter>(infoOrRef);
|
|
this.name = infoOrRef.name || info.name;
|
|
this.in = info.in;
|
|
this.required = !!info.required;
|
|
const schemaPointer = (parser.isRef(infoOrRef) ? infoOrRef.$ref : pointer) + '/schema';
|
|
this.schema = new SchemaModel(parser, info.schema || {}, schemaPointer, 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);
|
|
}
|
|
|
|
@action
|
|
toggle() {
|
|
this.expanded = !this.expanded;
|
|
}
|
|
}
|