Skip to content
This repository has been archived by the owner on Nov 16, 2023. It is now read-only.

Add TimeSpan handling to TypeExtensions #230

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public static class TypeExtensions
[typeof(decimal)] = () => new OpenApiSchema {Type = "number", Format = "double"},
[typeof(DateTime)] = () => new OpenApiSchema {Type = "string", Format = "date-time"},
[typeof(DateTimeOffset)] = () => new OpenApiSchema {Type = "string", Format = "date-time"},
[typeof(TimeSpan)] = () => new OpenApiSchema {Type = "string"},
[typeof(Guid)] = () => new OpenApiSchema {Type = "string", Format = "uuid"},
[typeof(char)] = () => new OpenApiSchema {Type = "string"},

Expand All @@ -45,6 +46,7 @@ public static class TypeExtensions
[typeof(double?)] = () => new OpenApiSchema {Type = "number", Format = "double", Nullable = true},
[typeof(decimal?)] = () => new OpenApiSchema {Type = "number", Format = "double", Nullable = true},
[typeof(DateTime?)] = () => new OpenApiSchema {Type = "string", Format = "date-time", Nullable = true},
[typeof(TimeSpan?)] = () => new OpenApiSchema {Type = "string", Nullable = true},
Copy link
Member

Choose a reason for hiding this comment

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

TimeSpan?) [](start = 24, length = 10)

add a unit test case or update existing to cover this datatype

Copy link
Author

Choose a reason for hiding this comment

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

Will add this in, thanks! I couldn't locate existing unit tests for this class but it may be indirectly tested somewhere else; I'll do some digging.

Copy link
Member

@Shwetap05 Shwetap05 Feb 10, 2020

Choose a reason for hiding this comment

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

Most of the test call the generator method directly, you can update any existing xml used in test https://github.com/microsoft/OpenAPI.NET.CSharpAnnotations/blob/master/test/Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Tests/OpenApiDocumentGeneratorTests/OpenApiDocumentGeneratorTest.cs to use a timespan type and update the expected json


In reply to: 377244341 [](ancestors = 377244341)

[typeof(DateTimeOffset?)] = () =>
new OpenApiSchema {Type = "string", Format = "date-time", Nullable = true},
[typeof(Guid?)] = () => new OpenApiSchema {Type = "string", Format = "uuid", Nullable = true},
Expand Down