All Downloads are FREE. Search and download functionalities are using the official Maven repository.

package.es.parse.parsers.api-design-systems-yaml.index.mjs Maven / Gradle / Ivy

Go to download

Advanced algorithms for semantic ApiDOM manipulations like dereferencing or resolution.

There is a newer version: 1.0.0-alpha.9
Show newest version
import { pick } from 'ramda';
import { parse, mediaTypes as ADSMediaTypes, detect } from '@swagger-api/apidom-parser-adapter-api-design-systems-yaml';
import ParserError from "../../../errors/ParserError.mjs";
import Parser from "../Parser.mjs";
class APIDesignSystemsYAMLParser extends Parser {
  refractorOpts;
  constructor(options) {
    const {
      fileExtensions = ['.yaml', '.yml'],
      mediaTypes = ADSMediaTypes,
      ...rest
    } = options !== null && options !== void 0 ? options : {};
    super({
      ...rest,
      name: 'api-design-systems-yaml',
      fileExtensions,
      mediaTypes
    });
  }
  async canParse(file) {
    const hasSupportedFileExtension = this.fileExtensions.length === 0 ? true : this.fileExtensions.includes(file.extension);
    const hasSupportedMediaType = this.mediaTypes.includes(file.mediaType);
    if (!hasSupportedFileExtension) return false;
    if (hasSupportedMediaType) return true;
    if (!hasSupportedMediaType) {
      return detect(file.toString());
    }
    return false;
  }
  async parse(file) {
    const source = file.toString();
    try {
      const parserOpts = pick(['sourceMap', 'refractorOpts'], this);
      return await parse(source, parserOpts);
    } catch (error) {
      throw new ParserError(`Error parsing "${file.uri}"`, {
        cause: error
      });
    }
  }
}
export default APIDesignSystemsYAMLParser;




© 2015 - 2025 Weber Informatics LLC | Privacy Policy