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

Maybe fields listed as required in multi-constructor data types with named fields #212

Open
paulyoung opened this issue Apr 23, 2020 · 1 comment

Comments

@paulyoung
Copy link
Contributor

This works as expected, since_1 is required:

data Foo
  = Bar { _1 :: LText }
{
  "swagger": "2.0",
  "info": {
    "version": "",
    "title": ""
  },
  "definitions": {
    "Foo": {
      "required": [
        "_1"
      ],
      "type": "object",
      "properties": {
        "_1": {
          "type": "string"
        }
      }
    }
  },
  "paths": {}
}

So does this, since _1 is not required:

data Foo
  = Bar { _1 :: Maybe LText }
{
  "swagger": "2.0",
  "info": {
    "version": "",
    "title": ""
  },
  "definitions": {
    "Foo": {
      "type": "object",
      "properties": {
        "_1": {
          "type": "string"
        }
      }
    }
  },
  "paths": {}
}

But this does not, since _2 should not be required:

data Foo
  = Bar { _1 :: LText }
  | Baz { _2 :: Maybe LText }
  deriving (Generic, ToJSON, ToSchema)
{
  "swagger": "2.0",
  "info": {
    "version": "",
    "title": ""
  },
  "definitions": {
    "Foo": {
      "minProperties": 1,
      "maxProperties": 1,
      "type": "object",
      "properties": {
        "Bar": {
          "required": [
            "_1"
          ],
          "type": "object",
          "properties": {
            "_1": {
              "type": "string"
            }
          }
        },
        "Baz": {
          "required": [
            "_2"
          ],
          "type": "object",
          "properties": {
            "_2": {
              "type": "string"
            }
          }
        }
      }
    }
  },
  "paths": {}
}
@fisx
Copy link
Collaborator

fisx commented Apr 30, 2020

looks like a legitimate bug to me. do you have time to work on fixing this?

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