Skip to content

Commit

Permalink
Ignores additional properties by default
Browse files Browse the repository at this point in the history
This adds a config field `ignoreAdditionalProperties` which is
defaulted to `True`. When code gen encounters
`additionalProperties: false`, we now ignore it or produce an
error based on the value of that config field.
  • Loading branch information
AugmenTab committed Apr 9, 2024
1 parent 9ff6be9 commit 6019573
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 2 deletions.
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 @@ -34,6 +34,7 @@ let
baseConfig =
{ defaultTypeOptions = TypeOptions.default
, typeOptions = [] : List SpecificTypeOptions
, ignoreAdditionalProperties = True
}

in
Expand Down
1 change: 1 addition & 0 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
{ moduleBaseName :: T.Text
, defaultTypeOptions :: TypeOptions
, typeOptionsMap :: Map.Map T.Text TypeOptions
, ignoreAdditionalProperties :: Bool
}

data TypeOptions = TypeOptions
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 @@ -26,6 +26,7 @@ decoder =
<$> Dhall.field "moduleBaseName" Dhall.strictText
<*> Dhall.field "defaultTypeOptions" typeOptionsDecoder
<*> Dhall.field "typeOptions" typeOptionsMapDecoder
<*> Dhall.field "ignoreAdditionalProperties" Dhall.bool
)
<*> Dhall.field "inputFileName" Dhall.string
<*> Dhall.field "destination" Dhall.string
Expand Down
1 change: 1 addition & 0 deletions json-fleece-openapi3/json-fleece-openapi3.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -2025,6 +2025,7 @@ library
, containers ==0.6.*
, insert-ordered-containers ==0.2.*
, json-fleece-codegen-util ==0.8.*
, mtl ==2.2.*
, non-empty-text ==0.2.*
, openapi3 ==3.2.*
, text >=1.2 && <2.1
Expand Down
1 change: 1 addition & 0 deletions json-fleece-openapi3/package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ library:
- aeson >= 2.0 && < 2.2
- insert-ordered-containers >= 0.2 && < 0.3
- containers >= 0.6 && < 0.7
- mtl >= 2.2 && < 2.3
- non-empty-text >= 0.2 && < 0.3
- openapi3 >= 3.2 && < 3.3
- text >= 1.2 && < 2.1
Expand Down
16 changes: 14 additions & 2 deletions json-fleece-openapi3/src/Fleece/OpenApi3.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module Fleece.OpenApi3
) where

import Control.Monad (join, (<=<))
import Control.Monad.Reader (asks)
import qualified Data.Aeson as Aeson
import Data.Bifunctor (bimap, first)
import qualified Data.HashMap.Strict.InsOrd as IOHM
Expand Down Expand Up @@ -1257,8 +1258,19 @@ mkAdditionalPropertiesSchema raiseError schemaKey mkInlineItemSchema mbAdditiona
pure
. schemaInfoWithoutDependencies
$ CGU.anyJSONSchemaTypeInfo
Just (OA.AdditionalPropertiesAllowed False) ->
raiseError "Schemas for objects with additional properties disallowed are not yet supported."
Just (OA.AdditionalPropertiesAllowed False) -> do
ignoreAdditionalProperties <- asks CGU.ignoreAdditionalProperties
if ignoreAdditionalProperties
then
pure
. schemaInfoWithoutDependencies
$ CGU.anyJSONSchemaTypeInfo
else
raiseError $
"Schemas for objects with additional properties disallowed are"
<> " not yet supported. `additionalProperties: false` can be"
<> " ignored by setting the `ignoreAdditionalProperties` field"
<> " in the Fleece code gen config to false."
Just (OA.AdditionalPropertiesSchema (OA.Ref ref)) ->
pure $
SchemaTypeInfoWithDeps
Expand Down

0 comments on commit 6019573

Please sign in to comment.