mirror of
https://github.com/strapi/strapi.git
synced 2025-07-13 12:02:10 +00:00
44 lines
980 B
JavaScript
44 lines
980 B
JavaScript
'use strict';
|
|
|
|
const cleanSchemaAttributes = require('../clean-schema-attributes');
|
|
|
|
/**
|
|
*
|
|
* @param {object} attributes - The attributes found on a contentType
|
|
* @param {object} route - The current route
|
|
*
|
|
* @returns The Swagger requestBody
|
|
*/
|
|
module.exports = (attributes, route) => {
|
|
const requiredAttributes = Object.entries(attributes)
|
|
.filter(([, val]) => {
|
|
return val.required;
|
|
})
|
|
.map(([attr, val]) => {
|
|
return { [attr]: val };
|
|
});
|
|
|
|
const requestAttributes =
|
|
route.method === 'POST' && requiredAttributes.length
|
|
? Object.assign({}, ...requiredAttributes)
|
|
: attributes;
|
|
|
|
return {
|
|
requestBody: {
|
|
required: true,
|
|
content: {
|
|
'application/json': {
|
|
schema: {
|
|
properties: {
|
|
data: {
|
|
type: 'object',
|
|
properties: cleanSchemaAttributes(requestAttributes),
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
};
|
|
};
|