File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ openapi : 3.0.0
2+ info :
3+ version : 1.0.0
4+ title : Multipart form data
5+
6+ paths :
7+ " /api " :
8+ post :
9+ responses :
10+ 200 :
11+ description : Response
12+ requestBody :
13+ $ref : " #/components/requestBodies/Multipart"
14+ " /noMaybes " :
15+ post :
16+ responses :
17+ 200 :
18+ description : Response
19+ requestBody :
20+ $ref : " #/components/requestBodies/MultipartNoMaybes"
21+ components :
22+ requestBodies :
23+ Multipart :
24+ # https://swagger.io/docs/specification/v3_0/describing-request-body/multipart-requests/
25+ content :
26+ multipart/form-data : # Media type
27+ schema : # Request payload
28+ type : object
29+ required :
30+ - id
31+ properties : # Request parts
32+ id : # Part 1 (string value)
33+ type : string
34+ format : uuid
35+ address : # Part2 (object)
36+ type : object
37+ properties :
38+ street :
39+ type : string
40+ city :
41+ type : string
42+ profileImage : # Part 3 (an image)
43+ type : string
44+ format : binary
45+ MultipartNoMaybes :
46+ # https://swagger.io/docs/specification/v3_0/describing-request-body/multipart-requests/
47+ content :
48+ multipart/form-data : # Media type
49+ schema : # Request payload
50+ type : object
51+ required :
52+ - id
53+ - address
54+ - profileImage
55+ properties : # Request parts
56+ id : # Part 1 (string value)
57+ type : string
58+ format : uuid
59+ address : # Part2 (object)
60+ type : object
61+ properties :
62+ street :
63+ type : string
64+ city :
65+ type : string
66+ profileImage : # Part 3 (an image)
67+ type : string
68+ format : binary
Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ import GithubV3RestApi.Api
1111import GithubV3RestApi.Types
1212import MarioPartyStats.Api
1313import MarioPartyStats.Types
14+ import MultipartFormData.Api
1415import NullableEnum.Json
1516import OpenApi.Common
1617import PatreonApi.Api
@@ -45,6 +46,9 @@ init () =
4546 let
4647 _ =
4748 SimpleRef . Json . decodeForbidden
49+
50+ _ =
51+ MultipartFormData . Api . api
4852 in
4953 ( {}
5054 , Cmd . batch
Original file line number Diff line number Diff line change 5151 marioPartyStats =
5252 OpenApi . Config . inputFrom ( OpenApi . Config . File " ./example/MarioPartyStats.json" )
5353
54+ multipartFormData : OpenApi . Config . Input
55+ multipartFormData =
56+ OpenApi . Config . inputFrom ( OpenApi . Config . File " ./example/multipart-form-data.yaml" )
57+
5458 nullableEnum : OpenApi . Config . Input
5559 nullableEnum =
5660 OpenApi . Config . inputFrom ( OpenApi . Config . File " ./example/nullable-enum.yaml" )
@@ -136,6 +140,7 @@ run =
136140 |> OpenApi . Config . withInput cookieAuth
137141 |> OpenApi . Config . withInput ifconfigOvh
138142 |> OpenApi . Config . withInput marioPartyStats
143+ |> OpenApi . Config . withInput multipartFormData
139144 |> OpenApi . Config . withInput nullableEnum
140145 |> OpenApi . Config . withInput overridingGlobalSecurity
141146 |> OpenApi . Config . withInput realworldConduit
Original file line number Diff line number Diff line change 1- module JsonSchema.Generate exposing (schemaToDeclarations )
1+ module JsonSchema.Generate exposing (multipartFormDataRequestBodyToDeclarations , schemaToDeclarations )
22
33import CliMonad exposing (CliMonad )
44import Common
@@ -16,6 +16,43 @@ import NonEmpty
1616import 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+
1956schemaToDeclarations : Common .Component -> Common .UnsafeName -> Json .Schema .Definitions .Schema -> CliMonad (List CliMonad .Declaration )
2057schemaToDeclarations component name schema =
2158 SchemaUtils . schemaToType [] schema
You can’t perform that action at this time.
0 commit comments