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

Type of TimeSpan incorrectly inferred as complex object instead of string #401

Closed
basilfx opened this issue Mar 23, 2022 · 5 comments · Fixed by #524
Closed

Type of TimeSpan incorrectly inferred as complex object instead of string #401

basilfx opened this issue Mar 23, 2022 · 5 comments · Fixed by #524
Labels
bug Something isn't working

Comments

@basilfx
Copy link

basilfx commented Mar 23, 2022

Describe the issue
The type that is inferred for a TimeSpan is a complex object. Instead, I would expect a string (something like 1.00:00:00).

A simple HttpTrigger that returns an OkObjectResult serializes a TimeSpan to a string, whereas the extension resolves a complex object for its schema definition. If I am correct, the OkObjectResult uses the Newtonsoft.Json serializer.

I tried to 'override' it using a JsonConverter attribute, but that does not work. Neither does adding [DataType(DataType.Duration)].

To Reproduce
See this demonstration project: https://github.com/basilfx/azure-functions-openapi-function-timespan

Expected behavior
TimeSpan schema type is inferred as a string.

Screenshots
Note how the result is different from the example schema.

Schermafbeelding 2022-03-23 om 22 28 54

Schermafbeelding 2022-03-23 om 22 46 27

Environment (please complete the following information, if applicable):

  • OS: macOS
  • Azure Functions v4
  • .NET SDK 6.0.102
  • OpenAPI Extension 1.2.0
@basilfx basilfx changed the title Type of TimeSpan incorrectly inferred Type of TimeSpan incorrectly inferred as complex object instead of string Mar 23, 2022
@justinyoo
Copy link
Contributor

justinyoo commented Mar 30, 2022

@basilfx Thanks for the issue! Did you mean the TimeSpan instance should look like this?

https://dotnetfiddle.net/tyLTMW

I mean the TimeSpan instance is serialised like above (as a string value), so the OpenAPI document should also follow it?

@basilfx
Copy link
Author

basilfx commented Mar 30, 2022

Yes, that's what I would expect, and that is how Newtonsoft.Json (used by AF for serializing an IActionResult) serializes a TimeSpan by default.

@snerte
Copy link

snerte commented Jun 2, 2022

I am also running into this issue. As I am generating a client, the deserialization will fail.

@basilfx
Copy link
Author

basilfx commented Oct 18, 2022

@justinyoo Any update on this issue? Anything I can do to help?

@sinantutan
Copy link
Contributor

Did you by chance find a workaround/fix?

@justinyoo justinyoo linked a pull request Dec 21, 2022 that will close this issue
@justinyoo justinyoo added bug Something isn't working and removed triage labels Dec 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants