2017-11-14 18:46:50 +03:00
|
|
|
import { OpenAPISpec } from '../types';
|
2017-10-12 00:01:37 +03:00
|
|
|
import { observable, computed } from 'mobx';
|
|
|
|
|
|
|
|
// import { OpenAPIExternalDocumentation, OpenAPIInfo } from '../types';
|
|
|
|
|
|
|
|
import { MenuBuilder } from './MenuBuilder';
|
|
|
|
import { OpenAPIParser } from './OpenAPIParser';
|
|
|
|
import { ApiInfoModel } from './models/ApiInfo';
|
2017-11-21 14:00:33 +03:00
|
|
|
import { RedocNormalizedOptions } from './RedocNormalizedOptions';
|
2017-11-23 00:38:38 +03:00
|
|
|
import { SecuritySchemesModel } from './models/SecuritySchemes';
|
2017-10-12 00:01:37 +03:00
|
|
|
/**
|
|
|
|
* Store that containts all the specification related information in the form of tree
|
|
|
|
*/
|
|
|
|
export class SpecStore {
|
|
|
|
@observable.ref parser: OpenAPIParser;
|
|
|
|
|
2017-11-21 14:00:33 +03:00
|
|
|
constructor(
|
|
|
|
spec: OpenAPISpec,
|
|
|
|
specUrl: string | undefined,
|
|
|
|
private options: RedocNormalizedOptions,
|
|
|
|
) {
|
2017-11-21 17:33:22 +03:00
|
|
|
this.parser = new OpenAPIParser(spec, specUrl, options);
|
2017-10-12 00:01:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
@computed
|
2017-11-14 18:46:50 +03:00
|
|
|
get info(): ApiInfoModel {
|
2017-10-12 00:01:37 +03:00
|
|
|
return new ApiInfoModel(this.parser);
|
|
|
|
}
|
|
|
|
|
|
|
|
@computed
|
|
|
|
get externalDocs() {
|
2017-11-14 18:46:50 +03:00
|
|
|
return this.parser.spec.externalDocs;
|
2017-10-12 00:01:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
@computed
|
|
|
|
get operationGroups() {
|
2017-11-21 14:00:33 +03:00
|
|
|
return MenuBuilder.buildStructure(this.parser, this.options);
|
2017-10-12 00:01:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
@computed
|
2017-11-24 12:51:59 +03:00
|
|
|
get securitySchemes() {
|
2017-11-23 00:38:38 +03:00
|
|
|
const schemes = this.parser.spec.components && this.parser.spec.components.securitySchemes;
|
|
|
|
return schemes && new SecuritySchemesModel(this.parser);
|
2017-10-12 00:01:37 +03:00
|
|
|
}
|
|
|
|
}
|