question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

OpenAPI schemas: 'date' format shows same as 'date-time'

See original GitHub issue

Bug description

Developer portal shows example data for date fields regardless of their format.

Reproduction steps

  1. Create following product.yaml file:
openapi: "3.0.2"
info:
  title: Products
  version: "1.0"

components:
  schemas:
    product:
      description: Product
      type: object
      properties:
        id:
          type: integer
        name:
          type: string
        date1:
          type: string
          format: date
          example: "2020-06-25"
        date2:
          type: string
          format: date-time
          example: "2020-07-25T12:34:56Z"

paths:
  /:
    get:
      responses:
        "200":
          description: OK response
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/product"

Notice difference in format and example fields:

        date1:
          type: string
          format: date
          example: "2020-06-25"
        date2:
          type: string
          format: date-time
          example: "2020-07-25T12:34:56Z"
  1. Publish that as API to APIM
  2. Go to developer portal and see API details
  3. Incorrect format is shown for date1 field:
{
    "id": 0,
    "name": "string",
    "date1": "2020-06-25T00:00:00",
    "date2": "2020-07-25T12:34:56+00:00"
}

Expected behavior

In above json date1 field should be 2020-06-25 as per string formats.

Expected output would be:

{
    "id": 0,
    "name": "string",
    "date1": "2020-06-25",
    "date2": "2020-07-25T12:34:56+00:00"
}

Is your portal managed or self-hosted?

Self-hosted

Release tag or commit SHA (if using self-hosted version)

N/A

API Management service name

demo9001

Environment

  • Operating system: Windows 10
  • Browser: Edge
  • Version: Version 86.0.622.3 (Official build) dev (64-bit)

Additional context

N/A

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
mikaahopeltocommented, Nov 13, 2020

This issue seems to be root-caused on the API Management side. If you add the above product.yaml as a new Open API in the portal and then click the ‘Open the OpenAPI editor (YAML)’ from the management portal, you’ll get the following outcome including the date-time problem: image

However, the most visible outcome is that end users (aka. api developers) can’t use the dev portal’s Try it -functionality without first going through all dates and fixing the manually every time.

This happens on the managed API Management service.

1reaction
xedstrcommented, Nov 5, 2021

Hi, Any news on the deployment of the fix? Thanks

Read more comments on GitHub >

github_iconTop Results From Across the Web

What is the correct way to declare a date in an OpenAPI ...
Use format: date and don't use pattern , much easier to read. If you do want to use a regex for a different...
Read more >
Dates in OpenAPI Files | Baeldung
In this case, we used the date format to describe the createdAt date. This format describes dates using the ISO 8601 full-date format....
Read more >
Data Types - Swagger
OpenAPI defines the following built-in string formats: date – full-date notation as defined by RFC 3339, section 5.6, for example, 2017-07-21.
Read more >
Non-Standard Date and Time Formats | by John Wang - Medium
Non-standard APIs actually cause interoperability problems because the OpenAPI 3.0 and Swagger 2.0 API specifications only support RFC-3339 ...
Read more >
Parse and Format Date Function Calls | Mendix Documentation
For example parseDateTime('35-11-2015', 'dd-MM-yyyy', dateTime(2015)) will return 05 December 2015 12:00 AM . 2.3 Example. The examples below illustrate which ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found