Skip to content

Commit c4dac2f

Browse files
authored
Merge pull request #243 from wolfadex/qualify
Remove workaround for elm-codegen improperly qualifying names
2 parents 445299a + 2116978 commit c4dac2f

File tree

3 files changed

+35
-55
lines changed

3 files changed

+35
-55
lines changed

src/JsonSchema/Generate.elm

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ schemaToDeclarations name schema =
216216
}
217217
)
218218
(CliMonad.moduleToNamespace Common.Types)
219-
(schemaToDecoder False schema)
219+
(schemaToDecoder schema)
220220
, CliMonad.map2
221221
(\typesNamespace encoder ->
222222
{ moduleName = Common.Json
@@ -231,21 +231,21 @@ schemaToDeclarations name schema =
231231
}
232232
)
233233
(CliMonad.moduleToNamespace Common.Types)
234-
(schemaToEncoder False schema)
234+
(schemaToEncoder schema)
235235
]
236236
|> CliMonad.combine
237237
)
238238
)
239239
|> CliMonad.withPath name
240240

241241

242-
schemaToDecoder : Bool -> Json.Schema.Definitions.Schema -> CliMonad Elm.Expression
243-
schemaToDecoder qualify schema =
242+
schemaToDecoder : Json.Schema.Definitions.Schema -> CliMonad Elm.Expression
243+
schemaToDecoder schema =
244244
SchemaUtils.schemaToType True schema
245-
|> CliMonad.andThen (\{ type_ } -> SchemaUtils.typeToDecoder qualify type_)
245+
|> CliMonad.andThen (\{ type_ } -> SchemaUtils.typeToDecoder type_)
246246

247247

248-
schemaToEncoder : Bool -> Json.Schema.Definitions.Schema -> CliMonad (Elm.Expression -> Elm.Expression)
249-
schemaToEncoder qualify schema =
248+
schemaToEncoder : Json.Schema.Definitions.Schema -> CliMonad (Elm.Expression -> Elm.Expression)
249+
schemaToEncoder schema =
250250
SchemaUtils.schemaToType True schema
251-
|> CliMonad.andThen (\{ type_ } -> SchemaUtils.typeToEncoder qualify type_)
251+
|> CliMonad.andThen (\{ type_ } -> SchemaUtils.typeToEncoder type_)

src/OpenApi/Generate.elm

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ unitDeclarations name =
382382
}
383383
)
384384
(CliMonad.moduleToNamespace Common.Types)
385-
(SchemaUtils.typeToDecoder False Common.Unit)
385+
(SchemaUtils.typeToDecoder Common.Unit)
386386
, CliMonad.map2
387387
(\typesNamespace encoder ->
388388
{ moduleName = Common.Json
@@ -397,7 +397,7 @@ unitDeclarations name =
397397
}
398398
)
399399
(CliMonad.moduleToNamespace Common.Types)
400-
(SchemaUtils.typeToEncoder False Common.Unit)
400+
(SchemaUtils.typeToEncoder Common.Unit)
401401
]
402402

403403

@@ -493,7 +493,7 @@ toRequestFunctions server effectTypes method pathUrl operation =
493493
)
494494

495495
JsonContent type_ ->
496-
SchemaUtils.typeToEncoder True type_
496+
SchemaUtils.typeToEncoder type_
497497
|> CliMonad.map
498498
(\encoder config ->
499499
let
@@ -2482,7 +2482,7 @@ operationToTypesExpectAndResolver functionName operation =
24822482
}
24832483
}
24842484
)
2485-
(SchemaUtils.typeToDecoder True type_)
2485+
(SchemaUtils.typeToDecoder type_)
24862486

24872487
StringContent _ ->
24882488
{ successType =
@@ -2625,7 +2625,7 @@ errorResponsesToErrorDecoders functionName errorResponses =
26252625
(\contentSchema ->
26262626
case contentSchema of
26272627
JsonContent type_ ->
2628-
SchemaUtils.typeToDecoder True type_
2628+
SchemaUtils.typeToDecoder type_
26292629

26302630
StringContent _ ->
26312631
CliMonad.succeed Gen.Json.Decode.string

src/SchemaUtils.elm

Lines changed: 22 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1355,8 +1355,8 @@ fieldToAnnotation qualify { useMaybe } { type_, required } =
13551355
CliMonad.map Gen.Maybe.annotation_.maybe annotation
13561356

13571357

1358-
typeToEncoder : Bool -> Common.Type -> CliMonad (Elm.Expression -> Elm.Expression)
1359-
typeToEncoder qualify type_ =
1358+
typeToEncoder : Common.Type -> CliMonad (Elm.Expression -> Elm.Expression)
1359+
typeToEncoder type_ =
13601360
case type_ of
13611361
Common.Basic basicType basic ->
13621362
basicTypeToEncoder basicType basic
@@ -1377,12 +1377,7 @@ typeToEncoder qualify type_ =
13771377
(\jsonNamespace rec ->
13781378
Elm.apply
13791379
(Elm.value
1380-
{ importFrom =
1381-
if qualify then
1382-
jsonNamespace
1383-
1384-
else
1385-
[]
1380+
{ importFrom = jsonNamespace
13861381
, name = "encode" ++ Common.toTypeName name
13871382
, annotation = Nothing
13881383
}
@@ -1401,7 +1396,7 @@ typeToEncoder qualify type_ =
14011396
properties
14021397
|> CliMonad.combineMap
14031398
(\( key, field ) ->
1404-
typeToEncoder qualify field.type_
1399+
typeToEncoder field.type_
14051400
|> CliMonad.map
14061401
(\encoder rec ->
14071402
let
@@ -1438,7 +1433,7 @@ typeToEncoder qualify type_ =
14381433
)
14391434

14401435
Common.List t ->
1441-
typeToEncoder qualify t
1436+
typeToEncoder t
14421437
|> CliMonad.map
14431438
(\encoder ->
14441439
Gen.Json.Encode.call_.list (Elm.functionReduced "rec" encoder)
@@ -1447,7 +1442,7 @@ typeToEncoder qualify type_ =
14471442
-- An object with additionalProperties (the type of those properties is
14481443
-- `additionalProperties`) and no normal `properties` fields: A simple Dict.
14491444
Common.Dict additionalProperties [] ->
1450-
typeToEncoder qualify additionalProperties.type_
1445+
typeToEncoder additionalProperties.type_
14511446
|> CliMonad.map
14521447
(\encoder ->
14531448
Gen.Json.Encode.call_.dict Gen.Basics.values_.identity (Elm.functionReduced "rec" encoder)
@@ -1463,7 +1458,7 @@ typeToEncoder qualify type_ =
14631458
properties
14641459
|> CliMonad.combineMap
14651460
(\( key, field ) ->
1466-
typeToEncoder qualify field.type_
1461+
typeToEncoder field.type_
14671462
|> CliMonad.map
14681463
(\encoder rec ->
14691464
let
@@ -1508,7 +1503,7 @@ typeToEncoder qualify type_ =
15081503
)
15091504
)
15101505
)
1511-
(typeToEncoder qualify additionalProperties.type_)
1506+
(typeToEncoder additionalProperties.type_)
15121507

15131508
Common.Nullable t ->
15141509
CliMonad.map
@@ -1524,7 +1519,7 @@ typeToEncoder qualify type_ =
15241519
encoder
15251520
]
15261521
)
1527-
(typeToEncoder qualify t)
1522+
(typeToEncoder t)
15281523

15291524
Common.Value ->
15301525
CliMonad.succeed <| Gen.Basics.identity
@@ -1534,12 +1529,7 @@ typeToEncoder qualify type_ =
15341529
(\jsonNamespace name rec ->
15351530
Elm.apply
15361531
(Elm.value
1537-
{ importFrom =
1538-
if qualify then
1539-
jsonNamespace
1540-
1541-
else
1542-
[]
1532+
{ importFrom = jsonNamespace
15431533
, name = "encode" ++ Common.toTypeName name
15441534
, annotation = Nothing
15451535
}
@@ -1562,7 +1552,7 @@ typeToEncoder qualify type_ =
15621552
variantEncoder
15631553
)
15641554
(typeToAnnotationWithNullable True variant.type_)
1565-
(typeToEncoder qualify variant.type_)
1555+
(typeToEncoder variant.type_)
15661556
)
15671557
|> CliMonad.map2
15681558
(\typesNamespace branches rec ->
@@ -1629,8 +1619,8 @@ refToTypeName ref =
16291619
CliMonad.fail <| "Couldn't get the type ref (" ++ String.join "/" ref ++ ") for the response"
16301620

16311621

1632-
typeToDecoder : Bool -> Common.Type -> CliMonad Elm.Expression
1633-
typeToDecoder qualify type_ =
1622+
typeToDecoder : Common.Type -> CliMonad Elm.Expression
1623+
typeToDecoder type_ =
16341624
case type_ of
16351625
Common.Object properties ->
16361626
List.foldl
@@ -1650,7 +1640,7 @@ typeToDecoder qualify type_ =
16501640
)
16511641
prevExpr
16521642
)
1653-
(typeToDecoder qualify field.type_)
1643+
(typeToDecoder field.type_)
16541644
prevExprRes
16551645
)
16561646
(CliMonad.succeed
@@ -1681,11 +1671,11 @@ typeToDecoder qualify type_ =
16811671

16821672
Common.List t ->
16831673
CliMonad.map Gen.Json.Decode.list
1684-
(typeToDecoder qualify t)
1674+
(typeToDecoder t)
16851675

16861676
Common.Dict additionalProperties [] ->
16871677
CliMonad.map Gen.Json.Decode.dict
1688-
(typeToDecoder qualify additionalProperties.type_)
1678+
(typeToDecoder additionalProperties.type_)
16891679

16901680
Common.Dict additionalProperties properties ->
16911681
properties
@@ -1706,7 +1696,7 @@ typeToDecoder qualify type_ =
17061696
)
17071697
)
17081698
)
1709-
(typeToDecoder qualify field.type_)
1699+
(typeToDecoder field.type_)
17101700
prevExprRes
17111701
)
17121702
(CliMonad.succeed
@@ -1837,7 +1827,7 @@ typeToDecoder qualify type_ =
18371827
)
18381828
)
18391829
)
1840-
(typeToDecoder qualify additionalProperties.type_)
1830+
(typeToDecoder additionalProperties.type_)
18411831

18421832
Common.Enum variants ->
18431833
CliMonad.enumName variants
@@ -1874,12 +1864,7 @@ typeToDecoder qualify type_ =
18741864
CliMonad.map
18751865
(\jsonNamespace ->
18761866
Elm.value
1877-
{ importFrom =
1878-
if qualify then
1879-
jsonNamespace
1880-
1881-
else
1882-
[]
1867+
{ importFrom = jsonNamespace
18831868
, name = "decode" ++ Common.toTypeName name
18841869
, annotation = Nothing
18851870
}
@@ -1901,18 +1886,13 @@ typeToDecoder qualify type_ =
19011886
OpenApi.Common.Internal.make_.null
19021887
]
19031888
)
1904-
(typeToDecoder qualify t)
1889+
(typeToDecoder t)
19051890

19061891
Common.Ref ref ->
19071892
CliMonad.map2
19081893
(\jsonNamespace name ->
19091894
Elm.value
1910-
{ importFrom =
1911-
if qualify then
1912-
jsonNamespace
1913-
1914-
else
1915-
[]
1895+
{ importFrom = jsonNamespace
19161896
, name = "decode" ++ Common.toTypeName name
19171897
, annotation = Nothing
19181898
}
@@ -1924,7 +1904,7 @@ typeToDecoder qualify type_ =
19241904
variants
19251905
|> CliMonad.combineMap
19261906
(\variant ->
1927-
typeToDecoder qualify variant.type_
1907+
typeToDecoder variant.type_
19281908
|> CliMonad.map2
19291909
(\typesNamespace ->
19301910
Gen.Json.Decode.call_.map

0 commit comments

Comments
 (0)