-
Notifications
You must be signed in to change notification settings - Fork 352
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
refactor: Payload Generator improvements SO-232 #322
Conversation
4566f5e
to
7f41cf4
Compare
packages/http/src/mocker/generator/__tests__/JSONSchema.spec.ts
Outdated
Show resolved
Hide resolved
'x-expires-after': expect.any(String), | ||
'x-strange-header': file === 'petstore.oas3.json' ? 'string' : '{}', | ||
'x-strange-header': file === 'petstore.oas3.json' ? 'string' : {}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This but confuses me. Why was it ‘{}’ before and why is it {} now? They both seem like funny things to happen, don’t we just want an empty string for a header?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good question, I actually wanted to brief/ask you about this anyway.
In OpenAPI 3 documents the schema has a separate property in the Header object (example
or examples
) — in OAS2 the schema is "melted" with the header definition itself.
For this reason, JSON Schema Faker is kind of confused and generates an empty object for a schema that's not really complete/defined.
I can add a small workaround to standardise the behaviour. Up to you!
This PR revisits a little bit the way we generate the examples from JSON Schemas.
Note: While refactoring the code I also spotted a test passing incorrectly because of a spy that wasn't reset. https://github.com/stoplightio/prism/pull/322/files#diff-e53e98c10a813d2d271cc0fa5c55ddcaR201