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

fix(msw): do not use spread objects if nullable object schema in oneOf #1626

Merged

Conversation

soartec-lab
Copy link
Member

Status

READY

Description

Suppose I have a schema nullable object in oneOf as below.

openapi: 3.0.0
info:
  version: 1.0.0
  title: AnyOf Schema
  license:
    name: MIT

paths:
  /one-of-with-nullable-object:
    get:
      operationId: getOneOfWithNullableObject
      tags:
        - pets
      description: |-
        oneOf with nullable object.
      responses:
        '200':
          description: Pet
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Pet'

components:
  schemas:
    Pet:
      oneOf:
        - $ref: '#/components/schemas/Dog'
        - $ref: '#/components/schemas/Cat'
    Dog:
      type: object
      nullable: true
      required:
        - id
        - name
      properties:
        id:
          type: integer
          format: int64
        name:
          type: string
    Cat:
      type: object
      required:
        - id
        - category
      properties:
        id:
          type: integer
          format: int64
        category:
          type: string

In this case, the mock defined function cannot be spread and will result in a syntax error.
Therefore, I modified it to avoid it in the case of nullable.

Before

Dog is nullable so occur syntax error

export const getGetOneOfObjectOrIntegerPetsResponseMock = (): Pet => (faker.helpers.arrayElement([{...getGetOneOfObjectOrIntegerPetsResponseDogMock()},{...getGetOneOfObjectOrIntegerPetsResponseCatMock()}]))

After

mock of Doc doesn't use spread.

export const getGetOneOfObjectOrIntegerPetsResponseMock = (): Pet => (faker.helpers.arrayElement([getGetOneOfObjectOrIntegerPetsResponseDogMock(),{...getGetOneOfObjectOrIntegerPetsResponseCatMock()}]))

Related PRs

none

Todos

  • Tests
  • Documentation
  • Changelog Entry (unreleased)

Steps to Test or Reproduce

You can check by i added test case.

@soartec-lab soartec-lab added bug Something isn't working msw MSW related issues labels Sep 15, 2024
@soartec-lab soartec-lab added this to the 7.1.1 milestone Sep 15, 2024
@melloware melloware merged commit 261f8de into orval-labs:master Sep 15, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working msw MSW related issues
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants