Skip to content

Commit

Permalink
Add test for issue #107 fixed by #108
Browse files Browse the repository at this point in the history
  • Loading branch information
joel-bach committed Apr 27, 2024
1 parent 570723c commit 124b589
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 2 deletions.
5 changes: 5 additions & 0 deletions specifications/z_complex_self_made_example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,10 @@ components:
items:
type: string
minItems: 1
Value:
type: string
enum:
- yyy
CoverType:
type: object
properties:
Expand All @@ -388,6 +392,7 @@ components:
- $ref: '#/components/schemas/Test8'
- $ref: '#/components/schemas/Test9'
- $ref: '#/components/schemas/Test10'
- $ref: '#/components/schemas/Value'
parameters:
PetParameters:
name: petId
Expand Down
1 change: 1 addition & 0 deletions testing/golden-output/openapi.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ library
OpenAPI.Types.Test7
OpenAPI.Types.Test8
OpenAPI.Types.Test9
OpenAPI.Types.Value
OpenAPI.Configuration
OpenAPI.SecuritySchemes
OpenAPI.Common
Expand Down
2 changes: 2 additions & 0 deletions testing/golden-output/src/OpenAPI.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ module OpenAPI (
module OpenAPI.Types.Test7,
module OpenAPI.Types.Test8,
module OpenAPI.Types.Test9,
module OpenAPI.Types.Value,
module OpenAPI.Configuration,
module OpenAPI.SecuritySchemes,
module OpenAPI.Common,
Expand All @@ -45,6 +46,7 @@ import OpenAPI.Types.Test6
import OpenAPI.Types.Test7
import OpenAPI.Types.Test8
import OpenAPI.Types.Test9
import OpenAPI.Types.Value
import OpenAPI.Configuration
import OpenAPI.SecuritySchemes
import OpenAPI.Common
2 changes: 2 additions & 0 deletions testing/golden-output/src/OpenAPI/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ module OpenAPI.Types (
module OpenAPI.Types.Test7,
module OpenAPI.Types.Test8,
module OpenAPI.Types.Test9,
module OpenAPI.Types.Value,
) where

import OpenAPI.TypeAlias
Expand All @@ -26,3 +27,4 @@ import OpenAPI.Types.Test6
import OpenAPI.Types.Test7
import OpenAPI.Types.Test8
import OpenAPI.Types.Test9
import OpenAPI.Types.Value
7 changes: 5 additions & 2 deletions testing/golden-output/src/OpenAPI/Types/CoverType.hs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import {-# SOURCE #-} OpenAPI.Types.Test6
import {-# SOURCE #-} OpenAPI.Types.Test7
import {-# SOURCE #-} OpenAPI.Types.Test8
import {-# SOURCE #-} OpenAPI.Types.Test9
import {-# SOURCE #-} OpenAPI.Types.Value

-- | Defines the object schema located at @components.schemas.CoverType@ in the specification.
--
Expand Down Expand Up @@ -71,6 +72,7 @@ data CoverTypeCoverVariants =
| CoverTypeCoverTest8 Test8
| CoverTypeCoverTest9 Test9
| CoverTypeCoverTest10 Test10
| CoverTypeCoverValue Value
deriving (GHC.Show.Show, GHC.Classes.Eq)
instance Data.Aeson.Types.ToJSON.ToJSON CoverTypeCoverVariants
where {toJSON (CoverTypeCoverPetByAge a) = Data.Aeson.Types.ToJSON.toJSON a;
Expand All @@ -84,8 +86,9 @@ instance Data.Aeson.Types.ToJSON.ToJSON CoverTypeCoverVariants
toJSON (CoverTypeCoverTest7 a) = Data.Aeson.Types.ToJSON.toJSON a;
toJSON (CoverTypeCoverTest8 a) = Data.Aeson.Types.ToJSON.toJSON a;
toJSON (CoverTypeCoverTest9 a) = Data.Aeson.Types.ToJSON.toJSON a;
toJSON (CoverTypeCoverTest10 a) = Data.Aeson.Types.ToJSON.toJSON a}
toJSON (CoverTypeCoverTest10 a) = Data.Aeson.Types.ToJSON.toJSON a;
toJSON (CoverTypeCoverValue a) = Data.Aeson.Types.ToJSON.toJSON a}
instance Data.Aeson.Types.FromJSON.FromJSON CoverTypeCoverVariants
where {parseJSON val = case (CoverTypeCoverPetByAge Data.Functor.<$> Data.Aeson.Types.FromJSON.fromJSON val) GHC.Base.<|> ((CoverTypeCoverMischling Data.Functor.<$> Data.Aeson.Types.FromJSON.fromJSON val) GHC.Base.<|> ((CoverTypeCoverTest Data.Functor.<$> Data.Aeson.Types.FromJSON.fromJSON val) GHC.Base.<|> ((CoverTypeCoverTest2 Data.Functor.<$> Data.Aeson.Types.FromJSON.fromJSON val) GHC.Base.<|> ((CoverTypeCoverTest3 Data.Functor.<$> Data.Aeson.Types.FromJSON.fromJSON val) GHC.Base.<|> ((CoverTypeCoverTest4 Data.Functor.<$> Data.Aeson.Types.FromJSON.fromJSON val) GHC.Base.<|> ((CoverTypeCoverTest5 Data.Functor.<$> Data.Aeson.Types.FromJSON.fromJSON val) GHC.Base.<|> ((CoverTypeCoverTest6 Data.Functor.<$> Data.Aeson.Types.FromJSON.fromJSON val) GHC.Base.<|> ((CoverTypeCoverTest7 Data.Functor.<$> Data.Aeson.Types.FromJSON.fromJSON val) GHC.Base.<|> ((CoverTypeCoverTest8 Data.Functor.<$> Data.Aeson.Types.FromJSON.fromJSON val) GHC.Base.<|> ((CoverTypeCoverTest9 Data.Functor.<$> Data.Aeson.Types.FromJSON.fromJSON val) GHC.Base.<|> ((CoverTypeCoverTest10 Data.Functor.<$> Data.Aeson.Types.FromJSON.fromJSON val) GHC.Base.<|> Data.Aeson.Types.Internal.Error "No variant matched"))))))))))) of
where {parseJSON val = case (CoverTypeCoverPetByAge Data.Functor.<$> Data.Aeson.Types.FromJSON.fromJSON val) GHC.Base.<|> ((CoverTypeCoverMischling Data.Functor.<$> Data.Aeson.Types.FromJSON.fromJSON val) GHC.Base.<|> ((CoverTypeCoverTest Data.Functor.<$> Data.Aeson.Types.FromJSON.fromJSON val) GHC.Base.<|> ((CoverTypeCoverTest2 Data.Functor.<$> Data.Aeson.Types.FromJSON.fromJSON val) GHC.Base.<|> ((CoverTypeCoverTest3 Data.Functor.<$> Data.Aeson.Types.FromJSON.fromJSON val) GHC.Base.<|> ((CoverTypeCoverTest4 Data.Functor.<$> Data.Aeson.Types.FromJSON.fromJSON val) GHC.Base.<|> ((CoverTypeCoverTest5 Data.Functor.<$> Data.Aeson.Types.FromJSON.fromJSON val) GHC.Base.<|> ((CoverTypeCoverTest6 Data.Functor.<$> Data.Aeson.Types.FromJSON.fromJSON val) GHC.Base.<|> ((CoverTypeCoverTest7 Data.Functor.<$> Data.Aeson.Types.FromJSON.fromJSON val) GHC.Base.<|> ((CoverTypeCoverTest8 Data.Functor.<$> Data.Aeson.Types.FromJSON.fromJSON val) GHC.Base.<|> ((CoverTypeCoverTest9 Data.Functor.<$> Data.Aeson.Types.FromJSON.fromJSON val) GHC.Base.<|> ((CoverTypeCoverTest10 Data.Functor.<$> Data.Aeson.Types.FromJSON.fromJSON val) GHC.Base.<|> ((CoverTypeCoverValue Data.Functor.<$> Data.Aeson.Types.FromJSON.fromJSON val) GHC.Base.<|> Data.Aeson.Types.Internal.Error "No variant matched")))))))))))) of
{Data.Aeson.Types.Internal.Success a -> GHC.Base.pure a;
Data.Aeson.Types.Internal.Error a -> Control.Monad.Fail.fail a}}
50 changes: 50 additions & 0 deletions testing/golden-output/src/OpenAPI/Types/Value.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
-- CHANGE WITH CAUTION: This is a generated code file generated by https://github.com/Haskell-OpenAPI-Code-Generator/Haskell-OpenAPI-Client-Code-Generator.

{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE MultiWayIf #-}

-- | Contains the types generated from the schema Value
module OpenAPI.Types.Value where

import qualified Prelude as GHC.Integer.Type
import qualified Prelude as GHC.Maybe
import qualified Control.Monad.Fail
import qualified Data.Aeson
import qualified Data.Aeson as Data.Aeson.Encoding.Internal
import qualified Data.Aeson as Data.Aeson.Types
import qualified Data.Aeson as Data.Aeson.Types.FromJSON
import qualified Data.Aeson as Data.Aeson.Types.ToJSON
import qualified Data.Aeson as Data.Aeson.Types.Internal
import qualified Data.ByteString
import qualified Data.ByteString as Data.ByteString.Internal
import qualified Data.Foldable
import qualified Data.Functor
import qualified Data.Maybe
import qualified Data.Scientific
import qualified Data.Text
import qualified Data.Text as Data.Text.Internal
import qualified Data.Time.Calendar as Data.Time.Calendar.Days
import qualified Data.Time.LocalTime as Data.Time.LocalTime.Internal.ZonedTime
import qualified GHC.Base
import qualified GHC.Classes
import qualified GHC.Int
import qualified GHC.Show
import qualified GHC.Types
import qualified OpenAPI.Common
import OpenAPI.TypeAlias

-- | Defines the enum schema located at @components.schemas.Value@ in the specification.
--
--
data Value =
ValueOther Data.Aeson.Types.Internal.Value -- ^ This case is used if the value encountered during decoding does not match any of the provided cases in the specification.
| ValueTyped Data.Text.Internal.Text -- ^ This constructor can be used to send values to the server which are not present in the specification yet.
| ValueEnumYyy -- ^ Represents the JSON value @"yyy"@
deriving (GHC.Show.Show, GHC.Classes.Eq)
instance Data.Aeson.Types.ToJSON.ToJSON Value
where {toJSON (ValueOther val) = val;
toJSON (ValueTyped val) = Data.Aeson.Types.ToJSON.toJSON val;
toJSON (ValueEnumYyy) = "yyy"}
instance Data.Aeson.Types.FromJSON.FromJSON Value
where {parseJSON val = GHC.Base.pure (if | val GHC.Classes.== "yyy" -> ValueEnumYyy
| GHC.Base.otherwise -> ValueOther val)}
8 changes: 8 additions & 0 deletions testing/golden-output/src/OpenAPI/Types/Value.hs-boot
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module OpenAPI.Types.Value where
import qualified Data.Aeson
import qualified OpenAPI.Common
data Value
instance Show Value
instance Eq Value
instance Data.Aeson.FromJSON Value
instance Data.Aeson.ToJSON Value

0 comments on commit 124b589

Please sign in to comment.