Skip to content

Commit

Permalink
Fix for when language-tabs are simple strings
Browse files Browse the repository at this point in the history
include whiteboard_env.json
refs #46
  • Loading branch information
MikeRalphson committed Sep 28, 2017
1 parent 333e86d commit 24c3625
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# widdershins
OpenApi / Swagger / AsyncAPI definition to [Slate](https://github.com/lord/slate) /
OpenApi / Swagger / AsyncAPI definition to [Slate](https://github.com/lord/slate) /
[Shins](https://github.com/mermade/shins) compatible markdown

![Build](https://img.shields.io/travis/Mermade/widdershins/master.svg) [![Tested on APIs.guru](https://api.apis.guru/badges/tested_on.svg)](https://APIs.guru) [![Tested on Mermade OpenAPIs](https://img.shields.io/badge/Additional%20Specs-419-brightgreen.svg)](https://github.com/mermade/openapi_specifications)
Expand Down Expand Up @@ -74,6 +74,8 @@ To only include a subset of the pre-defined language-tabs, or to rename their di
options.language_tabs = [{ 'http': 'HTTP' }, { 'javascript': 'JavaScript' }, { 'javascript--nodejs': 'Node.JS' }, { 'python': 'Python' }, { 'ruby': 'Ruby' }];
```

If you need to support a version of Slate \<v1.5.0 (or a renderer which also doesn't support display-names for language-tabs, such as `node-slate`, `slate-node` or `whiteboard`), you can use the `--environment` option with the included `whiteboard_env.json` file to simply achieve this.

The `loadedFrom` option is only needed where the OpenApi / Swagger definition does not specify a host, and (as per the OpenApi [specification](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#fixed-fields)) the API endpoint is deemed to be based on the source URL
the definition was loaded from.

Expand Down
6 changes: 3 additions & 3 deletions asyncapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,9 +247,9 @@ function convert(asyncapi, options, callback) {

var target = header.language_tabs[l];
if (typeof target === 'object') {
l = Object.keys(target)[0];
target = Object.keys(target)[0];
}
var lcLang = common.languageCheck(l, header.language_tabs, false);
var lcLang = common.languageCheck(target, header.language_tabs, false);
if (lcLang) {
var templateName = 'code_' + lcLang.substring(lcLang.lastIndexOf('-') + 1);
var templateFunc = templates[templateName];
Expand Down Expand Up @@ -346,7 +346,7 @@ function convert(asyncapi, options, callback) {
data.enums = [];
data.schemaProperties = [];
common.schemaToArray(schema,0,data.schemaProperties,true);

for (let p of data.schemaProperties) {
if (p.schema && p.schema.enum) {
for (let e of p.schema.enum) {
Expand Down
4 changes: 2 additions & 2 deletions openapi3.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,9 +276,9 @@ function processOperation(op, method, resource, options) {

var target = header.language_tabs[l];
if (typeof target === 'object') {
l = Object.keys(target)[0];
target = Object.keys(target)[0];
}
var lcLang = common.languageCheck(l, header.language_tabs, false);
var lcLang = common.languageCheck(target, header.language_tabs, false);
if (lcLang) {
var templateName = 'code_'+lcLang.substring(lcLang.lastIndexOf('-') + 1);
var templateFunc = templates[templateName];
Expand Down
3 changes: 3 additions & 0 deletions whiteboard_env.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"language_tabs": ["shell","http","html","javascript","python","ruby","java"]
}

0 comments on commit 24c3625

Please sign in to comment.