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

the same oneOf schema can pass request validation. But cannot pass response validation #877

Open
kennyma-eplus opened this issue Nov 27, 2023 · 0 comments

Comments

@kennyma-eplus
Copy link

Here is my schema. You can see the request and response is the same

Here is my schema. You can see the request and response is the same
{
    "openapi": "3.0.3",
    "info": {
      "title": "test",
      "version": "1.0.0",
      "description": "test"
    },
    "paths": {
        "/ping": {
            "post": {
                "summary": "test",
                "description": "test",
                "x-eov-operation-handler": "ping",
                "x-eov-operation-id": "ping",
                "requestBody":{
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "test": {
                                        "oneOf": [
                                            {
                                                "type": "object",
                                                "properties": {
                                                    "type": { "type": "string", "enum": ["requiredMessage"] },
                                                    "message": { "type": "string" }
                                                },
                                                "required": ["type", "message"],
                                                "additionalProperties": false
                                            },
                                            {
                                                "type": "object",
                                                "properties": {
                                                    "type": { "type": "string", "enum": ["requiredUrl"] },
                                                    "url": { "type": "string" }
                                                },
                                                "required": ["type", "url"],
                                                "additionalProperties": false
                                            }
                                        ]
                                    }      
                                },
                                "required": ["test"]
                            }
                        }
                    }
                },
                "responses": {
                    "200": {
                        "description": "test",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "type": "object",
                                    "properties": {
                                        "test": {
                                            "oneOf": [
                                                {
                                                    "type": "object",
                                                    "properties": {
                                                        "type": { "type": "string", "enum": ["requiredMessage"] },
                                                        "message": { "type": "string" }
                                                    },
                                                    "required": ["type", "message"],
                                                    "additionalProperties": false
                                                },
                                                {
                                                    "type": "object",
                                                    "properties": {
                                                        "type": { "type": "string", "enum": ["requiredUrl"] },
                                                        "url": { "type": "string" }
                                                    },
                                                    "required": ["type", "url"],
                                                    "additionalProperties": false
                                                }
                                            ]
                                        }      
                                    },
                                    "required": ["test"]
                                }
                            }
                        }
                    }
                }
            }
        }
    }
  }

the operation-handler just forward the request to response

const ping = (req, res) => {
    const { body } = req
    res.json(body)
}
module.exports = { ping }

Here is my payload:

{
    "test": {
        "type": "requiredUrl",
        "url": "url"
    }
}

request pass, but response cannot pass

Internal Server Error: /response/test must have required property 'message', /response/test/type must be equal to one of the allowed values: requiredMessage, /response/test must have required property 'url', /response/test must match exactly one schema in oneOf
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

No branches or pull requests

1 participant