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

Infinite <<loop>> when using named fields #211

Open paulyoung opened 4 years ago

paulyoung commented 4 years ago

This data type:

data Foo
  = Bar Foo
  | Baz Foo
  deriving (Generic, ToJSON, ToSchema)

Produces this JSON:

{
  "swagger": "2.0",
  "info": {
    "version": "",
    "title": ""
  },
  "definitions": {
    "Foo": {
      "minProperties": 1,
      "maxProperties": 1,
      "type": "object",
      "properties": {
        "Baz": {
          "$ref": "#/definitions/Foo"
        },
        "Bar": {
          "$ref": "#/definitions/Foo"
        }
      }
    }
  },
  "paths": {}
}

However, if I attempt to name the field like this:

data Foo
  = Bar { _1 :: Foo }
  | Baz { _2 :: Foo }
  deriving (Generic, ToJSON, ToSchema)

I get:

<<loop>>
paulyoung commented 4 years ago

My motivation for using named fields is in an attempt to have the required field populated and managed for me.

I’m hoping that I can later use that to know which type arguments were a Maybe

fisx commented 4 years ago

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

paulyoung commented 4 years ago

@Gabriel439 suggested that this could potentially be fixed using the same approach as in https://github.com/dhall-lang/dhall-haskell/issues/1660

paulyoung commented 4 years ago

I linked to the issue but the PR that fixes it is https://github.com/dhall-lang/dhall-haskell/pull/1825

paulyoung commented 4 years ago

It looks like those changes allow erroring out and breaking the loop but don't actually allow generic deriving of recursive data types.