Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
api-spec-converter
Advanced tools
Readme
Convert between API description formats such as Swagger and RAML
Currently only supports conversion to OpenAPI(fka Swagger) 2.0 format, and from OpenAPI 2.0 to OpenAPI 3.0.x
You can also use the online version at https://lucybot-inc.github.io/api-spec-converter/.
Problems? See issue #132
npm install -g api-spec-converter
npm install --save api-spec-converter
$ api-spec-converter -h
Usage: api-spec-converter [options] <URL|filename>
Convert API descriptions between popular formats.
Supported formats:
* swagger_1
* swagger_2
* openapi_3
* api_blueprint
* io_docs
* google
* raml
* wadl
Options:
-h, --help output usage information
-V, --version output the version number
-f, --from <format> Specifies format to convert
-t, --to <format> Specifies output format
-s, --syntax [syntax] Specifies output data syntax: json or yaml. Defaults to json
-o, --order [sortOrder] Specifies top fields ordering: openapi or alpha. Defaults to openapi
-c, --check Check if result is valid spec
-d, --dummy Fill missing required fields with dummy data
Example:
$ api-spec-converter --from=swagger_1 --to=swagger_2 --syntax=yaml --order=alpha https://raw.githubusercontent.com/LucyBot-Inc/api-spec-converter/master/test/input/swagger_1/petstore/pet.json > swagger.json
from
- source format (see formats below)to
- desired format (see formats below)source
- Filename, URL, or JS object for the sourcevar Converter = require('api-spec-converter');
Converter.convert({
from: 'swagger_1',
to: 'swagger_2',
source: 'https://api.gettyimages.com/swagger/api-docs',
}, function(err, converted) {
console.log(converted.stringify());
// For yaml and/or OpenApi field order output replace above line
// with an options object like below
// var options = {syntax: 'yaml', order: 'openapi'}
// console.log(converted.stringify(options));
})
This library has full support for both callback and promises. All async functions return promises but also will execute callback if provided.
var Converter = require('api-spec-converter');
Converter.convert({
from: 'swagger_1',
to: 'swagger_2',
source: 'https://api.gettyimages.com/swagger/api-docs',
})
.then(function(converted) {
console.log(converted.stringify());
});
var Converter = require('api-spec-converter');
Converter.convert({
from: 'swagger_1',
to: 'swagger_2',
source: 'https://api.gettyimages.com/swagger/api-docs',
})
.then(function(converted) {
// [Optional] Fill missing fields with dummy values
converted.fillMissing();
// [Optional] Validate converted spec
return converted.validate()
.then(function (result) {
if (result.errors)
return console.error(JSON.stringify(errors, null, 2));
if (result.warnings)
return console.error(JSON.stringify(warnings, null, 2));
fs.writeFileSync('swagger2.json', converted.stringify());
});
});
<script src="node_modules/api-spec-converter/dist/api-spec-converter.js"></script>
APISpecConverter.convert(...)
from: | swagger_1 | swagger_2 | openapi_3 | io_docs | api_blueprint | raml | wadl | |
---|---|---|---|---|---|---|---|---|
to swagger_1 | n/a | |||||||
to swagger_2 | :white_check_mark: | n/a | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
to openapi_3 | :eight_spoked_asterisk: | :white_check_mark: | n/a | :eight_spoked_asterisk: | :eight_spoked_asterisk: | :eight_spoked_asterisk: | :eight_spoked_asterisk: | :eight_spoked_asterisk: |
to io_docs | n/a | |||||||
to api_blueprint | n/a | |||||||
to google | n/a | |||||||
to raml | n/a | |||||||
to wadl | n/a |
Contributions are welcome and encouraged.
Please add a test case if you're adding features or fixing bugs. To run the tests:
npm test
In case you need to override the expected outputs, due to a justified and verified change, run this:
WRITE_GOLDEN=true npm test
npm run browserify
git commit -a -m "Build browser distribution"
npm version minor # or major/patch
npm publish
git push --follow-tags
FAQs
Convert API descriptions between popular formats such as OpenAPI(fka Swagger), RAML, API Blueprint, WADL, etc.
The npm package api-spec-converter receives a total of 18,110 weekly downloads. As such, api-spec-converter popularity was classified as popular.
We found that api-spec-converter demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.