-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathmedia-types.ts
More file actions
42 lines (35 loc) · 1.1 KB
/
media-types.ts
File metadata and controls
42 lines (35 loc) · 1.1 KB
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
import { last } from 'ramda';
import { MediaTypes } from '@swagger-api/apidom-core';
/**
* @public
*/
export type Format = 'generic' | 'json' | 'yaml';
/**
* @public
*/
export class AsyncAPIMediaTypes extends MediaTypes<string> {
filterByFormat(format: Format = 'generic') {
const effectiveFormat = format === 'generic' ? 'asyncapi;version' : format;
return this.filter((mediaType) => mediaType.includes(effectiveFormat));
}
findBy(version = '3.0.0', format: Format = 'generic') {
const search =
format === 'generic'
? `vnd.aai.asyncapi;version=${version}`
: `vnd.aai.asyncapi+${format};version=${version}`;
const found = this.find((mediaType) => mediaType.includes(search));
return found || this.unknownMediaType;
}
latest(format: Format = 'generic') {
return last(this.filterByFormat(format)) as string;
}
}
/**
* @public
*/
const mediaTypes = new AsyncAPIMediaTypes(
'application/vnd.aai.asyncapi;version=3.0.0',
'application/vnd.aai.asyncapi+json;version=3.0.0',
'application/vnd.aai.asyncapi+yaml;version=3.0.0',
);
export default mediaTypes;