Skip to content

Commit

Permalink
Does not generate code when additionalProperties is false
Browse files Browse the repository at this point in the history
This modifies the previous commit to generate no code when the
`additionalProperties` field is set to `false`. The relevavnt
config field has been renamed to `strictAdditionalProperties`, with
the value determining the behavior when the `additionalProperties`
field is `false`:

- `True`: We raise an error.
- `False`: We ignore the field and generate no code for it.
  • Loading branch information
AugmenTab committed Apr 10, 2024
1 parent b891944 commit 0b7d610
Show file tree
Hide file tree
Showing 7 changed files with 149 additions and 122 deletions.
2 changes: 1 addition & 1 deletion json-fleece-codegen-util/codegen-prelude.dhall
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ let
baseConfig =
{ defaultTypeOptions = TypeOptions.default
, typeOptions = [] : List SpecificTypeOptions
, ignoreAdditionalProperties = True
, strictAdditionalProperties = True
}

in
Expand Down
2 changes: 1 addition & 1 deletion json-fleece-codegen-util/src/Fleece/CodeGenUtil.hs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ data CodeGenOptions = CodeGenOptions
{ moduleBaseName :: T.Text
, defaultTypeOptions :: TypeOptions
, typeOptionsMap :: Map.Map T.Text TypeOptions
, ignoreAdditionalProperties :: Bool
, strictAdditionalProperties :: Bool
}

data TypeOptions = TypeOptions
Expand Down
2 changes: 1 addition & 1 deletion json-fleece-codegen-util/src/Fleece/CodeGenUtil/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ decoder =
<$> Dhall.field "moduleBaseName" Dhall.strictText
<*> Dhall.field "defaultTypeOptions" typeOptionsDecoder
<*> Dhall.field "typeOptions" typeOptionsMapDecoder
<*> Dhall.field "ignoreAdditionalProperties" Dhall.bool
<*> Dhall.field "strictAdditionalProperties" Dhall.bool
)
<*> Dhall.field "inputFileName" Dhall.string
<*> Dhall.field "destination" Dhall.string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ module TestCases.Types.MixedInAdditionalPropertiesFalse
, mixedInAdditionalPropertiesFalseSchema
) where

import qualified Data.Map as Map
import qualified Data.Text as T
import Fleece.Core ((#*), (#+))
import Fleece.Core ((#+))
import qualified Fleece.Core as FC
import Prelude (($), Eq, Maybe, Show)
import qualified TestCases.Types.MixedInAdditionalPropertiesFalse.Bar as Bar
Expand All @@ -16,7 +14,6 @@ import qualified TestCases.Types.MixedInAdditionalPropertiesFalse.Foo as Foo
data MixedInAdditionalPropertiesFalse = MixedInAdditionalPropertiesFalse
{ bar :: Maybe Bar.Bar
, foo :: Maybe Foo.Foo
, additionalProperties :: (Map.Map T.Text FC.AnyJSON)
}
deriving (Eq, Show)

Expand All @@ -25,5 +22,4 @@ mixedInAdditionalPropertiesFalseSchema =
FC.object $
FC.constructor MixedInAdditionalPropertiesFalse
#+ FC.optional "bar" bar Bar.barSchema
#+ FC.optional "foo" foo Foo.fooSchema
#* FC.additionalFields additionalProperties FC.anyJSON
#+ FC.optional "foo" foo Foo.fooSchema
1 change: 1 addition & 0 deletions json-fleece-openapi3/examples/test-cases/codegen.dhall
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ in
{ moduleBaseName = "TestCases"
, inputFileName = "${rootDir}/test-cases.yaml"
, destination = rootDir
, strictAdditionalProperties = False
, typeOptions =
[ { type = "TestCases.Types.CustomDateFormat.CustomDateFormat"
, options =
Expand Down
2 changes: 1 addition & 1 deletion json-fleece-openapi3/examples/test-cases/test-cases.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,7 @@ components:

MixedInAdditionalPropertiesFalse:
type: object
description: An object with additionalProperties = false mixed in with other properties. This will produce an error if `ignoreAdditionalProperties` is set to `False`.
description: An object with additionalProperties = false mixed in with other properties. This will produce an error if `strictAdditionalProperties` is set to `True`.
properties:
foo:
type: string
Expand Down
Loading

0 comments on commit 0b7d610

Please sign in to comment.