Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
hxlnt opened this issue Jan 13, 2025 · 1 comment

Comments

@hxlnt
Copy link

hxlnt commented Jan 13, 2025

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
@hxlnt hxlnt changed the title Prism mocks of strings with format: duration are sometimes "P," causing validation errors at random Prism mocks of strings with format: duration are sometimes malformed, causing validation errors at random Jan 13, 2025
@hxlnt
Copy link
Author

hxlnt commented Jan 15, 2025

Looks like this might be an issue with the json-schema-faker dependency, so I've logged a bug there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant