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

Add useOptionalNullable codegen option #47

Merged
merged 1 commit into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions json-fleece-codegen-util/codegen-prelude.dhall
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ let
{ defaultTypeOptions = TypeOptions.default
, typeOptions = [] : List SpecificTypeOptions
, strictAdditionalProperties = True
, useOptionalNullable = False
}

in
Expand Down
4 changes: 2 additions & 2 deletions json-fleece-codegen-util/json-fleece-codegen-util.cabal
Original file line number Diff line number Diff line change
@@ -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.37.0.
--
-- see: https://github.com/sol/hpack

name: json-fleece-codegen-util
version: 0.11.0.0
version: 0.12.0.0
description: Please see the README on GitHub at <https://github.com/githubuser/json-fleece-codegen-util#readme>
homepage: https://github.com/flipstone/json-fleece#readme
bug-reports: https://github.com/flipstone/json-fleece/issues
Expand Down
2 changes: 1 addition & 1 deletion json-fleece-codegen-util/package.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: json-fleece-codegen-util
version: 0.11.0.0
version: 0.12.0.0
github: "flipstone/json-fleece/json-fleece-codegen-util"
license: BSD3
author: "Author name here"
Expand Down
14 changes: 8 additions & 6 deletions json-fleece-codegen-util/src/Fleece/CodeGenUtil.hs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ data CodeGenOptions = CodeGenOptions
, defaultTypeOptions :: TypeOptions
, typeOptionsMap :: Map.Map T.Text TypeOptions
, strictAdditionalProperties :: Bool
, useOptionalNullable :: Bool
}

data TypeOptions = TypeOptions
Expand Down Expand Up @@ -1659,6 +1660,7 @@ generateFleeceObject typeMap references typeName rawCodeGenFields mbAdditionalPr
traverse (mkFleeceSchemaField typeMap moduleName) codeGenFields

mbAdditionalPropertiesSchemaTypeInfo <- mapM (schemaInfoOrRefToSchemaTypeInfo typeMap . codeGenAdditionalPropertiesSchemaInfoOrRef) mbAdditionalProperties
useOptionalNullableBool <- asks useOptionalNullable

let
additionalPropsFieldNameAndType =
Expand All @@ -1685,7 +1687,7 @@ generateFleeceObject typeMap references typeName rawCodeGenFields mbAdditionalPr
fleeceField field =
HC.addReferences [HC.VarReference "Fleece.Core" Nothing "(#+)"] $
"#+ "
<> fleeceFieldFunction field
<> fleeceFieldFunction field useOptionalNullableBool
<> " "
<> HC.stringLiteral (fieldJSONName field)
<> " "
Expand Down Expand Up @@ -1792,11 +1794,11 @@ fieldFleeceSchemaCode :: FleeceSchemaField -> HC.HaskellCode
fieldFleeceSchemaCode =
schemaTypeSchema . fieldBaseSchemaTypeInfo

fleeceFieldFunction :: FleeceSchemaField -> HC.HaskellCode
fleeceFieldFunction field =
if fieldRequired field
then fleeceCoreVar "required"
else fleeceCoreVar "optional"
fleeceFieldFunction :: FleeceSchemaField -> Bool -> HC.HaskellCode
fleeceFieldFunction field useOptionalNullableBool
| fieldRequired field = fleeceCoreVar "required"
| useOptionalNullableBool = fleeceCoreVar "optionalNullable"
| otherwise = fleeceCoreVar "optional"

mkFleeceSchemaField ::
CodeGenMap ->
Expand Down
1 change: 1 addition & 0 deletions json-fleece-codegen-util/src/Fleece/CodeGenUtil/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ decoder =
<*> Dhall.field "defaultTypeOptions" typeOptionsDecoder
<*> Dhall.field "typeOptions" typeOptionsMapDecoder
<*> Dhall.field "strictAdditionalProperties" Dhall.bool
<*> Dhall.field "useOptionalNullable" Dhall.bool
)
<*> Dhall.field "inputFileName" Dhall.string
<*> Dhall.field "destination" Dhall.string
Expand Down
6 changes: 3 additions & 3 deletions json-fleece-openapi3/json-fleece-openapi3.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -2058,7 +2058,7 @@ library
, base >=4.7 && <5
, containers ==0.6.*
, insert-ordered-containers ==0.2.*
, json-fleece-codegen-util ==0.11.*
, json-fleece-codegen-util ==0.12.*
, mtl >=2.2 && <2.4
, non-empty-text ==0.2.*
, openapi3 ==3.2.*
Expand All @@ -2078,7 +2078,7 @@ executable fleece-openapi3
ghc-options: -rtsopts -threaded
build-depends:
base >=4.7 && <5
, json-fleece-codegen-util ==0.11.*
, json-fleece-codegen-util ==0.12.*
, json-fleece-openapi3
default-language: Haskell2010
if flag(strict)
Expand All @@ -2099,7 +2099,7 @@ test-suite json-fleece-openapi3-test
, bytestring >=0.11 && <0.13
, file-embed >=0.0.15 && <0.0.17
, hedgehog
, json-fleece-codegen-util ==0.11.*
, json-fleece-codegen-util ==0.12.*
, json-fleece-openapi3
, yaml ==0.11.*
default-language: Haskell2010
Expand Down
2 changes: 1 addition & 1 deletion json-fleece-openapi3/package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ when:

dependencies:
- base >= 4.7 && < 5
- json-fleece-codegen-util >= 0.11 && < 0.12
- json-fleece-codegen-util >= 0.12 && < 0.13

extra-source-files:
- examples/star-trek/codegen.dhall
Expand Down
6 changes: 3 additions & 3 deletions json-fleece-swagger2/json-fleece-swagger2.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ library
build-depends:
base >=4.7 && <5
, insert-ordered-containers ==0.2.*
, json-fleece-codegen-util ==0.11.*
, json-fleece-codegen-util ==0.12.*
, json-fleece-openapi3 ==0.4.*
, openapi3 ==3.2.*
, swagger2 ==2.8.*
Expand All @@ -105,7 +105,7 @@ executable fleece-swagger2
ghc-options: -rtsopts -threaded
build-depends:
base >=4.7 && <5
, json-fleece-codegen-util ==0.11.*
, json-fleece-codegen-util ==0.12.*
, json-fleece-swagger2
default-language: Haskell2010
if flag(strict)
Expand All @@ -127,7 +127,7 @@ test-suite json-fleece-swagger2-test
, bytestring >=0.11 && <0.13
, file-embed >=0.0.15 && <0.0.17
, hedgehog
, json-fleece-codegen-util ==0.11.*
, json-fleece-codegen-util ==0.12.*
, json-fleece-swagger2
default-language: Haskell2010
if flag(strict)
Expand Down
2 changes: 1 addition & 1 deletion json-fleece-swagger2/package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ description: Please see the README on GitHub at <https://github.com/gith

dependencies:
- base >= 4.7 && < 5
- json-fleece-codegen-util >= 0.11 && < 0.12
- json-fleece-codegen-util >= 0.12 && < 0.13

flags:
strict:
Expand Down
2 changes: 1 addition & 1 deletion scripts/lib/run-in-container.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ if [ "$IN_DEV_CONTAINER" ]; then
:
else
docker compose build
exec docker compose run dev $0 "$@"
exec docker compose run --rm dev $0 "$@"
fi