Skip to content

Commit

Permalink
Use NonEmpty for arrays that specify minItems > 0
Browse files Browse the repository at this point in the history
  • Loading branch information
pbrisbin committed Apr 1, 2024
1 parent 4aa2c29 commit a89d27d
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion openapi3-code-generator/src/OpenAPI/Generate/Model.hs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import qualified Data.Bifunctor as BF
import qualified Data.Either as E
import qualified Data.Int as Int
import qualified Data.List as List
import Data.List.NonEmpty (NonEmpty)
import qualified Data.Map as Map
import qualified Data.Maybe as Maybe
import qualified Data.Scientific as Scientific
Expand Down Expand Up @@ -560,7 +561,10 @@ defineArrayModelForSchema strategy schemaName schema = do
Nothing -> do
OAM.logWarning "Array type was defined without a items schema and therefore cannot be defined correctly"
pure ([t|Aeson.Object|], (emptyDoc, Set.empty))
let arrayType = appT listT type'
let arrayType =
case OAS.schemaObjectMinItems schema of
Just w | w > 0 -> appT [t|NonEmpty|] type'
_ -> appT listT type'
schemaName' <- haskellifyNameM True schemaName
OAM.logTrace $ "Define as list named '" <> T.pack (nameBase schemaName') <> "'"
path <- getCurrentPathEscaped
Expand Down

0 comments on commit a89d27d

Please sign in to comment.