Skip to content

Commit d7ceed2

Browse files
committed
WIP
1 parent 259e7a6 commit d7ceed2

3 files changed

Lines changed: 1024 additions & 716 deletions

File tree

src/JsonSchema/Generate.elm

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module JsonSchema.Generate exposing (schemaToDeclarations)
1+
module JsonSchema.Generate exposing (multipartFormDataRequestBodyToDeclarations, schemaToDeclarations)
22

33
import CliMonad exposing (CliMonad)
44
import Common
@@ -16,6 +16,43 @@ import NonEmpty
1616
import SchemaUtils
1717

1818

19+
multipartFormDataRequestBodyToDeclarations : Common.UnsafeName -> Json.Schema.Definitions.Schema -> CliMonad (List CliMonad.Declaration)
20+
multipartFormDataRequestBodyToDeclarations name schema =
21+
SchemaUtils.schemaToType [] schema
22+
|> CliMonad.andThen
23+
(\{ type_, documentation } ->
24+
type_
25+
|> SchemaUtils.typeToAnnotationWithNullable
26+
|> CliMonad.map
27+
(\annotation ->
28+
let
29+
typeName : Common.TypeName
30+
typeName =
31+
Common.toTypeName name
32+
in
33+
if (Elm.ToString.annotation annotation).signature == typeName then
34+
[]
35+
36+
else
37+
[ { moduleName = Common.Types Common.RequestBody
38+
, name = typeName
39+
, declaration =
40+
Elm.alias typeName annotation
41+
|> (case documentation of
42+
Nothing ->
43+
identity
44+
45+
Just doc ->
46+
Elm.withDocumentation doc
47+
)
48+
|> Elm.expose
49+
, group = "Aliases"
50+
}
51+
]
52+
)
53+
)
54+
55+
1956
schemaToDeclarations : Common.Component -> Common.UnsafeName -> Json.Schema.Definitions.Schema -> CliMonad (List CliMonad.Declaration)
2057
schemaToDeclarations component name schema =
2158
SchemaUtils.schemaToType [] schema

0 commit comments

Comments
 (0)