GetShopTV / swagger2

Swagger 2.0 data model.
http://hackage.haskell.org/package/swagger2
BSD 3-Clause "New" or "Revised" License
74 stars 59 forks source link

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

Open paulyoung opened 4 years ago

paulyoung commented 4 years ago

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 commented 4 years ago

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