mirror of
https://github.com/usebruno/bruno.git
synced 2025-06-25 22:41:30 +02:00
build entire json object for request and only support first requestBody content type
This commit is contained in:
parent
35db296c1f
commit
36ee1f542a
@ -20,6 +20,21 @@ const ensureUrl = (url) => {
|
|||||||
return protUrl.replace(/([^:]\/)\/+/g, '$1');
|
return protUrl.replace(/([^:]\/)\/+/g, '$1');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const buildEmptyJsonBody = (bodySchema) => {
|
||||||
|
let _jsonBody = {};
|
||||||
|
each(bodySchema.properties || {}, (prop, name) => {
|
||||||
|
if (prop.type === 'object') {
|
||||||
|
_jsonBody[name] = buildEmptyJsonBody(prop);
|
||||||
|
// handle arrays
|
||||||
|
} else if (prop.type === 'array') {
|
||||||
|
_jsonBody[name] = [];
|
||||||
|
} else {
|
||||||
|
_jsonBody[name] = '';
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return _jsonBody;
|
||||||
|
};
|
||||||
|
|
||||||
const transformOpenapiRequestItem = (request) => {
|
const transformOpenapiRequestItem = (request) => {
|
||||||
let _operationObject = request.operationObject;
|
let _operationObject = request.operationObject;
|
||||||
const brunoRequestItem = {
|
const brunoRequestItem = {
|
||||||
@ -102,20 +117,19 @@ const transformOpenapiRequestItem = (request) => {
|
|||||||
// TODO: handle allOf/anyOf/oneOf
|
// TODO: handle allOf/anyOf/oneOf
|
||||||
if (_operationObject.requestBody) {
|
if (_operationObject.requestBody) {
|
||||||
let content = get(_operationObject, 'requestBody.content', {});
|
let content = get(_operationObject, 'requestBody.content', {});
|
||||||
Object.entries(content).forEach(([mimeType, body]) => {
|
let mimeType = Object.keys(content)[0];
|
||||||
|
let body = content[mimeType] || {};
|
||||||
|
let bodySchema = body.schema;
|
||||||
if (mimeType === 'application/json') {
|
if (mimeType === 'application/json') {
|
||||||
brunoRequestItem.request.body.mode = 'json';
|
brunoRequestItem.request.body.mode = 'json';
|
||||||
if (body.schema && body.schema.type === 'object') {
|
if (bodySchema && bodySchema.type === 'object') {
|
||||||
let _jsonBody = {};
|
let _jsonBody = buildEmptyJsonBody(bodySchema);
|
||||||
each(body.schema.properties || {}, (prop, name) => {
|
|
||||||
_jsonBody[name] = '';
|
|
||||||
});
|
|
||||||
brunoRequestItem.request.body.json = JSON.stringify(_jsonBody, null, 2);
|
brunoRequestItem.request.body.json = JSON.stringify(_jsonBody, null, 2);
|
||||||
}
|
}
|
||||||
} else if (mimeType === 'application/x-www-form-urlencoded') {
|
} else if (mimeType === 'application/x-www-form-urlencoded') {
|
||||||
brunoRequestItem.request.body.mode = 'formUrlEncoded';
|
brunoRequestItem.request.body.mode = 'formUrlEncoded';
|
||||||
if (body.schema && body.schema.type === 'object') {
|
if (bodySchema && bodySchema.type === 'object') {
|
||||||
each(body.schema.properties || {}, (prop, name) => {
|
each(bodySchema.properties || {}, (prop, name) => {
|
||||||
brunoRequestItem.request.body.formUrlEncoded.push({
|
brunoRequestItem.request.body.formUrlEncoded.push({
|
||||||
uid: uuid(),
|
uid: uuid(),
|
||||||
name: name,
|
name: name,
|
||||||
@ -127,8 +141,8 @@ const transformOpenapiRequestItem = (request) => {
|
|||||||
}
|
}
|
||||||
} else if (mimeType === 'multipart/form-data') {
|
} else if (mimeType === 'multipart/form-data') {
|
||||||
brunoRequestItem.request.body.mode = 'multipartForm';
|
brunoRequestItem.request.body.mode = 'multipartForm';
|
||||||
if (body.schema && body.schema.type === 'object') {
|
if (bodySchema && bodySchema.type === 'object') {
|
||||||
each(body.schema.properties || {}, (prop, name) => {
|
each(bodySchema.properties || {}, (prop, name) => {
|
||||||
brunoRequestItem.request.body.multipartForm.push({
|
brunoRequestItem.request.body.multipartForm.push({
|
||||||
uid: uuid(),
|
uid: uuid(),
|
||||||
name: name,
|
name: name,
|
||||||
@ -145,7 +159,6 @@ const transformOpenapiRequestItem = (request) => {
|
|||||||
brunoRequestItem.request.body.mode = 'xml';
|
brunoRequestItem.request.body.mode = 'xml';
|
||||||
brunoRequestItem.request.body.xml = '';
|
brunoRequestItem.request.body.xml = '';
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return brunoRequestItem;
|
return brunoRequestItem;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user