main
Last change
on this file was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago |
Initial commit
|
-
Property mode
set to
100644
|
File size:
1.2 KB
|
Line | |
---|
1 | import stampit from 'stampit';
|
---|
2 | import { pick } from 'ramda';
|
---|
3 | import { parse, mediaTypes, detect } from '@swagger-api/apidom-parser-adapter-api-design-systems-json';
|
---|
4 | import ParserError from "../../../errors/ParserError.mjs";
|
---|
5 | import Parser from "../Parser.mjs";
|
---|
6 | const ApiDesignSystemsJsonParser = stampit(Parser, {
|
---|
7 | props: {
|
---|
8 | name: 'api-design-systems-json',
|
---|
9 | fileExtensions: ['.json'],
|
---|
10 | mediaTypes
|
---|
11 | },
|
---|
12 | methods: {
|
---|
13 | async canParse(file) {
|
---|
14 | const hasSupportedFileExtension = this.fileExtensions.length === 0 ? true : this.fileExtensions.includes(file.extension);
|
---|
15 | const hasSupportedMediaType = this.mediaTypes.includes(file.mediaType);
|
---|
16 | if (!hasSupportedFileExtension) return false;
|
---|
17 | if (hasSupportedMediaType) return true;
|
---|
18 | if (!hasSupportedMediaType) {
|
---|
19 | return detect(file.toString());
|
---|
20 | }
|
---|
21 | return false;
|
---|
22 | },
|
---|
23 | async parse(file) {
|
---|
24 | const source = file.toString();
|
---|
25 | try {
|
---|
26 | const parserOpts = pick(['sourceMap', 'syntacticAnalysis', 'refractorOpts'], this);
|
---|
27 | return await parse(source, parserOpts);
|
---|
28 | } catch (error) {
|
---|
29 | throw new ParserError(`Error parsing "${file.uri}"`, {
|
---|
30 | cause: error
|
---|
31 | });
|
---|
32 | }
|
---|
33 | }
|
---|
34 | }
|
---|
35 | });
|
---|
36 | export default ApiDesignSystemsJsonParser; |
---|
Note:
See
TracBrowser
for help on using the repository browser.