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

new feature for examples generations #52

Closed
jean13360 opened this issue Jun 20, 2024 · 2 comments · Fixed by #53
Closed

new feature for examples generations #52

jean13360 opened this issue Jun 20, 2024 · 2 comments · Fixed by #53
Assignees

Comments

@jean13360
Copy link

I fork this project because i need some new features

  • During my API testing , i need to have a random response from the list of examples

'200':
description: Good
content:
application/json:
schema:
$ref: '#/components/schemas/User'
examples:
Err0r1:
description: "Error1"
value:
detail: Error1
Err0r2:
description: "Error2"
value:
detail: "Error2"

I change your implementation of method getResponseSchema because the resultSchema.examples is not an array and the default generator not work

I do
if (!Array.isArray(examples)) {
let arrayOfExample = []
for (const key in examples) {
arrayOfExample.push(examples[key].value)
}
resultSchema.examples = arrayOfExample;

Maybe you can add this type of feature ? maybe you can also random the reponse 200/500 or 400?

I add too an new option to generate random value for items only described into the schema definition

Thanks

@aleksandryackovlev aleksandryackovlev self-assigned this Jun 21, 2024
@aleksandryackovlev aleksandryackovlev linked a pull request Jun 25, 2024 that will close this issue
6 tasks
@aleksandryackovlev
Copy link
Owner

A new option has been added. If you want to randomly generate responses from the examples, just add a new option randomizeExamples in the config:

createMockMiddleware({
  spec: '/the/path/to/your/spec/file',
  options: { randomizeExamples: true },
}); 

@jean13360
Copy link
Author

Thx

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 a pull request may close this issue.

2 participants