Skip to content

OpenAPI example rendered incorrectly for strings that happen to be DateTime(Offset) strings #60630

Closed
@martincostello

Description

@martincostello

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

It's possible this is a Microsoft.OpenApi issue, but I figured I'd start here.

Upgrading an application with an OpenAPI document from ASP.NET Core 9 to ASP.NET Core 10 preview 1, the examples in the returned JSON (or YAML) document are being rendered with string properties that happen to parse as a DateTimeOffset being rendered as such, rather than the original string representation.

It seems that something somewhere sees the string will parse as a DateTimeOffset, converts it, and then subsequently it is formatted as such, changing the string's value.

Image

As far as I can tell, my OpenAPI extensions are rendering the examples as strings correctly when assigned to the Example property on the relevant OpenAPI primitive.

Image

The relevant snippet from the OpenAPI schema is:

"TimeResponse": {
  "type": "object",
  "properties": {
    "timestamp": {
      "type": "string",
      "description": "The timestamp for the response for which the times are generated.",
      "format": "date-time"
    },
    "rfc1123": {
      "type": "string",
      "description": "The current UTC date and time in RFC1123 format."
    },
    "unix": {
      "type": "integer",
      "description": "The number of seconds since the UNIX epoch.",
      "format": "int64"
     },
     "universalSortable": {
       "type": "string",
       "description": "The current UTC date and time in universal sortable format."
      },
    "universalFull": {
      "type": "string",
      "description": "The current UTC date and time in universal full format."
    }
  },
  "description": "Represents the response from the /time API resource.",
  "example": {
    "timestamp": "2016-06-03T18:44:14.0000000+00:00",
    "rfc1123": "2016-06-03T18:44:14.0000000+00:00",
    "unix": 1464979454,
    "universalSortable": "2016-06-03T18:44:14.0000000+00:00",
    "universalFull": "2016-06-03T18:44:14.0000000+01:00"
 }
}

rfc1123, universalSortable and universalFull are all being rendered the same as timestamp when they should be rendered in different string formats.

Expected Behavior

String properties that are not explicitly typed as the format: date-time are not coerced to a different type.

Steps To Reproduce

  1. Clone martincostello/api@a5135f4
  2. Run build.ps1 from the root of the repository.

Exceptions (if any)

The Json_Schema_Is_Correct and Yaml_Schema_Is_Correct tests fail.

.NET Version

10.0.100-preview.1.25120.13

Anything else?

No.

Metadata

Metadata

Assignees

No one assigned

    Labels

    ExternalThis is an issue in a component not contained in this repository. It is open for tracking purposes.area-minimalIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcfeature-openapi

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions