-
-
Notifications
You must be signed in to change notification settings - Fork 106
/
Copy pathinfo.ts
88 lines (69 loc) · 2.45 KB
/
info.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import { BaseModel } from '../base';
import { Contact } from './contact';
import { ExternalDocumentation } from './external-docs';
import { License } from './license';
import { Tags } from './tags';
import { Tag } from './tag';
import { hasDescription, description, extensions } from './mixins';
import type { ContactInterface } from '../contact';
import type { InfoInterface } from '../info';
import type { ExtensionsInterface } from '../extensions';
import type { ExternalDocumentationInterface } from '../external-docs';
import type { LicenseInterface } from '../license';
import type { TagsInterface } from '../tags';
import type { v2 } from '../../spec-types';
export class Info extends BaseModel<v2.InfoObject> implements InfoInterface {
title(): string {
return this._json.title;
}
version(): string {
return this._json.version;
}
hasId(): boolean {
return !!this._meta.asyncapi.parsed.id;
}
id(): string | undefined {
return this._meta.asyncapi.parsed.id;
}
hasDescription(): boolean {
return hasDescription(this);
}
description(): string | undefined {
return description(this);
}
hasTermsOfService(): boolean {
return !!this._json.termsOfService;
}
termsOfService(): string | undefined {
return this._json.termsOfService;
}
hasContact(): boolean {
return Object.keys(this._json.contact || {}).length > 0;
}
contact(): ContactInterface | undefined {
const contact = this._json.contact;
return contact && this.createModel(Contact, contact, { pointer: '/info/contact' });
}
hasLicense(): boolean {
return Object.keys(this._json.license || {}).length > 0;
}
license(): LicenseInterface | undefined {
const license = this._json.license;
return license && this.createModel(License, license, { pointer: '/info/license' });
}
hasExternalDocs(): boolean {
return Object.keys(this._meta.asyncapi.parsed.externalDocs || {}).length > 0;
}
externalDocs(): ExternalDocumentationInterface | undefined {
if (this.hasExternalDocs()) {
return this.createModel(ExternalDocumentation, this._meta.asyncapi.parsed.externalDocs as v2.ExternalDocumentationObject, { pointer: '/externalDocs' });
}
}
tags(): TagsInterface {
const tags = this._meta.asyncapi.parsed.tags || [];
return new Tags(tags.map((tag: any, idx: number) => this.createModel(Tag, tag, { pointer: `/tags/${idx}` })));
}
extensions(): ExtensionsInterface {
return extensions(this);
}
}