-
-
Notifications
You must be signed in to change notification settings - Fork 664
fix(mock): use one-sided bounds when only minLength/maxLength or minItems/maxItems is specified #3120
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
Closed
youngcm2
wants to merge
7
commits into
orval-labs:master
from
youngcm2:fix/incorrect-array-values-msw
Closed
fix(mock): use one-sided bounds when only minLength/maxLength or minItems/maxItems is specified #3120
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
728bcc8
fix(mock): use one-sided bounds when only minLength/maxLength or minI…
youngcm2 0ab111c
fix(mock): use min 1 instead of undefined when only maxLength/maxItem…
youngcm2 16be61e
test(mock): add one-sided array constraint unit tests for minItems/ma…
youngcm2 672113b
fix(mock): replace negated conditions to satisfy unicorn/no-negated-c…
youngcm2 7d296de
Update endpoints.ts
melloware d614c63
Update orval version in snapshot file
melloware 57dafec
Update generated comment to Orval v8.6.2
melloware File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| /** | ||
| * Generated by orval v8.6.2 🍺 | ||
| * Do not edit manually. | ||
| * Mock Constraints | ||
| * Test one-sided string and array constraints for MSW mock generation | ||
| * OpenAPI spec version: 1.0.0 | ||
| */ | ||
| import axios from 'axios'; | ||
| import type { AxiosRequestConfig, AxiosResponse } from 'axios'; | ||
|
|
||
| import type { ConstrainedItem } from './model'; | ||
|
|
||
| import { faker } from '@faker-js/faker'; | ||
|
|
||
| import { HttpResponse, http } from 'msw'; | ||
| import type { RequestHandlerOptions } from 'msw'; | ||
|
|
||
| /** | ||
| * @summary Get items with one-sided constraints | ||
| */ | ||
| export const getItems = ( | ||
| options?: AxiosRequestConfig, | ||
| ): Promise<AxiosResponse<ConstrainedItem>> => { | ||
| return axios.get(`/items`, options); | ||
| }; | ||
|
|
||
| export type GetItemsResult = AxiosResponse<ConstrainedItem>; | ||
|
|
||
| export const getGetItemsResponseMock = ( | ||
| overrideResponse: Partial<Extract<ConstrainedItem, object>> = {}, | ||
| ): ConstrainedItem => ({ | ||
| maxLengthOnly: faker.helpers.arrayElement([ | ||
| faker.string.alpha({ length: { max: 5 } }), | ||
| undefined, | ||
| ]), | ||
| minLengthOnly: faker.helpers.arrayElement([ | ||
| faker.string.alpha({ length: { min: 30 } }), | ||
| undefined, | ||
| ]), | ||
| maxItemsOnly: faker.helpers.arrayElement([ | ||
| Array.from({ length: faker.number.int({ max: 2 }) }, (_, i) => i + 1).map( | ||
| () => faker.string.alpha({ length: { min: 10, max: 20 } }), | ||
| ), | ||
| undefined, | ||
| ]), | ||
| minItemsOnly: faker.helpers.arrayElement([ | ||
| Array.from({ length: faker.number.int({ min: 5 }) }, (_, i) => i + 1).map( | ||
| () => faker.string.alpha({ length: { min: 10, max: 20 } }), | ||
| ), | ||
| undefined, | ||
| ]), | ||
| bothBounds: faker.helpers.arrayElement([ | ||
| faker.string.alpha({ length: { min: 2, max: 8 } }), | ||
| undefined, | ||
| ]), | ||
| ...overrideResponse, | ||
| }); | ||
|
|
||
| export const getGetItemsMockHandler = ( | ||
| overrideResponse?: | ||
| | ConstrainedItem | ||
| | (( | ||
| info: Parameters<Parameters<typeof http.get>[1]>[0], | ||
| ) => Promise<ConstrainedItem> | ConstrainedItem), | ||
| options?: RequestHandlerOptions, | ||
| ) => { | ||
| return http.get( | ||
| '*/items', | ||
| async (info: Parameters<Parameters<typeof http.get>[1]>[0]) => { | ||
| return HttpResponse.json( | ||
| overrideResponse !== undefined | ||
| ? typeof overrideResponse === 'function' | ||
| ? await overrideResponse(info) | ||
| : overrideResponse | ||
| : getGetItemsResponseMock(), | ||
| { status: 200 }, | ||
| ); | ||
| }, | ||
| options, | ||
| ); | ||
| }; | ||
| export const getMockConstraintsMock = () => [getGetItemsMockHandler()]; |
23 changes: 23 additions & 0 deletions
23
tests/__snapshots__/mock/mock-constraints/model/constrainedItem.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| /** | ||
| * Generated by orval v8.6.2 🍺 | ||
| * Do not edit manually. | ||
| * Mock Constraints | ||
| * Test one-sided string and array constraints for MSW mock generation | ||
| * OpenAPI spec version: 1.0.0 | ||
| */ | ||
|
|
||
| export interface ConstrainedItem { | ||
| /** @maxLength 5 */ | ||
| maxLengthOnly?: string; | ||
| /** @minLength 30 */ | ||
| minLengthOnly?: string; | ||
| /** @maxItems 2 */ | ||
| maxItemsOnly?: string[]; | ||
| /** @minItems 5 */ | ||
| minItemsOnly?: string[]; | ||
| /** | ||
| * @minLength 2 | ||
| * @maxLength 8 | ||
| */ | ||
| bothBounds?: string; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| /** | ||
| * Generated by orval v8.6.2 🍺 | ||
| * Do not edit manually. | ||
| * Mock Constraints | ||
| * Test one-sided string and array constraints for MSW mock generation | ||
| * OpenAPI spec version: 1.0.0 | ||
| */ | ||
|
|
||
| export * from './constrainedItem'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| openapi: 3.1.0 | ||
| info: | ||
| title: Mock Constraints | ||
| description: 'Test one-sided string and array constraints for MSW mock generation' | ||
| version: 1.0.0 | ||
| tags: | ||
| - name: mock-constraints | ||
| description: One-sided constraint test endpoints | ||
| servers: | ||
| - url: http://localhost | ||
| paths: | ||
| /items: | ||
| get: | ||
| tags: | ||
| - mock-constraints | ||
| summary: Get items with one-sided constraints | ||
| operationId: getItems | ||
| responses: | ||
| 200: | ||
| description: Successful Operation | ||
| content: | ||
| application/json: | ||
| schema: | ||
| $ref: '#/components/schemas/ConstrainedItem' | ||
| components: | ||
| schemas: | ||
| ConstrainedItem: | ||
| type: object | ||
| properties: | ||
| maxLengthOnly: | ||
| type: string | ||
| maxLength: 5 | ||
| minLengthOnly: | ||
| type: string | ||
| minLength: 30 | ||
| maxItemsOnly: | ||
| type: array | ||
| maxItems: 2 | ||
| items: | ||
| type: string | ||
| minItemsOnly: | ||
| type: array | ||
| minItems: 5 | ||
| items: | ||
| type: string | ||
| bothBounds: | ||
| type: string | ||
| minLength: 2 | ||
| maxLength: 8 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.