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

Feature request: Add support to mock generator for non required fields #200

Closed
petkostas opened this issue Nov 18, 2023 · 3 comments
Closed
Labels
enhancement New feature or request

Comments

@petkostas
Copy link

petkostas commented Nov 18, 2023

I am using libopenapi in a project to render documentation, and I used the mock generator to render the responses of different operations.
While it was working as expected, I encountered a minor annoyance. I crossed a case where the Media type response had no example and used a schema reference.
The mock generator generated a mock response, but I noticed it was omitting a few fields. After a couple of experiments, I realized that this behavior was related to the use of required in the schema object. Removing this provided a complete working example.
Is there a way to switch this (maybe through an mg.OnlyRequired() switch? That would greatly help, especially when you prefer to render a complete response example for schemas that include a required field.
Let me know if I can help. I can open a PR for this.

P.S. Heh #200 nice 👍🏼 😄

@daveshanley
Copy link
Member

  1. Would you expect this to be a different method, or a configuration?
  2. Would you expect the 'switch' (however its implemented) to render all fields, regardless of 'required' state?

@daveshanley daveshanley added the enhancement New feature or request label Nov 20, 2023
@petkostas
Copy link
Author

Hello @daveshanley, a different method would be sufficient for me (and also keeps things clean). The expected behavior would be that when calling that method, you get a mock with all the schema fields regardless of the required state.

daveshanley added a commit that referenced this issue Nov 22, 2023
Signed-off-by: quobix <dave@quobix.com>
@daveshanley daveshanley mentioned this issue Nov 22, 2023
daveshanley added a commit that referenced this issue Nov 25, 2023
Signed-off-by: quobix <dave@quobix.com>
@daveshanley
Copy link
Member

Added in v0.13.12

A new switch method features on the renderer.SchemaRenderer struct called DisableRequiredCheck() This will render all properties, regardless of the 'required` property values.

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

No branches or pull requests

2 participants