Skip to content

Commit

Permalink
Fix URLs with body fields
Browse files Browse the repository at this point in the history
  • Loading branch information
Pupix committed Jul 27, 2018
1 parent 8b062d9 commit c338d91
Show file tree
Hide file tree
Showing 2 changed files with 133 additions and 8 deletions.
139 changes: 132 additions & 7 deletions createSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ module.exports = async ({ address, port, username, password, protocol }) => {
helpFull.types = types;
helpFull.events = events;

const help = mixin(helpConsole, helpFull);
const help = mixin({}, helpConsole, helpFull);

Object.keys(help.types).forEach(type => {
swagger.definitions[type] = {};
Expand Down Expand Up @@ -251,13 +251,138 @@ module.exports = async ({ address, port, username, password, protocol }) => {
}

result[method.toLowerCase()].parameters = funcDef.arguments.map((argument) => {
const isPathParameter = new RegExp(`{${argument.name}}`).test(funcDef.url);
return {
in: isPathParameter ? 'path' : 'header',
let argumentLocation = 'body';

if (new RegExp(`{${argument.name}}`).test(funcDef.url)) {
argumentLocation = 'path';
// These are the only known header arguments
} else if (['JWT', 'if-none-match'].includes(argument.name)) {
argumentLocation = 'header';
}

const parameter = {
in: argumentLocation,
name: argument.name,
required: !argument.optional,
type: argument.type.type
required: !argument.optional
};

if (/^u?int/.test(argument.type.type)) {
parameter.format = argument.type.type;
parameter.type = 'integer';
return parameter;
}

// Check if the type of the field is a double
if (argument.type.type === 'string') {
parameter.type = argument.type.type;
}

// Check if the type of the field is a double
if (argument.type.type === 'double' || argument.type.type === 'float') {
parameter.format = argument.type.type;
parameter.type = 'number';
return parameter;
}

// Check if the type of the field is signed as `object`
if (argument.type.type === 'object') {
parameter.additionalProperties = true;
parameter.type = argument.type.type;
return parameter;
}

// Check if the type of the field is signed as `boolean`
if (argument.type.type === 'bool') {
parameter.type = 'boolean';
return parameter;
}

if (argument.type.type === 'map') {
parameter.type = 'object';

if (argument.type.elementType === 'object') {
parameter.additionalProperties = {
additionalProperties: true,
type: 'object'
};
return parameter;
}

if (argument.type.elementType === 'string') {
parameter.additionalProperties = {
type: 'string'
};
return parameter;
}

if (/^u?int/.test(argument.type.elementType)) {
parameter.additionalProperties = {
format: argument.type.elementType,
type: 'integer'
};
return parameter;
}

if (argument.type.elementType === 'double' || argument.type.elementType === 'float') {
parameter.additionalProperties = {
format: argument.type.elementType,
type: 'number'
};
return parameter;
}

parameter.additionalProperties = {
$ref: `#/definitions/${argument.type.elementType}`,
};

return parameter;
}

if (argument.type.type === 'vector') {
parameter.type = 'array';

if (argument.type.elementType === 'object') {
parameter.items = {
additionalProperties: true,
type: 'object'
};
return parameter;
}

if (argument.type.elementType === 'string') {
parameter.items = {
type: 'string'
};
return parameter;
}

if (/^u?int/.test(argument.type.elementType)) {
parameter.items = {
format: argument.type.elementType,
type: 'integer'
};
return parameter;
}

if (argument.type.elementType === 'double' || argument.type.elementType === 'float') {
parameter.items = {
format: argument.type.elementType,
type: 'number'
};
return parameter;
}

parameter.items = {
$ref: `#/definitions/${argument.type.elementType}`,
};

return parameter;
}

parameter.schema = { $ref: `#/definitions/${argument.type.type}` };
delete parameter.type;

return parameter;
});

if (funcDef.http_method === 'GET' || funcDef.http_method === 'POST') {
Expand Down Expand Up @@ -564,4 +689,4 @@ module.exports = async ({ address, port, username, password, protocol }) => {
swagger.paths = functions;

return swagger;
};
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rift-explorer",
"version": "2.0.0",
"version": "2.0.1",
"description": "Explore the API of the League of Legends client",
"main": "app.js",
"scripts": {
Expand Down

0 comments on commit c338d91

Please sign in to comment.