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

refactor: Payload Generator improvements SO-232 #322

Merged
merged 14 commits into from
May 27, 2019

Conversation

XVincentX
Copy link
Contributor

@XVincentX XVincentX commented May 25, 2019

This PR revisits a little bit the way we generate the examples from JSON Schemas.

  1. Remove the interface+class boilerplate (for a single method) and export a simple function signature somebody can implement
  2. Remove the serialisation responsibility from the schema generator — this is something the framework should do somewhere else
  3. Refactor the tests to use less snapshots and more assertions

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

@XVincentX XVincentX marked this pull request as ready for review May 25, 2019 18:51
@XVincentX XVincentX changed the title refactor: Payload Generator improvements refactor: Payload Generator improvements SO-232 May 25, 2019
philsturgeon
philsturgeon previously approved these changes May 25, 2019
'x-expires-after': expect.any(String),
'x-strange-header': file === 'petstore.oas3.json' ? 'string' : '{}',
'x-strange-header': file === 'petstore.oas3.json' ? 'string' : {},
Copy link
Contributor

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?

Copy link
Contributor Author

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!

philsturgeon
philsturgeon previously approved these changes May 27, 2019
@XVincentX XVincentX merged commit 4ee9b33 into master May 27, 2019
@XVincentX XVincentX deleted the feat/simple-generator branch May 27, 2019 13:24
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.

None yet

2 participants