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

MSW: Error using oneOf nested inside allOf #1526

Open
C-Higgins opened this issue Jul 19, 2024 · 1 comment
Open

MSW: Error using oneOf nested inside allOf #1526

C-Higgins opened this issue Jul 19, 2024 · 1 comment
Labels
bug Something isn't working msw MSW related issues

Comments

@C-Higgins
Copy link

C-Higgins commented Jul 19, 2024

Minimal input schema:

{
  "openapi": "3.0.1",
  "info": {
    "title": "bug report"
  },
  "paths": {
    "/something": {
      "post": {
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "uploads": {
                      "type": "array",
                      "items": {
                        "allOf": [
                          {
                            "type": "object",
                            "properties": {
                              "file_type": {
                                "type": "string"
                              }
                            }
                          },
                          {
                            "oneOf": [
                              {
                                "type": "object",
                                "properties": {
                                  "type": {
                                    "type": "string",
                                    "enum": ["a"]
                                  }
                                }
                              },
                              {
                                "type": "object",
                                "properties": {
                                  "type": {
                                    "type": "string",
                                    "enum": ["b"]
                                  },
                                  "other": {
                                    "type": "string"
                                  }
                                }
                              }
                            ]
                          }
                        ]
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}

Output with syntax error:

export const getPostSomethingResponseMock = (overrideResponse: Partial< PostSomething200 > = {}): PostSomething200 => ({uploads: faker.helpers.arrayElement([Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({file_type: faker.helpers.arrayElement([faker.word.sample(), undefined]),{type: faker.helpers.arrayElement([faker.helpers.arrayElement(['a'] as const), undefined])},{other: faker.helpers.arrayElement([faker.word.sample(), undefined]), type: faker.helpers.arrayElement([faker.helpers.arrayElement(['b'] as const), undefined])}})), undefined]), ...overrideResponse})

Tested on orval 6.29.1 and 6.31.0. The code in the schema file and the API file is correct; only the MSW file has this problem.

This seems to only happen with a oneOf nested inside an allOf.

@melloware melloware added msw MSW related issues bug Something isn't working mock Related to mock generation and removed bug Something isn't working mock Related to mock generation labels Jul 19, 2024
@melloware
Copy link
Collaborator

melloware commented Jul 19, 2024

Similar to this issue: #1508

And this one: #1101

@melloware melloware changed the title Syntax error in generated MSW file MSW: Error using oneOf nested inside allOf Jul 19, 2024
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

No branches or pull requests

2 participants