Skip to content

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

@paulyoung

Description

@paulyoung

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": {}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions