Skip to content
This repository has been archived by the owner on Sep 6, 2019. It is now read-only.

Allow the convertFile to retrieve RAML definition from URL instead of only physical file #19

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions src/raml/ramlConverter.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const toJSONOptions = { serializeMetadata: false, sourceMap: true };
const RamlErrorModel = require('../helpers/ramlErrorModel');
const jsonHelper = require('../utils/json');
const path = require('path');
const urlHelper = require('../utils/url');

class RamlConverter extends Converter {

Expand All @@ -40,16 +41,20 @@ class RamlConverter extends Converter {

_loadFile(filePath:string, options:any) {
this.filePath = filePath;
const fileContent = fs.readFileSync(filePath, 'utf8');

this.format = RamlConverter.detectFormat(fileContent);
if (!urlHelper.isURL(filePath)) {
const fileContent = fs.readFileSync(filePath, 'utf8');
this.format = RamlConverter.detectFormat(fileContent);
}
return new Promise((resolve, reject) => {
parser.loadApi(filePath, Converter._options(options)).then((api) => {
try {
const errors = api.errors();
if (!_.isEmpty(errors)) this.errors = jsonHelper.parse(errors);
this.data = api.expand(true).toJSON(toJSONOptions);
this._removeSourceMapLocalRef(this.data, path.basename(filePath));
if (urlHelper.isURL(filePath)) {
this.format = api.RAMLVersion();
}
resolve();
}
catch (e) {
Expand Down