@strapi/plugin-documentation 4.1.11 → 4.1.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -147,8 +147,10 @@ describe('Build Component Schema', () => {
147
147
 
148
148
  const expectedShape = {
149
149
  type: 'object',
150
+ required: ['data'],
150
151
  properties: {
151
152
  data: {
153
+ required: [],
152
154
  type: 'object',
153
155
  properties: { test: { type: 'string' } },
154
156
  },
@@ -237,6 +239,7 @@ describe('Build Component Schema', () => {
237
239
 
238
240
  const expectedShape = {
239
241
  type: 'object',
242
+ required: ['locale'],
240
243
  properties: { test: { type: 'string' } },
241
244
  };
242
245
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@strapi/plugin-documentation",
3
- "version": "4.1.11",
3
+ "version": "4.1.12",
4
4
  "description": "Create an OpenAPI Document and visualize your API with SWAGGER UI.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -24,8 +24,8 @@
24
24
  "test": "echo \"no tests yet\""
25
25
  },
26
26
  "dependencies": {
27
- "@strapi/helper-plugin": "4.1.11",
28
- "@strapi/utils": "4.1.11",
27
+ "@strapi/helper-plugin": "4.1.12",
28
+ "@strapi/utils": "4.1.12",
29
29
  "bcryptjs": "2.4.3",
30
30
  "cheerio": "^1.0.0-rc.5",
31
31
  "fs-extra": "10.0.0",
@@ -57,5 +57,5 @@
57
57
  "description": "Create an OpenAPI Document and visualize your API with SWAGGER UI.",
58
58
  "kind": "plugin"
59
59
  },
60
- "gitHead": "698ae33e0007811ce24b568cc5d873d7a4d2a832"
60
+ "gitHead": "ab698015cfc4f43fa0ce2ae94ec59e00a67e4cda"
61
61
  }
@@ -48,7 +48,7 @@ module.exports = {
48
48
  properties: {
49
49
  data: {
50
50
  nullable: true,
51
- oneOf: [{ type: 'object' }, { type: 'array' }],
51
+ oneOf: [{ type: 'object' }, { type: 'array', items: [] }],
52
52
  },
53
53
  error: {
54
54
  type: 'object',
@@ -15,10 +15,10 @@ const { hasFindMethod, isLocalizedPath } = require('./utils/routes');
15
15
  * @param {string} routePath - The route's path property
16
16
  * @returns {string}
17
17
  */
18
- const parsePathWithVariables = (routePath) => {
18
+ const parsePathWithVariables = routePath => {
19
19
  return pathToRegexp
20
20
  .parse(routePath)
21
- .map((token) => {
21
+ .map(token => {
22
22
  if (_.isObject(token)) {
23
23
  return token.prefix + '{' + token.name + '}';
24
24
  }
@@ -35,11 +35,11 @@ const parsePathWithVariables = (routePath) => {
35
35
  *
36
36
  * @returns {object } Swagger path params object
37
37
  */
38
- const getPathParams = (routePath) => {
38
+ const getPathParams = routePath => {
39
39
  return pathToRegexp
40
40
  .parse(routePath)
41
- .filter((token) => _.isObject(token))
42
- .map((param) => {
41
+ .filter(token => _.isObject(token))
42
+ .map(param => {
43
43
  return {
44
44
  name: param.name,
45
45
  in: 'path',
@@ -83,7 +83,7 @@ const getPathWithPrefix = (prefix, route) => {
83
83
  */
84
84
  const getPaths = ({ routeInfo, uniqueName, contentTypeInfo }) => {
85
85
  // Get the routes for the current content type
86
- const contentTypeRoutes = routeInfo.routes.filter((route) => {
86
+ const contentTypeRoutes = routeInfo.routes.filter(route => {
87
87
  return (
88
88
  route.path.includes(contentTypeInfo.pluralName) ||
89
89
  route.path.includes(contentTypeInfo.singularName)
@@ -152,7 +152,7 @@ const getPaths = ({ routeInfo, uniqueName, contentTypeInfo }) => {
152
152
  *
153
153
  * @returns {object} Open API paths
154
154
  */
155
- const getAllPathsForContentType = (apiInfo) => {
155
+ const getAllPathsForContentType = apiInfo => {
156
156
  let paths = {};
157
157
 
158
158
  const pathsObject = getPaths(apiInfo);
@@ -175,7 +175,7 @@ const getAllPathsForContentType = (apiInfo) => {
175
175
  *
176
176
  * @returns {object}
177
177
  */
178
- const buildApiEndpointPath = (api) => {
178
+ const buildApiEndpointPath = api => {
179
179
  // A reusable loop for building paths and component schemas
180
180
  // Uses the api param to build a new set of params for each content type
181
181
  // Passes these new params to the function provided
@@ -20,11 +20,9 @@ const getAllSchemasForContentType = ({ routeInfo, attributes, uniqueName }) => {
20
20
  // Store response and request schemas in an object
21
21
  let schemas = {};
22
22
  // Get all the route methods
23
- const routeMethods = routeInfo.routes.map((route) => route.method);
23
+ const routeMethods = routeInfo.routes.map(route => route.method);
24
24
  // Check for localized paths
25
- const hasLocalizationPath = routeInfo.routes.filter((route) =>
26
- isLocalizedPath(route.path)
27
- ).length;
25
+ const hasLocalizationPath = routeInfo.routes.filter(route => isLocalizedPath(route.path)).length;
28
26
  // When the route methods contain any post or put requests
29
27
  if (routeMethods.includes('POST') || routeMethods.includes('PUT')) {
30
28
  const attributesToOmit = [
@@ -38,23 +36,24 @@ const getAllSchemasForContentType = ({ routeInfo, attributes, uniqueName }) => {
38
36
  ];
39
37
  const attributesForRequest = _.omit(attributes, attributesToOmit);
40
38
 
41
- const requiredAttributes = Object.entries(attributesForRequest)
42
- .filter(([, attribute]) => attribute.required)
43
- .map(([attributeName, attribute]) => {
44
- return { [attributeName]: attribute };
45
- });
39
+ // Get a list of required attribute names
40
+ const requiredAttributes = Object.entries(attributesForRequest).reduce((acc, attribute) => {
41
+ const [attributeKey, attributeValue] = attribute;
46
42
 
47
- const requestAttributes =
48
- routeMethods.includes('POST') && requiredAttributes.length
49
- ? Object.assign({}, ...requiredAttributes)
50
- : attributesForRequest;
43
+ if (attributeValue.required) {
44
+ acc.push(attributeKey);
45
+ }
46
+
47
+ return acc;
48
+ }, []);
51
49
 
52
50
  if (hasLocalizationPath) {
53
51
  schemas = {
54
52
  ...schemas,
55
53
  [`${pascalCase(uniqueName)}LocalizationRequest`]: {
54
+ required: [...requiredAttributes, 'locale'],
56
55
  type: 'object',
57
- properties: cleanSchemaAttributes(requestAttributes, { isRequest: true }),
56
+ properties: cleanSchemaAttributes(attributesForRequest, { isRequest: true }),
58
57
  },
59
58
  };
60
59
  }
@@ -64,10 +63,12 @@ const getAllSchemasForContentType = ({ routeInfo, attributes, uniqueName }) => {
64
63
  ...schemas,
65
64
  [`${pascalCase(uniqueName)}Request`]: {
66
65
  type: 'object',
66
+ required: ['data'],
67
67
  properties: {
68
68
  data: {
69
+ required: requiredAttributes,
69
70
  type: 'object',
70
- properties: cleanSchemaAttributes(requestAttributes, { isRequest: true }),
71
+ properties: cleanSchemaAttributes(attributesForRequest, { isRequest: true }),
71
72
  },
72
73
  },
73
74
  },
@@ -88,7 +89,7 @@ const getAllSchemasForContentType = ({ routeInfo, attributes, uniqueName }) => {
88
89
  }
89
90
 
90
91
  // Check for routes that need to return a list
91
- const hasListOfEntities = routeInfo.routes.filter((route) => hasFindMethod(route.handler)).length;
92
+ const hasListOfEntities = routeInfo.routes.filter(route => hasFindMethod(route.handler)).length;
92
93
  if (hasListOfEntities) {
93
94
  // Build the list response schema
94
95
  schemas = {
@@ -143,7 +144,7 @@ const getAllSchemasForContentType = ({ routeInfo, attributes, uniqueName }) => {
143
144
  return schemas;
144
145
  };
145
146
 
146
- const buildComponentSchema = (api) => {
147
+ const buildComponentSchema = api => {
147
148
  // A reusable loop for building paths and component schemas
148
149
  // Uses the api param to build a new set of params for each content type
149
150
  // Passes these new params to the function provided
@@ -113,7 +113,7 @@ const cleanSchemaAttributes = (attributes, { typeMap = new Map(), isRequest = fa
113
113
  break;
114
114
  }
115
115
  case 'dynamiczone': {
116
- const components = attribute.components.map((component) => {
116
+ const components = attribute.components.map(component => {
117
117
  const componentAttributes = strapi.components[component].attributes;
118
118
  return {
119
119
  type: 'object',
@@ -2,7 +2,7 @@
2
2
 
3
3
  const _ = require('lodash');
4
4
 
5
- const pascalCase = (string) => {
5
+ const pascalCase = string => {
6
6
  return _.upperFirst(_.camelCase(string));
7
7
  };
8
8
 
@@ -1,8 +1,8 @@
1
1
  'use strict';
2
2
 
3
- const hasFindMethod = (handler) => handler.split('.').pop() === 'find';
3
+ const hasFindMethod = handler => handler.split('.').pop() === 'find';
4
4
 
5
- const isLocalizedPath = (routePath) => routePath.includes('localizations');
5
+ const isLocalizedPath = routePath => routePath.includes('localizations');
6
6
 
7
7
  module.exports = {
8
8
  isLocalizedPath,