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

RAML - Swagger url support in converter. #3

Open
wants to merge 59 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
dc3105a
Url support in converter.
Jan 10, 2017
e462864
Update README.md
agustinlg Jan 11, 2017
cff7644
DESIGNER-250 Fixes additionalProperties raml definition
Jan 11, 2017
5275223
DESIGNER-251 Adds oas-schema-title and oas-property-title annotations
Jan 12, 2017
322f04b
DESIGNER-252 Fixes date-only values with common errors
Jan 12, 2017
bca8178
Add mode parameter to parser bin script
Jan 12, 2017
f428c88
DESIGNER-255 Fixes property named 'facet' bug
Jan 12, 2017
c52e3ea
DESIGNER-256 Fixes body inline schema bug
Jan 13, 2017
2c2dd22
Removes innecesary displayName for uri parameters. Generates new raml…
Jan 13, 2017
ddfa8c9
DESIGNER-257 Fixes properties named '' or 'additionalProperties' bug
Jan 13, 2017
99c022d
Modified bin scripts
Jan 16, 2017
bd042af
Import functional spec examples
Jan 16, 2017
2904c25
Import functional spec examples
Jan 16, 2017
c91715b
SE-5090 additionalProperties convertion to RAML
Jan 17, 2017
e5975b7
Added raml examples and ignored test for raml to swagger conversion
Jan 17, 2017
2dfd7de
Import functional spec examples
Jan 17, 2017
bdf7bb8
Updates some apiguru apis
Jan 17, 2017
7b26bc1
DESIGNER-258 Replaces annotations for facets definitions in certain p…
Jan 18, 2017
a20293d
Tag version 0.1.0
Jan 18, 2017
b8989b5
DESIGNER-260 Raml to Swagger header type missing in exported Swagger
Jan 19, 2017
157f791
DESIGNER-261 Fixes item´s type convertion to swagger
Jan 19, 2017
61b7bc3
DESIGNER-262 Bump raml parser to 1.1.13
Jan 19, 2017
1d51449
Generates some files of raml-to-swagger test
Jan 20, 2017
3634732
Validate only import or export
Jan 21, 2017
0fe3a18
DESIGNER-282 Raml to Swagger, Swagger does not allow required propert…
Jan 23, 2017
15c6feb
DESIGNER-237: raml to oas : traits are converted as global parameters…
Jan 24, 2017
6fec3b7
Export functional spec examples
Jan 24, 2017
e760943
Export functional spec examples
Jan 24, 2017
552a02a
Export functional spec examples
Jan 24, 2017
a33e7fb
DESIGNER-285 Raml to Swagger - required in Swagger schema should be a…
Jan 24, 2017
edab7dc
DESIGNER-231: remove empty description attribute from OAS info node
Jan 24, 2017
c741ac4
DESIGNER-231: remove empty description attribute from OAS parameter node
Jan 24, 2017
9b20b57
DESIGNER-61: raml to swagger : resources order should be the same whe…
Jan 24, 2017
3fda30f
Export functional spec examples
Jan 24, 2017
e65bd37
avoid allOf attribute if all elements are the same
Jan 25, 2017
0e0303c
modify usage of let and const
Jan 25, 2017
2c3bec3
DESIGNER-279 Union types convertion
Jan 25, 2017
d1bc758
Export functional spec examples
Jan 25, 2017
fda63b9
DESIGNER-289 Multiple examples convertion
Jan 25, 2017
4c83cfb
Fixes importing items of type object in raml and adds excluded apis
Jan 26, 2017
3c5a3ad
move method to static
Jan 25, 2017
fa4f50b
DESIGNER-287: from oas to raml: convert OAS facets to Raml annotations
Jan 26, 2017
8c95e46
fix func-spec-example-20.yaml test file
Jan 26, 2017
baa5413
remove empty definitions attribute when empty
Jan 26, 2017
60bd066
remove postman and stoplight support
Jan 26, 2017
3d51764
remove unused declarations
Jan 26, 2017
6c89c07
Fixing AUTO when using a fsResolver
Jan 26, 2017
f1b9a37
DESIGNER-291 Removes 'date' from raml scalar types
Jan 26, 2017
af0a0f2
next version
Jan 26, 2017
715a261
add custom attribute to keep original type definition when it convert…
Jan 26, 2017
932bfb4
DESIGNER-295 Additional properties with pattern convertion
Jan 27, 2017
efaf5b4
oas to raml: add allOf inline response definition test file
Jan 27, 2017
8402417
DESIGNER-289 Adds x-raml-example-name facet
Jan 27, 2017
7261d74
DESIGNER-290 From Raml to Swagger, items should not reference an own …
Jan 30, 2017
cd63733
DESIGNER-299: raml to swagger : wrong convertion when union type is u…
Jan 30, 2017
041e6a8
Fixes issue with baseraml importer - Path parameters lost when declar…
Jan 30, 2017
adea4b6
change swagger output test file to yaml format
Jan 30, 2017
c5185e1
DESIGNER-300 Examples convertions
Jan 31, 2017
4935f2e
Url support in converter.
Jan 10, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@ test/data/temp.json
temp.json
.idea
.DS_Store
*.iml
/npm-debug.log
11 changes: 11 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
node_modules
coverage
example/target
test/data/temp.json
temp.json
.idea
.DS_Store
/npm-debug.log

site
test
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ This package helps to convert between different API specifications. It was origi

## Supported Conversions (beta)

- OAS (Swagger 2.0) -> RAML 1.0: [Complete Functional Specification](https://docs.google.com/a/tekgenesis.com/document/d/1LNDz9XrkfkPYILZwpgVytNs4WmLvNga81Ua4jdUWltk/pub)
- RAML 1.0 -> OAS (Swagger 2.0): [Complete Functional Specification](https://docs.google.com/a/tekgenesis.com/document/d/1UzRyR_46oc3bEyWoo3ONzfI7wWIH5LCVFxtJZLlvykY/pub)
- OAS (Swagger 2.0) -> RAML 1.0: [Complete Functional Specification](https://docs.google.com/a/tekgenesis.com/document/d/1LNDz9XrkfkPYILZwpgVytNs4WmLvNga81Ua4jdUWltk/view)
- RAML 1.0 -> OAS (Swagger 2.0): [Complete Functional Specification](https://docs.google.com/a/tekgenesis.com/document/d/1UzRyR_46oc3bEyWoo3ONzfI7wWIH5LCVFxtJZLlvykY/view)
- RAML 0.8 -> OAS (Swagger 2.0)
- RAML 0.8 -> RAML 1.0

Expand Down Expand Up @@ -86,7 +86,9 @@ swaggerToRaml.convertData(mySwaggerString).then(function(raml) {

```js
var options = {
validate: false, // Parse the output to check that its a valid document
validate: false, // Parse both input and output to check that its a valid document
validateImport: false, // Only validate input
validateExport: false, // Only validate output
format: 'yaml', // Output format: json (default for OAS) or yaml (default for RAML)
fs: { ... } // Use a custom file system solver (not yet available)
};
Expand Down
21 changes: 20 additions & 1 deletion lib/bin/converter.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ const program = require('commander')
const util = require('./util')
const formats = require('../formats')
const specConverter = require('../../index')
const urlHelper = require('../../lib/utils/url')

let from = formats.AUTO
let to = formats.RAML10
let validate = false
let file = undefined
let options = {'validate': validate}

program
.arguments('<file>')
Expand All @@ -32,7 +34,24 @@ program

if (typeof file === 'undefined') util.exit('File path required. See --help.')

if (urlHelper.isURL(file)) {
options['httpResolver'] = {
getResource: function(path){
return {'errorMessage': 'Method not allowed for URL ' + path + ' , only getResourceAsync'};
},
getResourceAsync: function(path){
return new Promise(function(resolve, reject){
urlHelper.get(path).then(function(response){
resolve({content: response});
}).catch(function(error) {
reject({'errorMessage':'Error getting ' + path, 'error': error});
});
});
}
};
}

const converter = new specConverter.Converter(from, to)
converter.convertFile(file, {validate: validate}).then(result =>
converter.convertFile(file, options).then(result =>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change only intends to add support for a url in the command line right?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, yes if you pass URL get the conversion from RAML

console.log(util.stringify(result))
).catch(util.exit)
2 changes: 1 addition & 1 deletion lib/bin/download-apiguru-apis.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const slugify = require('slugify')
const util = require('./util')
const urlHelper = require('../../lib/utils/url')

const baseDir = __dirname + '/../../test/data/apis-guru/swagger'
const baseDir = __dirname + '../../../test/data/apis-guru/swagger'
const baseUrl = 'https://api.apis.guru/v2/specs/'

urlHelper.get('https://api.apis.guru/v2/list.json').then((body) => {
Expand Down
73 changes: 41 additions & 32 deletions lib/bin/raml-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,49 +4,58 @@ const parser = require('raml-1-parser')
const util = require('./util')

let expand = true
let mode = '0'
let file = undefined

program
.arguments('<file>')
.option('-e, --expand <expand>', 'whether to expand (default) or not')
.option('-m, --mode <mode>', 'Mode 0 (default): reject on errors. Mode 1: get errors from json.')
.action(f => {
file = f
if (typeof program.expand !== 'undefined')
expand = program.expand
if (typeof program.mode !== 'undefined')
mode = program.mode
})
.parse(process.argv)

if (typeof file === 'undefined') util.exit('File path required. See --help.')

parser.loadApi(file, {
attributeDefaults: false,
rejectOnErrors: true
}).then((api) => {
if (expand && api.expand) api = api.expand(true)
const json = api.toJSON({serializeMetadata: false});
console.log(util.stringify(json))
}).catch(util.exit)

/* Using json:
parser.loadApi(file, {
attributeDefaults: false,
rejectOnErrors: false
}).then((api) => {

if (expand && api.expand) api = api.expand(true)

const json = api.toJSON({
serializeMetadata: false,
dumpSchemaContents: false,
rootNodeDetails: true
});

if (json.errors && json.errors.length)
console.error(util.stringify(json.errors))
else
console.log(util.stringify(json.specification))

}).catch((errors) => {
console.error(util.stringify(errors))
})
*/
switch (mode) {
case '1':
parser.loadApi(file, {
attributeDefaults: false,
rejectOnErrors: false
}).then((api) => {
if (expand && api.expand) api = api.expand(true)

const json = api.toJSON({
serializeMetadata: false,
dumpSchemaContents: false,
rootNodeDetails: true
});

if (json.errors && json.errors.length)
util.exit(json.errors)
else
console.log(util.stringify(json.specification))

}).catch(util.exit)
break;
default:
parser.loadApi(file, {
attributeDefaults: false,
rejectOnErrors: true
}).then((api) => {
if (expand && api.expand) api = api.expand(true)

const json = api.toJSON({
serializeMetadata: false
});

console.log(util.stringify(json))

}).catch(util.exit)
break;
}
2 changes: 1 addition & 1 deletion lib/entities/endpoint.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ class Endpoint {
}

set SLData(data) {
for (let key in data) {
for (const key in data) {
if (!data.hasOwnProperty(key)) continue;
this[key] = data[key];
}
Expand Down
8 changes: 0 additions & 8 deletions lib/entities/environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,6 @@ class Environment {
// this.securitySchemes[key] = securityScheme;
// };

loadSLData(envData) {
for (let key in envData) {
if (!envData.hasOwnProperty(key)) continue;
//direct map supported keys
this[key] = envData[key];
}
}

toJSON() {
return {
groups: this.resourcesOrder
Expand Down
4 changes: 0 additions & 4 deletions lib/entities/project.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,6 @@ class Project {
this.savedEntries.push(savedEntry);
}

loadSLData(slData) {
this.Description = slData.description;
}

addPathParamRef(path, paramName) {
this.pathParamsRef[path] = paramName;
}
Expand Down
48 changes: 0 additions & 48 deletions lib/entities/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,6 @@ class Schema {
this.name = '';
this.namespace = namespace;
this.definition = '';
this.example = '';
this.summary = '';
this.description = '';
this.public = true;
}

get Id() {
return this._id;
}

set Id(id) {
this._id = id;
}

get Name() {
Expand All @@ -36,42 +24,6 @@ class Schema {
get Definition() {
return this.definition;
}

get Example() {
return this.example;
}

set SLData(schemaData) {
let sd = schemaData || {};
this.name = sd.name || '';
this.definition = sd.definition || {};
this.example = sd.example || {};
this._id = sd._id;
}

get Summary() {
return this.summary || '';
}

set Summary(summary) {
this.summary = summary;
}

get Description() {
return this.description;
}

set Description(desc) {
this.description = desc;
}

get Public() {
return this.public;
}

set Public(p) {
this.public = p;
}
}

module.exports = Schema;
7 changes: 4 additions & 3 deletions lib/entities/swagger/definition.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ class SwaggerDefinition {
this.swagger = '2.0';
this.info = {
'version': '',
'title': title,
'description': description
'title': title
};
if (description) {
this.info['description'] = description;
}
this.host = '';
this.basePath = '';
this.schemes = [];
Expand All @@ -16,7 +18,6 @@ class SwaggerDefinition {
this.paths = {};
this.parameters = {};
this.responses = [];
this.definitions = {};
}

set BasePath(basePath) {
Expand Down
42 changes: 0 additions & 42 deletions lib/entities/swagger/method.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,48 +17,6 @@ class Method {
this.responses = this.method.responses || this.methodResolved.responses;
this.security = this.method.security || this.methodResolved.security;
}

get Summary() {
return this.summary;
}

get Tags() {
return this.tags;
}

get Description() {
return this.description;
}

get Deprecated() {
return this.deprecated;
}

// get OperationId() { return this.operationId; };
get ExternalDocs() {
return this.externalDocs;
}

// get Schemes() { return this.schemes; };
get Parameters() {
return this.parameters;
}

get Consumes() {
return this.consumes;
}

get Produces() {
return this.produces;
}

get Responses() {
return this.responses;
}

get Security() {
return this.security;
}
}

module.exports = Method;
Loading