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

[BUG] Nested objects with allOf are being generated as null #11

Closed
doubleppereira opened this issue Sep 6, 2022 · 5 comments · Fixed by #19
Closed

[BUG] Nested objects with allOf are being generated as null #11

doubleppereira opened this issue Sep 6, 2022 · 5 comments · Fixed by #19

Comments

@doubleppereira
Copy link

msw-auto-mock seems to have Problems with return values based on components/models with nested objects which have allOf instead of type.
This is a standard open-api document and it's being generated by Swashbuckle
See below the schema of the PaymentResultApiResponse and the result prop.

Open-API Doc Example below

"/v1/checkout/get-payment-status": {
      "post": {
        "tags": [
          "Checkout",
          "RequiresAuthentication",
          "RequiresKycTier-0"
        ],
        "operationId": "GetPaymentStatus",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "allOf": [
                  {
                    "$ref": "#/components/schemas/GetPaymentStatusRequest"
                  }
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PaymentResultApiResponse"
                }
              }
            }
          },
          "429": {
            "description": "Too Many Requests"
          },
          "400": {
            "description": "Bad Request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiResponse"
                }
              }
            }
          }
        },
        "security": [
          { }
        ]
      }
    },

// ...
  "components": {
    "schemas": {
        "PaymentResultApiResponse": {
            "required": [
            "isSuccessful"
            ],
            "type": "object",
            "properties": {
            "result": {
                "allOf": [ <--- is not being generated
                {
                    "$ref": "#/components/schemas/PaymentResult"
                }
                ],
                "nullable": true
            },
            "timestamp": {
                "type": "integer",
                "format": "int64",
                "readOnly": true
            },
            "isSuccessful": {
                "type": "boolean"
            },
            "errorMessage": {
                "type": "string",
                "nullable": true
            },
            "errorCode": {
                "type": "integer",
                "format": "int32",
                "nullable": true
            },
            "requestId": {
                "type": "string",
                "nullable": true
            }
            },
            "additionalProperties": false
        },

Output:

 ctx.json({
          result: null,
          timestamp: faker.datatype.number(),
          isSuccessful: faker.datatype.boolean(),
          errorMessage: faker.lorem.slug(1),
          errorCode: faker.datatype.number(),
          requestId: faker.lorem.slug(1),
        }),
@doubleppereira
Copy link
Author

I tried to play a bit with the code but I got to a situation of circular dependency issue on some other cases when resolving allOf refs

@zoubingwu
Copy link
Owner

Thanks for your feedback, I'll look into it.

@doubleppereira
Copy link
Author

Hi guys. Any update on this?

@nbrdx
Copy link

nbrdx commented Nov 19, 2022

Hey there, just ran into the same problem. Also looking for updates 🙂

@zoubingwu
Copy link
Owner

@doubleppereira @nbrdx hey this should be fixed in v0.11.0, pls upgrade to latest version and try it again.

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.

3 participants