Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ public static IOpenApiAny GetSpecificOpenApiAny(IOpenApiAny openApiAny, OpenApiS
{
if (DateTimeOffset.TryParse(value, CultureInfo.InvariantCulture, DateTimeStyles.None, out var dateTimeValue))
{
return new OpenApiDateTime(dateTimeValue);
// if the time component is exactly midnight(00:00:00) meaning no time has elapsed, return a date-only value
return dateTimeValue.TimeOfDay == TimeSpan.Zero ? new OpenApiDate(dateTimeValue.Date)
: new OpenApiDateTime(dateTimeValue);
}
}
else if (type == "string")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1338,5 +1338,22 @@ public void ParseDocumentWithReferencedSecuritySchemeWorks()
Assert.False(securityScheme.UnresolvedReference);
Assert.NotNull(securityScheme.Flows);
}

[Fact]
public void ValidateExampleShouldNotHaveDataTypeMismatch()
{
// Arrange
using var stream = Resources.GetStream(Path.Combine(SampleFolderPath, "documentWithDateExampleInSchema.yaml"));

// Act
var doc = new OpenApiStreamReader(new()
{
ReferenceResolution = ReferenceResolutionSetting.ResolveLocalReferences
}).Read(stream, out var diagnostic);

// Assert
var warnings = diagnostic.Warnings;
Assert.False(warnings.Any());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
openapi: 3.0.0
info:
title: Sample API
description: Lorem Ipsum
version: 1.0.0
servers:
- url: http://api.example.com/v1
description: Lorem Ipsum
paths:
/issues:
get:
summary: Returns a list of issues.
description: Lorem Ipsum
responses:
"200":
description: Lorem Ipsum
content:
application/json:
schema:
type: object
required:
- data
properties:
data:
type: array
items:
$ref: "#/components/schemas/issueData"
example:
data:
- issuedAt: "2023-10-12"
components:
schemas:
issueData:
type: object
title: Issue Data
description: Information about the issue.
properties:
issuedAt:
type: string
format: date
description: Lorem Ipsum
example: "2023-10-12"