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

Nontermination when using datatypeNameModifier with recursive data types #132

Closed
amiddelk opened this issue Oct 24, 2017 · 0 comments
Closed

Comments

@amiddelk
Copy link

amiddelk commented Oct 24, 2017

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.

amiddelk pushed a commit to amiddelk/swagger2 that referenced this issue Oct 24, 2017
Without the fix of GetShopTV#132, the added testcase causes nontermination.
With the fix, the tests are all green.
@fizruk fizruk closed this as completed in 4ce7dc9 Dec 31, 2017
fizruk added a commit that referenced this issue Dec 31, 2017
…enamemodifier

Fixes #132: Nontermination when using datatypeNameModifier with recursive data types
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

1 participant