redoc/src/services/SpecStore.ts

38 lines
1.4 KiB
TypeScript
Raw Normal View History

import { OpenAPIExternalDocumentation, OpenAPIPath, OpenAPISpec, Referenced } from '../types';
2017-10-12 00:01:37 +03:00
2018-07-26 17:34:44 +03:00
import { ContentItemModel, MenuBuilder } from './MenuBuilder';
2017-10-12 00:01:37 +03:00
import { ApiInfoModel } from './models/ApiInfo';
2020-08-14 16:33:25 +03:00
import { WebhookModel } from './models/Webhook';
2017-11-23 00:38:38 +03:00
import { SecuritySchemesModel } from './models/SecuritySchemes';
2018-01-22 21:30:53 +03:00
import { OpenAPIParser } from './OpenAPIParser';
import { RedocNormalizedOptions } from './RedocNormalizedOptions';
2017-10-12 00:01:37 +03:00
/**
2019-12-10 09:13:37 +03:00
* Store that contains all the specification related information in the form of tree
2017-10-12 00:01:37 +03:00
*/
export class SpecStore {
2018-07-26 17:34:44 +03:00
parser: OpenAPIParser;
info: ApiInfoModel;
externalDocs?: OpenAPIExternalDocumentation;
2018-08-16 12:36:51 +03:00
contentItems: ContentItemModel[];
2018-07-26 17:34:44 +03:00
securitySchemes: SecuritySchemesModel;
2020-08-14 16:33:25 +03:00
webhooks?: WebhookModel;
2017-10-12 00:01:37 +03:00
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);
2018-07-26 17:34:44 +03:00
this.info = new ApiInfoModel(this.parser);
this.externalDocs = this.parser.spec.externalDocs;
2018-08-16 12:36:51 +03:00
this.contentItems = MenuBuilder.buildStructure(this.parser, this.options);
2018-07-26 17:34:44 +03:00
this.securitySchemes = new SecuritySchemesModel(this.parser);
const webhookPath: Referenced<OpenAPIPath> = {
...this.parser?.spec?.['x-webhooks'],
...this.parser?.spec.webhooks,
};
this.webhooks = new WebhookModel(this.parser, options, webhookPath);
2017-10-12 00:01:37 +03:00
}
}