autodocodec-openapi3 0.2.0.0 → 0.2.1.0
raw patch · 3 files changed
+30/−13 lines, 3 files
Files
- CHANGELOG.md +8/−1
- autodocodec-openapi3.cabal +2/−2
- src/Autodocodec/OpenAPI/Schema.hs +20/−10
CHANGELOG.md view
@@ -1,12 +1,19 @@ # Changelog +## [0.2.1.0] - 2022-06-19++### Changed+* When combining alternative enum schemas, combine the enum values into one enum if they have the same type. (#17)+* Set default value on the property level instead of object level to fix generation of invalid schemas caused by the default value not matching the type of the object schema+* The generated schema for Maps and HashMaps now has a `type`` of `"object"` as well as `additionalProperties`+ ## [0.2.0.0] - 2022-04-05 ### Changed * Fixed an issue where, when using `named` and mutually recursive types, not all schemas would be declared when the top level type was declared with `declareSchemaRef` from openapi3 (#16) * Fixed an issue where using `named` would declare a named schema, but would return an un-named schema, sometimes leading to duplicate schema definitions (#16) * `declareSpecificNamedSchemaRef` and `declareSpecificSchemaRef` now work with any `MonadDeclare`, not just the `Declare` concrete monad (#16)-* Added a type field when generating enum schema from `EqCodec`. This is required so that enum values are shown in `swagger-ui`.+* Added a type field when generating enum schema from `EqCodec`. This is required so that enum values are shown in `swagger-ui`. (#15) ## [0.1.0.0] - 2021-12-23
autodocodec-openapi3.cabal view
@@ -1,11 +1,11 @@ cabal-version: 1.12 --- This file has been generated from package.yaml by hpack version 0.34.6.+-- This file has been generated from package.yaml by hpack version 0.34.7. -- -- see: https://github.com/sol/hpack name: autodocodec-openapi3-version: 0.2.0.0+version: 0.2.1.0 synopsis: Autodocodec interpreters for openapi3 homepage: https://github.com/NorfairKing/autodocodec#readme bug-reports: https://github.com/NorfairKing/autodocodec/issues
src/Autodocodec/OpenAPI/Schema.hs view
@@ -11,7 +11,7 @@ module Autodocodec.OpenAPI.Schema where import Autodocodec-import Control.Lens (Lens', (&), (?~), (^.))+import Control.Lens (Lens', (&), (.~), (?~), (^.)) import Control.Monad import Control.Monad.State.Lazy (StateT, evalStateT, runStateT) import qualified Control.Monad.State.Lazy as State@@ -67,7 +67,8 @@ pure $ NamedSchema Nothing $ mempty- { _schemaAdditionalProperties = Just $ AdditionalPropertiesSchema $ _namedSchemaSchema <$> itemsSchemaRef+ { _schemaType = Just OpenApiObject,+ _schemaAdditionalProperties = Just $ AdditionalPropertiesSchema $ _namedSchemaSchema <$> itemsSchemaRef } MapCodec c -> do itemsSchema <- go c@@ -75,7 +76,8 @@ pure $ NamedSchema Nothing $ mempty- { _schemaAdditionalProperties = Just $ AdditionalPropertiesSchema $ _namedSchemaSchema <$> itemsSchemaRef+ { _schemaType = Just OpenApiObject,+ _schemaAdditionalProperties = Just $ AdditionalPropertiesSchema $ _namedSchemaSchema <$> itemsSchemaRef } ValueCodec -> pure $@@ -163,10 +165,10 @@ OptionalKeyWithDefaultCodec key vs defaultValue mDoc -> do ns <- go vs ref <- declareSpecificNamedSchemaRef ns+ let addDefaultToSchema propertySchema = propertySchema {_schemaDefault = Just $ toJSONVia vs defaultValue} pure [ mempty- { _schemaProperties = [(key, addMDoc mDoc . _namedSchemaSchema <$> ref)],- _schemaDefault = Just $ toJSONVia vs defaultValue,+ { _schemaProperties = [(key, addDefaultToSchema . addMDoc mDoc . _namedSchemaSchema <$> ref)], _schemaType = Just OpenApiObject } ]@@ -217,11 +219,19 @@ DisjointUnion -> Nothing } pure $- NamedSchema Nothing $ case (s1 ^. orLens, s2 ^. orLens) of- (Just s1s, Just s2s) -> prototype & orLens ?~ (s1s ++ s2s)- (Just s1s, Nothing) -> prototype & orLens ?~ (s1s ++ [s2Ref])- (Nothing, Just s2s) -> prototype & orLens ?~ (s1Ref : s2s)- (Nothing, Nothing) -> prototype & orLens ?~ [s1Ref, s2Ref]+ NamedSchema Nothing $ case (s1 ^. enum_, s2 ^. enum_) of+ -- If both schemas are enums with the same type then combine their values+ (Just s1enums, Just s2enums)+ | s1 ^. type_ == s2 ^. type_ ->+ prototype+ & enum_ ?~ (s1enums ++ s2enums)+ & type_ .~ s1 ^. type_+ _ ->+ case (s1 ^. orLens, s2 ^. orLens) of+ (Just s1s, Just s2s) -> prototype & orLens ?~ (s1s ++ s2s)+ (Just s1s, Nothing) -> prototype & orLens ?~ (s1s ++ [s2Ref])+ (Nothing, Just s2s) -> prototype & orLens ?~ (s1Ref : s2s)+ (Nothing, Nothing) -> prototype & orLens ?~ [s1Ref, s2Ref] declareSpecificNamedSchemaRef :: MonadDeclare (Definitions Schema) m => OpenAPI.NamedSchema -> m (Referenced NamedSchema) declareSpecificNamedSchemaRef namedSchema =