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

Commit

Permalink
Detect URL when converting from a file
Browse files Browse the repository at this point in the history
  • Loading branch information
Okhoshi authored and Quentin Devos committed Mar 1, 2018
1 parent 93b000b commit 93ce968
Showing 1 changed file with 8 additions and 3 deletions.
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

0 comments on commit 93ce968

Please sign in to comment.