Skip to content

Prism mocks of strings with format: duration are sometimes malformed, causing validation errors at random #2650

Open
@hxlnt

Description

Current Behavior

Prism-generated dynamic mock responses of type: string and format: duration randomly produce non-valid duration strings such as "P725387655M58009976655DT" and "P", resulting in errors. Rerunning the same GET call produces errors unpredictably.

Expected Behavior

A dynamic response of format: duration should always pass validation.

Steps to Reproduce

  1. Snippet from my valid API definition for GET response:
  responses:
    '200':
      description: OK
      content:
        application/json:
          schema:
            type: object
            properties:
              min:
                type: string
                format: duration
              max:
                type: string
                format: duration
              average:
                type: string
                format: duration
              total:
                type: string
                format: duration
  1. Prism-mocked response body and error (first run):
{
  "average": "P1038276829W",
  "max": "P725387655M58009976655DT",
  "min": "P1629484W",
  "total": "P960507355Y99894M87085DT9121M"
}

[VALIDATOR] ✖ error Violation: response.body.max Response body property max must match format "duration"
3. Prism-mocked response body and error (second run, same query parameters):

{
  "average": "P",
  "max": "P",
  "min": "P718W",
  "total": "P"
}

[VALIDATOR] ✖ error Violation: response.body.max Response body property max must match format "duration"
[VALIDATOR] ✖ error Violation: response.body.average Response body property average must match format "duration"
[VALIDATOR] ✖ error Violation: response.body.total Response body property total must match format "duration"

Environment

  • Version used: 5.12.0
  • Environment name and version (e.g. Chrome 39, node.js 5.4): Node 22.7.0
  • Operating System and version (desktop or mobile): macOS Sonoma

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions