-
-
Notifications
You must be signed in to change notification settings - Fork 50
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
String parameters with format 'date' get no Format in the QueryAttribute #66
Comments
@brease-colin thanks for taking the time to report this. I was not aware that you could do this with Refit. It looks simple enough and I will try to implement it as soon as possible |
@all-contributors please add @brease-colin for bugs |
I've put up a pull request to add @brease-colin! 🎉 |
Thanks for the quick response (and the library in general)! I looked into the 'time' format some more. The strange thing is that even though it's not listed as an official data type in the Swagger 2.0 and OpenApi 3.0 specs as far as I can tell, it's still converted to a Also, on the models side, a string format of 'date' results in a DateTimeOffset as well, but with a |
@brease-colin I just started looking into this in detail. I'm not sure there is much to be improved here. I'm not sure that its a good idea to generated code that suggests a specific format, like |
The information I can find about the specs on the OpenAPI web site and also referenced for example here mention that an API with type
I do not have much experience with different OpenAPI server software, so I don't know how it's handled in general when a string in the wrong format (i.e. a full DateTime string for a I could understand you may be reluctant to change the default behavior, because for some, this may be a breaking change, but it's a change that would bring it in line with the specs. Personally I would not let the users actually pick a format. If you'd decide to support this and also make it optional, I would expect an argument like |
@brease-colin Thanks for looking into the details of this It's true that it might be a breaking change for some, but since multiple versions of the tool are available from nuget.org, I'm not that afraid of introducing breaking changes. I like the idea of bringing this in line with the OpenAPI specification so I will implement this starting with introducing the |
Does this work for you @brease-colin
The following example OpenAPI spec: {
"swagger": "2.0",
"info": {
"title": "XX",
"version": "0.0.0"
},
"host": "x.io",
"basePath": "/",
"schemes": [
"https"
],
"paths": {
"/t/dummy/{employee_id}": {
"get": {
"summary": "X",
"description": "X",
"operationId": "dummy",
"parameters": [
{
"name": "employee_id",
"in": "path",
"description": "the specific employee",
"required": true,
"format": "int64",
"type": "integer"
},
{
"name": "valid_from",
"in": "query",
"description": "the start of the period",
"required": true,
"format": "date",
"type": "string"
},
{
"name": "valid_to",
"in": "query",
"description": "the end of the period",
"required": true,
"format": "date",
"type": "string"
}
],
"responses": {
"200": {
"description": "No response was specified",
"schema": {
"$ref": "#/definitions/DummyList"
}
}
},
"produces": [
"application/json",
"application/xml"
]
}
},
}
} generates the following code when using the EDITED public interface IXX
{
/// <summary>
/// X
/// </summary>
[Get("/t/dummy/{employee_id}")]
Task Dummy(long employee_id, [Query(Format = "yyyy-MM-dd")] System.DateTimeOffset valid_from, [Query(Format = "yyyy-MM-dd")] System.DateTimeOffset valid_to);
} |
I assume the test_time parameter will not appear out of nowhere (as it's not in the spec you mention), but other than that, looks great! |
Copy/paste error there 😂 |
Describe the bug
When generating a client for an OpenApi (swagger version 2.0) with url (query) parameters of type string with a format of 'date' are generated as a regular DateTimeOffset without a 'Date' format.
Support Key:
mmt1dt0
OpenAPI Specifications
(not the full specs, but this is the gist of it)
Additional context
Resulting code is:
When executing, this results in errors.
Expected code:
The same may be true for other date / time related formats, like 'time'. The same may also be true for entity classes where properties are generated as regular 'DateTimeOffset'.
Ideally, for 'time' and 'date', both the arguments of functions and the properties of entity classes would result in 'TimeOnly' and 'DateOnly', respectively, but I'm not sure if those are fully supported in Refit? I think they are for properties, not sure about function arguments.
Edit: apparently 'time' was no format in OpenApi (Swagger) v2, but 'date' apparently is.
The text was updated successfully, but these errors were encountered: