Skip to content

Commit 648121b

Browse files
authored
Merge pull request #317 from wolfadex/unify-object-and-dict
Unify Object and Dict
2 parents 67dadf2 + 02dee2f commit 648121b

4 files changed

Lines changed: 493 additions & 513 deletions

File tree

src/Common.elm

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
module Common exposing
2-
( BasicType(..)
2+
( AdditionalProperties(..)
3+
, BasicType(..)
34
, Component(..)
45
, ConstValue(..)
56
, Field
67
, Module(..)
7-
, Object
88
, OneOfData
99
, Package(..)
1010
, RefTo
@@ -447,7 +447,11 @@ initialUppercaseWordToLowercase input =
447447

448448
type Type
449449
= Nullable Type
450-
| Object { isRecursive : Maybe UnsafeName } Object
450+
| Object
451+
{ isRecursive : Maybe UnsafeName
452+
, additionalProperties : AdditionalProperties
453+
, fields : List ( UnsafeName, Field )
454+
}
451455
| Basic
452456
-- This is separate for easier pattern matching
453457
BasicType
@@ -459,8 +463,6 @@ type Type
459463
| List Type
460464
| Tuple Type Type
461465
| Triple Type Type Type
462-
-- The type declared in additionalProperties, and a list of normal properties
463-
| Dict { type_ : Type, documentation : Maybe String } Object
464466
| OneOf TypeName ( OneOfData, List OneOfData )
465467
| Enum ( UnsafeName, List UnsafeName )
466468
| Value
@@ -469,6 +471,11 @@ type Type
469471
| Unit
470472

471473

474+
type AdditionalProperties
475+
= AdditionalPropertiesAllowed { type_ : Type, documentation : Maybe String }
476+
| AdditionalPropertiesDisallowed
477+
478+
472479
type RefTo r
473480
= RefTo Component UnsafeName
474481

@@ -511,10 +518,6 @@ basicTypeToString basicType =
511518
"number"
512519

513520

514-
type alias Object =
515-
List ( UnsafeName, Field )
516-
517-
518521
type alias OneOfData =
519522
{ name : UnsafeName
520523
, type_ : Type

src/JsonSchema/Generate.elm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ nonEnumToDeclarations component name schema documentation type_ =
262262
isRecursive : Bool
263263
isRecursive =
264264
case type_ of
265-
Common.Object r _ ->
265+
Common.Object r ->
266266
r.isRecursive == Just name
267267

268268
_ ->

src/OpenApi/Generate.elm

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1973,7 +1973,7 @@ multipartContent mediaType =
19731973
|> CliMonad.andThen
19741974
(\{ type_ } ->
19751975
case type_ of
1976-
Common.Object _ fields ->
1976+
Common.Object { fields } ->
19771977
fields
19781978
|> List.map
19791979
(\( fieldName, field ) ->
@@ -2207,7 +2207,7 @@ queryParameterToUrlBuilderArgument param =
22072207
Gen.Maybe.map build value
22082208
in
22092209
case type_ of
2210-
Common.Nullable (Common.Object _ fields) ->
2210+
Common.Nullable (Common.Object { fields }) ->
22112211
fields
22122212
|> CliMonad.combineMap
22132213
(\( fieldName, field ) ->
@@ -2219,7 +2219,7 @@ queryParameterToUrlBuilderArgument param =
22192219
|> CliMonad.withPath (Common.UnsafeName "query params (object)")
22202220
)
22212221

2222-
Common.Object _ fields ->
2222+
Common.Object { fields } ->
22232223
fields
22242224
|> CliMonad.combineMap
22252225
(\( fieldName, field ) ->

0 commit comments

Comments
 (0)