Azure / api-management-developer-portal

Developer portal provided by the Azure API Management service.
MIT License
489 stars 319 forks source link

Example time format changes to date-time if schema referenced through $ref #1574

Open ghost opened 2 years ago

ghost commented 2 years ago

When importing API through the developer portal / azure cli / azure PowerShell, example fields with format set to time are changed to full date-time if the example schema is referenced by $ref.

Reproduction steps

  1. Import the following API specification:

    
    openapi: 3.0.3
    info:
    title: Time Format Test
    description: Time Format Test
    version: 1.0.0
    servers:
    - url: 'https://example.com'
    paths:
    /without-schema:
    post:
      summary: POST ISO time
      operationId: post-iso-time
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                time:
                  type: string
                  format: time
            example:
              time:
                '10:00:00+01:00'
      responses:
        200:
          description: OK
    
    /with-schema:
    post:
      summary: POST ISO time with Schema
      operationId: post-iso-time-w-schema
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/IsoTime'
            example:
              time:
                '10:00:00+01:00'
      responses:
        200:
          description: OK

components: schemas: IsoTime: type: object properties: time: type: string format: time

2.  Navigate to the imported API. Check the operations generated body in the _Test_ tab.

## Expected behavior

Both operations should have the following body:

{"time":"10:00:00+01:00"}


## Actual behavior:

The body of the _POST ISO time with Schema_ operation is:

{"time":"2021-12-16T09:00:00Z"}


It has been converted from ISO time to ISO date-time in UTC.

This issue prevents users from testing the API with the provided example, as the backend service expects a _time_, not _date-time_ property.

This issue affects also _Azure CLI_, _APIM REST API_ and _Azure PowerShell_.
ghost commented 2 years ago

@marcin-m-dsv, thank you for opening this issue. Due to the winter holidays season, it may take us longer than a few days to respond to it. If the issue is urgent, please contact Azure support.

ghost commented 2 years ago

@marcin-m-dsv, thank you for reporting the bug.

mikebudzynski commented 2 years ago

@VitaliyKurokhtin, it sounds similar to a bug that was fixed with the October's release: https://github.com/Azure/API-Management/releases/tag/release-service-2021-10 but affects time instead of date type.

Properties with format: date in OpenAPI documents are no longer converted to a date-time object.

Hekku2 commented 2 months ago

We are having somewhat similar issue, but in our case the timestamp in example, such as

Input:

{
   "changeTime": "07:00:00"
}

Is converted to this in the example provided by APIM portal:

{
   "changeTime": "2024-08-21"
}

This is creating issues for our end users.