Skip to content

Commit f0c3b7f

Browse files
committed
WIP: Improves names in generated OpenAPI specs
1 parent 4a00694 commit f0c3b7f

16 files changed

+512
-252
lines changed

.helix/languages.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[language-server.haskell-language-server]
2+
command = "docker"
3+
args = ["compose", "run", "--rm", "-T", "dev", "haskell-language-server-wrapper", "--lsp"]
4+
5+
[language-server.haskell-language-server.config]
6+
haskell.formattingProvider = "fourmolu"
7+
haskell.plugin.hlint.globalOn = false
8+

orb.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ cabal-version: 1.12
55
-- see: https://github.com/sol/hpack
66

77
name: orb
8-
version: 0.5.0.2
8+
version: 0.6.0.0.4
99
description: Please see the README on GitHub at <https://github.com/flipstone/orb#readme>
1010
homepage: https://github.com/flipstone/orb#readme
1111
bug-reports: https://github.com/flipstone/orb/issues

package.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: orb
2-
version: 0.5.0.2
2+
version: 0.6.0.0.4
33
github: "flipstone/orb"
44
license: MIT
55
author: "Flipstone Technology Partners, Inc"

src/Orb/Main.hs

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module Orb.Main
33
, mainParserInfo
44
, mainParser
55
, mainParserWithCommands
6+
, openApiOptionsParser
67
, openApiLabelArgument
78
, generateOpenApiCommand
89
, generateOpenApiMain
@@ -11,6 +12,7 @@ module Orb.Main
1112
import Data.Aeson.Encode.Pretty qualified as AesonPretty
1213
import Data.ByteString.Lazy qualified as LBS
1314
import Data.List qualified as List
15+
import Data.Set qualified as Set
1416
import Options.Applicative qualified as Opt
1517
import System.Exit qualified as Exit
1618
import System.IO qualified as IO
@@ -76,7 +78,36 @@ mainParserWithCommands commands routes =
7678
-}
7779
generateOpenApiCommand :: OpenApi.OpenApiRouter a -> Opt.Mod Opt.CommandFields (IO ())
7880
generateOpenApiCommand routes =
79-
Opt.command "generate-open-api" (Opt.info (generateOpenApiMain routes <$> openApiLabelArgument routes) mempty)
81+
let
82+
parser =
83+
generateOpenApiMain
84+
<$> openApiOptionsParser
85+
<*> pure routes
86+
<*> openApiLabelArgument routes
87+
in
88+
Opt.command "generate-open-api" (Opt.info parser mempty)
89+
90+
{- |
91+
Constructs a 'Opt.Parser' that will parse command line options to control
92+
how the OpenApi spec is generated.
93+
-}
94+
openApiOptionsParser :: Opt.Parser OpenApi.OpenApiOptions
95+
openApiOptionsParser =
96+
let
97+
mkOpts allowedChars =
98+
OpenApi.defaultOpenApiOptions
99+
{ OpenApi.openApiAllowedSchemaNameChars = Set.fromList allowedChars
100+
}
101+
in
102+
mkOpts
103+
<$> Opt.option
104+
Opt.str
105+
( Opt.long "allowed-chars"
106+
<> Opt.metavar "CHARS"
107+
<> Opt.help "e.g. abcdefg12345"
108+
<> Opt.value (Set.toList (OpenApi.openApiAllowedSchemaNameChars OpenApi.defaultOpenApiOptions))
109+
<> Opt.showDefault
110+
)
80111

81112
{- |
82113
Constructs a 'Opt.Parser' than will parse an argument representing one
@@ -110,9 +141,9 @@ parserPrefs =
110141
the @generate-open-api@ command in their own main functions without
111142
using @optparse-applicative@.
112143
-}
113-
generateOpenApiMain :: OpenApi.OpenApiRouter a -> String -> IO ()
114-
generateOpenApiMain routes label =
115-
case OpenApi.mkOpenApi routes label of
144+
generateOpenApiMain :: OpenApi.OpenApiOptions -> OpenApi.OpenApiRouter a -> String -> IO ()
145+
generateOpenApiMain options routes label =
146+
case OpenApi.mkOpenApi options routes label of
116147
Left err -> do
117148
IO.hPutStrLn IO.stderr ("Unable to generate OpenApi Spec for " <> label <> "!")
118149
IO.hPutStrLn IO.stderr err

0 commit comments

Comments
 (0)