Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import Service from '@ember/service';
import RefParser from 'json-schema-ref-parser';
import request from 'ember-ajax/request';
import { task, all, timeout } from 'ember-concurrency';
import { inject as service } from '@ember/service';
import {
// isAjaxError,
isNotFoundError,
// isForbiddenError
} from 'ember-ajax/errors';
import semver from 'semver';
const parser = new RefParser();
export default Service.extend({
init() {
this._super(...arguments);
/**
* Instance of JSON Schema $Ref Parser
*
* @method parser
* @protected
* @return {Object}
*/
this.parser = parser;
},
flashMessages: service(),
fetchSchemas: task(function* (url) {
async function ngOpenApiGen() {
const options = parseOptions();
const refParser = new $RefParser();
const input = options.input;
try {
const openApi = await refParser.bundle(input, { dereference: { circular: false } }) as OpenAPIObject;
const gen = new NgOpenApiGen(openApi, options);
gen.generate();
} catch (err) {
console.error(`Error on API generation from ${input}: ${err}`);
}
}
export async function runNgOpenApiGen() {
const options = parseOptions();
const refParser = new $RefParser();
const input = options.input;
try {
const openApi = await refParser.bundle(input, { dereference: { circular: false } }) as OpenAPIObject;
const gen = new NgOpenApiGen(openApi, options);
gen.generate();
} catch (err) {
console.error(`Error on API generation from ${input}: ${err}`);
}
}
function bundle(
openApiDocFile: string | object,
): Promise {
const refParser = new $RefParser();
return refParser.bundle(
openApiDocFile as any,
{dereference: {circular: false}}
);
}
export default function prepareSpec(spec, options) {
const parser = new RefParser();
const external = !!(options && options.external === true);
return parser.dereference(spec, { external });
}