packages feed

autodocodec-openapi3 0.2.1.4 → 0.3.0.1

raw patch · 5 files changed

+16/−36 lines, 5 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

- Autodocodec.OpenAPI.DerivingVia: instance (Data.Typeable.Internal.Typeable a, Autodocodec.Class.HasCodec a) => Data.OpenApi.Internal.Schema.ToSchema (Autodocodec.DerivingVia.Autodocodec a)
- Autodocodec.OpenAPI.DerivingVia.NonOrphan: AutodocodecOpenApi :: a -> AutodocodecOpenApi a
- Autodocodec.OpenAPI.DerivingVia.NonOrphan: [unAutodocodecSwagger] :: AutodocodecOpenApi a -> a
- Autodocodec.OpenAPI.DerivingVia.NonOrphan: instance (Data.Typeable.Internal.Typeable a, Autodocodec.Class.HasCodec a) => Data.OpenApi.Internal.Schema.ToSchema (Autodocodec.OpenAPI.DerivingVia.NonOrphan.AutodocodecOpenApi a)
- Autodocodec.OpenAPI.DerivingVia.NonOrphan: newtype AutodocodecOpenApi a
+ Autodocodec.OpenAPI.DerivingVia: AutodocodecOpenApi :: a -> AutodocodecOpenApi a
+ Autodocodec.OpenAPI.DerivingVia: [unAutodocodecSwagger] :: AutodocodecOpenApi a -> a
+ Autodocodec.OpenAPI.DerivingVia: instance (Data.Typeable.Internal.Typeable a, Autodocodec.Class.HasCodec a) => Data.OpenApi.Internal.Schema.ToSchema (Autodocodec.OpenAPI.DerivingVia.AutodocodecOpenApi a)
+ Autodocodec.OpenAPI.DerivingVia: newtype AutodocodecOpenApi a

Files

CHANGELOG.md view
@@ -1,5 +1,13 @@ # Changelog +## [0.3.0.1] - 2025-07-09++* Fix discriminated union OpenAPI schema generation (see #61 for more info)++## [0.3.0.0] - 2024-07-29++* Dropped support for orphan instances.+ ## [0.2.1.4] - 2024-07-29  * Non-orphan version of the `ToSchema` deriving.
autodocodec-openapi3.cabal view
@@ -1,11 +1,11 @@ cabal-version: 1.12 --- This file has been generated from package.yaml by hpack version 0.36.0.+-- This file has been generated from package.yaml by hpack version 0.36.1. -- -- see: https://github.com/sol/hpack  name:           autodocodec-openapi3-version:        0.2.1.4+version:        0.3.0.1 synopsis:       Autodocodec interpreters for openapi3 homepage:       https://github.com/NorfairKing/autodocodec#readme bug-reports:    https://github.com/NorfairKing/autodocodec/issues@@ -27,7 +27,6 @@   exposed-modules:       Autodocodec.OpenAPI       Autodocodec.OpenAPI.DerivingVia-      Autodocodec.OpenAPI.DerivingVia.NonOrphan       Autodocodec.OpenAPI.Schema   other-modules:       Paths_autodocodec_openapi3
src/Autodocodec/OpenAPI/DerivingVia.hs view
@@ -1,26 +1,18 @@ {-# LANGUAGE ScopedTypeVariables #-}-{-# OPTIONS_GHC -fno-warn-orphans #-}  module Autodocodec.OpenAPI.DerivingVia where -import Autodocodec (Autodocodec, HasCodec)+import Autodocodec.Class (HasCodec) import Autodocodec.OpenAPI.Schema (declareNamedSchemaViaCodec) import qualified Data.OpenApi as OpenAPI import Data.Proxy (Proxy (Proxy)) import Data.Typeable (Typeable) +newtype AutodocodecOpenApi a = AutodocodecOpenApi {unAutodocodecSwagger :: a}+ -- | An instance for 'Autodocodec' that lets you use 'DerivingVia' to derive 'OpenAPI.ToSchema' if your type has a 'HasCodec' instance. -- -- > deriving (OpenAPI.ToSchema) via (Autodocodec FooBar)-instance (Typeable a, HasCodec a) => OpenAPI.ToSchema (Autodocodec a) where-  -- This is declared like this as because now 'declareNamedSchema' takes no arguments, it can be memoized (like a top level variable is).-  -- As a result, the result of the 'let', that is the schema, should also be memoized,-  -- so with this definition schema in 'declaredNamedSchema' should only need to be calculated once IF the instance is of the form:-  -- > deriving (OpenAPI.ToSchema) via (Autodocodec FooBar)-  -- where FooBar is a concrete type.-  -- If the instance is of the form:-  -- > deriving via (Autodocodec (FooBar a)) instance (OpenAPI.ToSchema (FooBar a))-  -- this memoisation trick probably won't work (as 'declaredNamedSchema' actually is a function due to hiddent typeclass dictionary arguments)-  -- but it shouldn't hurt to try. See:-  -- https://stackoverflow.com/questions/77056264/caching-an-expensive-to-compute-result-in-a-class-instance+instance (Typeable a, HasCodec a) => OpenAPI.ToSchema (AutodocodecOpenApi a) where+  -- See comments in 'Autodocodec.OpenAPI.DerivingVia' for the reason why this is defined like this.   declareNamedSchema = let schema = declareNamedSchemaViaCodec (Proxy :: Proxy a) in const schema
− src/Autodocodec/OpenAPI/DerivingVia/NonOrphan.hs
@@ -1,18 +0,0 @@-{-# LANGUAGE ScopedTypeVariables #-}--module Autodocodec.OpenAPI.DerivingVia.NonOrphan where--import Autodocodec.Class (HasCodec)-import Autodocodec.OpenAPI.Schema (declareNamedSchemaViaCodec)-import qualified Data.OpenApi as OpenAPI-import Data.Proxy (Proxy (Proxy))-import Data.Typeable (Typeable)--newtype AutodocodecOpenApi a = AutodocodecOpenApi {unAutodocodecSwagger :: a}---- | An instance for 'Autodocodec' that lets you use 'DerivingVia' to derive 'OpenAPI.ToSchema' if your type has a 'HasCodec' instance.------ > deriving (OpenAPI.ToSchema) via (Autodocodec FooBar)-instance (Typeable a, HasCodec a) => OpenAPI.ToSchema (AutodocodecOpenApi a) where-  -- See comments in 'Autodocodec.OpenAPI.DerivingVia' for the reason why this is defined like this.-  declareNamedSchema = let schema = declareNamedSchemaViaCodec (Proxy :: Proxy a) in const schema
src/Autodocodec/OpenAPI/Schema.hs view
@@ -6,7 +6,6 @@ {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE RecordWildCards #-} {-# LANGUAGE ScopedTypeVariables #-}-{-# OPTIONS_GHC -fno-warn-orphans #-}  module Autodocodec.OpenAPI.Schema where @@ -195,7 +194,7 @@         let d =               Discriminator                 { _discriminatorPropertyName = pn,-                  _discriminatorMapping = InsOrdHashMap.fromHashMap $ fmap fst m+                  _discriminatorMapping = InsOrdHashMap.fromHashMap $ fmap (\x -> "#/components/schemas/" <> fst x) m                 }             mkSchema dName (refName, oc) = do               s <- goObject $ oc *> (requiredFieldWith' pn (literalTextCodec dName) .= const dName)