@apistudio/apim-cli
Version:
CLI for API Management Products
50 lines (49 loc) • 1.41 kB
JavaScript
/**
* Copyright Super iPaaS Integration LLC, an IBM Company 2024
*/
import { AppConstants } from '../constants/app-constants.js';
import TypeNotFoundException from '../exeptions/type-not-found-exception.js';
import { isBaseAsset } from './asset.helper.js';
import { isJSON, parseJSON } from './json-helper.js';
import { isOpenAPI, isSwagger } from './rest-api-helper.js';
import { isYAML, loadYaml } from './yaml-helper.js';
export function getDocumentBasedOnLanguage(fileContent, language) {
try {
if ((language === 'yaml') || (language === 'yml')) {
return loadYaml(fileContent);
}
else if (language === 'json') {
return parseJSON(fileContent);
}
else {
return undefined;
}
}
catch (error) {
console.error(error);
}
return undefined;
}
export function getType(data, language) {
let type = undefined;
if (isOpenAPI(data, language) || isSwagger(data, language)) {
type = 'rest';
}
else if (isBaseAsset(data, language)) {
type = 'asset';
}
else {
return new TypeNotFoundException(AppConstants.TYPE_NOT_FOUND_EXCEPTION, 404);
}
return type;
}
export function getLanguage(data) {
let language = '';
if (isJSON(data)) {
language = 'json';
}
else if (isYAML(data)) {
language = 'yaml';
}
return language;
}