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

Conversation

henrych4
Copy link
Contributor

Signed-off-by: henrych4 singyinhenry@gmail.com

Description of what you did:

Reopen #7623 and update with respect to the comments to fix #7149

Signed-off-by: henrych4 <singyinhenry@gmail.com>
@henrych4 henrych4 requested a review from a team as a code owner October 14, 2020 14:31
@codecov
Copy link

codecov bot commented Oct 14, 2020

Codecov Report

Merging #8334 into master will decrease coverage by 0.00%.
The diff coverage is 0.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #8334      +/-   ##
==========================================
- Coverage   33.20%   33.19%   -0.01%     
==========================================
  Files        1220     1220              
  Lines       13616    13618       +2     
  Branches     1356     1357       +1     
==========================================
  Hits         4521     4521              
- Misses       8211     8212       +1     
- Partials      884      885       +1     
Flag Coverage Δ
#front 24.72% <ø> (ø)
#unit 54.45% <0.00%> (-0.03%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
packages/strapi-utils/lib/models.js 25.00% <0.00%> (-0.32%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9b62d98...148c4c0. Read the comment docs.

@petersg83 petersg83 self-requested a review October 15, 2020 10:15
Copy link
Contributor

@petersg83 petersg83 left a comment

Choose a reason for hiding this comment

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

Thanks for you contribution ! I have some remarks :)

maxLength,
minLength,
enum: enumeration,
};
Copy link
Contributor

Choose a reason for hiding this comment

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

I would suggest to just modify the else block.
Something like:

        } else {
          acc.properties[current] = {
            type,
            format: getFormat(attribute.type),
            description,
            default: defaultValue,
            minimum,
            maxmimun,
            maxLength,
            minLength,
            enum: enumeration,
          };
        }

(In your code the value of type is 'string' for date and password, so it would not work for those two. The right variable to use would be attribute.type.)

(I think we need to modify the function getType so it handles datetime)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated. Thanks for the comment, the code looks much better now.

default:
return type;
}
},
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;
    }
  },

Signed-off-by: henrych4 <singyinhenry@gmail.com>
case 'email':
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 :)

Signed-off-by: henrych4 <singyinhenry@gmail.com>
Signed-off-by: henrych4 <singyinhenry@gmail.com>
Copy link
Contributor

@petersg83 petersg83 left a comment

Choose a reason for hiding this comment

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

Thank you ! I tested it, it works well :)
While testing I saw that the type time was not handled neither in getType. Can you just add case 'time:' at the same place as case 'datetime' please ? :) No need to update getFormat as doesn't this it has an official format.

Signed-off-by: henrych4 <singyinhenry@gmail.com>
Copy link
Contributor

@petersg83 petersg83 left a comment

Choose a reason for hiding this comment

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

Thank you, nice addition ! :)

@petersg83 petersg83 added source: plugin:documentation Source is plugin/documentation package issue: enhancement Issue suggesting an enhancement to an existing feature labels Oct 16, 2020
@petersg83 petersg83 added this to the 3.2.4 milestone Oct 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
issue: enhancement Issue suggesting an enhancement to an existing feature source: plugin:documentation Source is plugin/documentation package
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Incorrect datetime type generated in the Documentation plugin
3 participants