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

feat: Support mapping repeated keys to array in form-data #2654

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

lilingxi01
Copy link

@lilingxi01 lilingxi01 commented Jan 17, 2025

Summary

This PR adds the support of mapping repeated form keys into arrays for validation in multipart form-data and url-encoded form-data. Using repeated keys to fulfill arrays in form-data is nowadays a popular workaround whenever an array is needed inside form-data (reference, reference). In the old version of Prism, repeated keys will be treated as overriding previous values, thus failing the validation.

Checklist

  • The basics
    • I tested these changes manually in my local or dev environment
  • Tests
    • Added or updated
    • N/A
  • Event Tracking
    • I added event tracking and followed the event tracking guidelines
    • N/A
  • Error Reporting
    • I reported errors and followed the error reporting guidelines
    • N/A

Additional context

I discovered this need when working with Stainless auto-generated SDK, where Prism is used to test the SDK. Whenever I have an array in multipart form-data, Prism simply fails with 422, but the same input easily passes with real server. Thus, I dug into the workarounds online and realized that repeating keys is an untold standard in accomplishing this need. OpenAI happens to have the exact same awkward situation with Stainless + Prism, and there is no workaround online for mock server like this, thus I decided to make Prism support it.

Interesting side note: OpenAI's library tests were luckily passing because their field is optional, and the key name is mismatched in their OpenAPI schema, thus Prism simply thought that the key was not provided and treated it as valid request. OpenAI's SDK (and per API reference) passes timestamp_granularities[] into the Prism while having timestamp_granularities as key name in the Stainless-hosted OpenAPI schema, so Prism thinks it is a valid request, but it is actually being untested. In my use case, my array field needs to be required, so I end up needing to find a workaround more seriously. With this patch, OpenAI's SDKs could then actually be tested against their actual OpenAPI schema (with timestamp_granularities[] as key name).

@lilingxi01 lilingxi01 requested a review from a team as a code owner January 17, 2025 09:01
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

Successfully merging this pull request may close these issues.

1 participant