Skip to content

Nontermination when using datatypeNameModifier with recursive data types #132

@amiddelk

Description

@amiddelk

Using LTS 9.9 with swagger2-2.1.6 or, alternatively, the current main branch of the repository:
When using the option genericDeclareNamedSchema in combination with recursive data types, the produced schema grows unbounded. Here is a standalone example:

{-# LANGUAGE DeriveGeneric #-}
module Main where

import Data.Proxy
import Data.Swagger
import Data.Swagger.Declare
import GHC.Generics

data SomeTy =
  SomeCon { keyA :: Int, keyB :: Maybe SomeTy }
  deriving (Eq, Show, Generic)

instance ToSchema SomeTy where
  declareNamedSchema = genericDeclareNamedSchema schemaOpts

schemaOpts = defaultSchemaOptions
  { Data.Swagger.datatypeNameModifier = drop 1 }

proxySomeTy :: Proxy SomeTy
proxySomeTy = Proxy

testSomeTy :: NamedSchema
testSomeTy = undeclare $ declareNamedSchema proxySomeTy

main :: IO ()
main = putStrLn (show testSomeTy)

My best guess would be that the transformed name is not taken properly in account when checking for recursion.

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