Skip to content

Commit

Permalink
OpenAPI (#251): support Integer in response
Browse files Browse the repository at this point in the history
  • Loading branch information
AshleyYakeley committed Apr 28, 2024
1 parent e7e8589 commit 0a13d7d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
8 changes: 7 additions & 1 deletion Pinafore/pinafore-webapi/lib/Pinafore/WebAPI/OpenAPI.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import qualified Data.Aeson.Key as Aeson
import qualified Data.Aeson.KeyMap as Aeson
import qualified Data.HashMap.Strict.InsOrd as InsOrd
import Data.OpenApi hiding (items, name, schema)
import qualified Data.Scientific as Scientific
import Data.Shim
import Pinafore.Language
import Pinafore.Language.API
Expand Down Expand Up @@ -104,6 +105,12 @@ mkResponse =
MkIOShimWit qType $ \case
Bool x -> return x
_ -> fail "not Boolean"
IntegerJSONType ->
return $
MkIOShimWit qType $ \case
Number x
| Just (i :: Int64) <- Scientific.toBoundedInteger x -> return $ toInteger i
_ -> fail "not Integer"
StringJSONType ->
return $
MkIOShimWit qType $ \case
Expand All @@ -129,7 +136,6 @@ mkResponse =
MkIOShimWit tl $ \case
Object x -> fl x
_ -> fail "not List"
t -> throwExc $ "response NYI: " <> showText t

mkParamResponse :: JSONParamType -> M (Text, IOShimWit (Maybe Value))
mkParamResponse (MkJSONParamType k (MkJSONOptType opt jt)) = do
Expand Down
1 change: 1 addition & 0 deletions Pinafore/pinafore-webapi/package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ library:
- base >= 4.16
- insert-ordered-containers
- network-uri
- scientific
- aeson
- openapi3
- shapes
Expand Down
1 change: 1 addition & 0 deletions Pinafore/pinafore-webapi/pinafore-webapi.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ library
, openapi3
, pinafore-language
, polar-shim
, scientific
, shapes
default-language: GHC2021

Expand Down

0 comments on commit 0a13d7d

Please sign in to comment.