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

Global type name uniqueness constraint too onerous #44

Open
Elvecent opened this issue Mar 25, 2022 · 0 comments
Open

Global type name uniqueness constraint too onerous #44

Elvecent opened this issue Mar 25, 2022 · 0 comments
Assignees

Comments

@Elvecent
Copy link

Elvecent commented Mar 25, 2022

Due to how Monoid instances for hashmaps work, the final API description contains exact same schemas for different types with the same name.

This is a bug unless it is required that type names are globally unique. However, it should be possible to lift this requirement by disambiguating hashmap keys, i. e. by adding route name as a prefix to each key.

Alternatively, I'd like there to be a warning or even an error, because otherwise I simply end up with wrong documentation.

Example:

-- in Module1.hs
data ResponseBody = ResponseBody { rbField1 :: () } deriving Generic

-- in Module2.hs
data ResponseBody = ResponseBody { rbField2 :: () } deriving Generic

-- in Main.hs
type MyApi
  = "Route1" :> Get '[JSON] Module1.ResponseBody
    :<|>
    "Route2" :> Get '[JSON] Module2.ResponseBody

main = let swagger = toOpenApi (Proxy :: Proxy MyApi) in
  B.putStrLn $ encodePretty swagger
{
    "components": {
        "schemas": {
            "ResponseBody": {
                "type": "object",
                "properties": {
                    "rbField2": {
                        "items": {},
                        "maxItems": 0,
                        "type": "array",
                        "example": []
                    }
                },
                "required": [
                    "rbField2"
                ]
            }
        }
    },
    "openapi": "3.0.0",
    "paths": {
        "/Route1": {
            "get": {
                "responses": {
                    "200": {
                        "content": {
                            "application/json;charset=utf-8": {
                                "schema": {
                                    "$ref": "#/components/schemas/ResponseBody"
                                }
                            }
                        },
                        "description": ""
                    }
                }
            }
        },
        "/Route2": {
            "get": {
                "responses": {
                    "200": {
                        "content": {
                            "application/json;charset=utf-8": {
                                "schema": {
                                    "$ref": "#/components/schemas/ResponseBody"
                                }
                            }
                        },
                        "description": ""
                    }
                }
            }
        }
    },
    "info": {
        "version": "",
        "title": ""
    }
}
@maksbotan maksbotan self-assigned this Mar 25, 2022
@ncaq ncaq moved this to Should in @ncaq TODO Feb 21, 2023
@ncaq ncaq added this to @ncaq TODO Feb 21, 2023
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

2 participants