Skip to content
This repository has been archived by the owner on Nov 28, 2022. It is now read-only.

Commit

Permalink
Merge pull request #65 from readmeio/feature/form-data
Browse files Browse the repository at this point in the history
Moving functions out of scope to appease codeclimate
  • Loading branch information
domharrington committed Oct 30, 2017
2 parents 277c30e + 3deff75 commit 71961ac
Showing 1 changed file with 50 additions and 50 deletions.
100 changes: 50 additions & 50 deletions packages/api-explorer-ui/src/lib/parameters-to-json-schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,69 +10,69 @@ const types = {
header: 'Headers',
};

module.exports = pathOperation => {
const hasRequestBody = !!pathOperation.requestBody;
const hasParameters = !!(pathOperation.parameters && pathOperation.parameters.length !== 0);
function getBodyParam(pathOperation) {
const schema = getSchema(pathOperation);

if (!hasParameters && !hasRequestBody) return null;
if (!schema) return null;

function getBodyParam() {
const schema = getSchema(pathOperation);
const type = schema.type === 'application/x-www-form-urlencoded' ? 'formData' : 'body';

if (!schema) return null;
return {
type,
label: types[type],
schema: schema.schema,
};
}

const type = schema.type === 'application/x-www-form-urlencoded' ? 'formData' : 'body';
function getOtherParams(pathOperation) {
return Object.keys(types).map(type => {
const required = [];
const parameters = (pathOperation.parameters || []).filter(param => param.in === type);
if (parameters.length === 0) return null;

return {
type,
label: types[type],
schema: schema.schema,
};
}
const properties = parameters.reduce((prev, current) => {
const schema = { type: 'string' };

function getOtherParams() {
return Object.keys(types).map(type => {
const required = [];
const parameters = (pathOperation.parameters || []).filter(param => param.in === type);
if (parameters.length === 0) return null;
if (current.description) schema.description = current.description;

const properties = parameters.reduce((prev, current) => {
const schema = { type: 'string' };
if (current.schema) {
if (current.schema.type === 'array') {
schema.type = 'array';
schema.items = current.schema.items;
}

if (current.description) schema.description = current.description;
if (current.schema.default) schema.default = current.schema.default;
if (current.schema.enum) schema.enum = current.schema.enum;
}

if (current.schema) {
if (current.schema.type === 'array') {
schema.type = 'array';
schema.items = current.schema.items;
}
prev[current.name] = schema;

if (current.schema.default) schema.default = current.schema.default;
if (current.schema.enum) schema.enum = current.schema.enum;
}
if (current.required) {
required.push(current.name);
}

prev[current.name] = schema;
return prev;
}, {});

if (current.required) {
required.push(current.name);
}
return {
type,
label: types[type],
schema: {
type: 'object',
properties,
required,
},
};
});
}

module.exports = pathOperation => {
const hasRequestBody = !!pathOperation.requestBody;
const hasParameters = !!(pathOperation.parameters && pathOperation.parameters.length !== 0);

if (!hasParameters && !hasRequestBody) return null;

return prev;
}, {});

return {
type,
label: types[type],
schema: {
type: 'object',
properties,
required,
},
};
});
}

return [getBodyParam()].concat(...getOtherParams()).filter(Boolean);
return [getBodyParam(pathOperation)].concat(...getOtherParams(pathOperation)).filter(Boolean);
};

// Exported for use in oas-to-har for default values object
Expand Down

0 comments on commit 71961ac

Please sign in to comment.