forked from biocad/openapi3
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from jbgour/validate-not_-case
Rebase forked lib on current biocad master
- Loading branch information
Showing
8 changed files
with
352 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,19 @@ | ||
{-# LANGUAGE RecordWildCards #-} | ||
{-# LANGUAGE LambdaCase #-} | ||
-- | | ||
-- Module: Data.OpenApi.SchemaOptions | ||
-- Maintainer: Nickolay Kudasov <[email protected]> | ||
-- Stability: experimental | ||
-- | ||
-- Generic deriving options for @'ToParamSchema'@ and @'ToSchema'@. | ||
module Data.OpenApi.SchemaOptions where | ||
module Data.OpenApi.SchemaOptions ( | ||
SchemaOptions (..) | ||
, defaultSchemaOptions | ||
, fromAesonOptions | ||
) where | ||
|
||
import qualified Data.Aeson.Types as Aeson | ||
import Data.Char | ||
|
||
-- | Options that specify how to encode your type to Swagger schema. | ||
data SchemaOptions = SchemaOptions | ||
|
@@ -40,14 +46,26 @@ data SchemaOptions = SchemaOptions | |
-- @ | ||
defaultSchemaOptions :: SchemaOptions | ||
defaultSchemaOptions = SchemaOptions | ||
-- \x -> traceShowId x | ||
{ fieldLabelModifier = id | ||
, constructorTagModifier = id | ||
, datatypeNameModifier = id | ||
, datatypeNameModifier = conformDatatypeNameModifier | ||
, allNullaryToStringTag = True | ||
, unwrapUnaryRecords = False | ||
, sumEncoding = Aeson.defaultTaggedObject | ||
} | ||
|
||
|
||
-- | According to spec https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#components-object | ||
-- name must conform to ^[a-zA-Z0-9\.\-_]+$ | ||
conformDatatypeNameModifier :: String -> String | ||
conformDatatypeNameModifier = | ||
foldl (\acc x -> acc ++ convertChar x) "" | ||
where | ||
convertChar = \case | ||
c | isAlphaNum c || elem c "-._" -> [c] | ||
c -> "_" ++ (show $ ord c) ++ "_" | ||
|
||
-- | Convert 'Aeson.Options' to 'SchemaOptions'. | ||
-- | ||
-- Specifically the following fields get copied: | ||
|
Oops, something went wrong.