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

openapi: Fix generated types for duration strings #20841

Merged
merged 3 commits into from
Jun 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions changelog/20841.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:improvement
openapi: Fix generated types for duration strings
```
4 changes: 2 additions & 2 deletions sdk/framework/openapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -918,8 +918,8 @@ func convertType(t FieldType) schemaType {
ret.baseType = "integer"
ret.format = "int64"
case TypeDurationSecond, TypeSignedDurationSecond:
ret.baseType = "integer"
ret.format = "seconds"
ret.baseType = "string"
Copy link
Contributor

Choose a reason for hiding this comment

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

don't these endpoints accept both int OR string?

if that's the case, wouldn't it break those passing in ints?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was mostly looking at how these fields are returned in responses today. Do you have an example of where this is used as int or string in a request?

Copy link
Contributor

Choose a reason for hiding this comment

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

there's at least one, still looking for a request, but this is a response that returns int or string
framework.Path
callback fcn

Copy link
Contributor

Choose a reason for hiding this comment

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

couldn't find any requests that handle both int or string, would need to take a closer look

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The sys/rotate/config example you mentioned seems to be a bug where two different types are returned. Unfortunately, it would not be easy to fix, since it would break backwards compatibility.

As far as requests go, I think we should be fine as long as both string and int are accepted. As long as the user provides a string, it should work.

ret.format = "duration"
case TypeBool:
ret.baseType = "boolean"
case TypeMap:
Expand Down