Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix incorrect openapi type for datetime, date and password #8334

Merged
merged 6 commits into from
Oct 16, 2020
Merged
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 21 additions & 0 deletions packages/strapi-plugin-documentation/services/Documentation.js
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,7 @@ module.exports = {
} else {
acc.properties[current] = {
type,
format: this.getFormat(attribute.type),
description,
default: defaultValue,
minimum,
Expand Down Expand Up @@ -1456,6 +1457,8 @@ module.exports = {
case 'text':
case 'enumeration':
case 'date':
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to remove password and date. Just to add datetime here :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@henrych4 You forgot to add datetime :)

case 'datetime':
case 'time':
case 'richtext':
return 'string';
case 'float':
Expand All @@ -1473,6 +1476,24 @@ module.exports = {
}
},

/**
* Refer to https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.0.md#dataTypes
* @param {String} type
* @returns {String}
*/
getFormat: type => {
switch (type) {
case 'date':
return 'date';
case 'datetime':
return 'date-time';
case 'password':
return 'password';
default:
return undefined;
}
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you make the handling of date and password explicit please? And make the default value undefined as the function would be wrong for other types.

Something like:

  getFormat: type => {
    switch (type) {
      case 'date':
        return 'date';
      case 'datetime':
        return 'date-time';
      case 'password':
        return 'password';
      default:
        return undefined;
    }
  },


getPluginDefaultVerbDocumentation: function(pluginName, docName, routePath, verb) {
try {
const documentation = JSON.parse(
Expand Down