Skip to content

Commit 5788d68

Browse files
committed
Add docstrings for package
1 parent 9122e18 commit 5788d68

2 files changed

Lines changed: 212 additions & 26 deletions

File tree

src/Common.elm

Lines changed: 100 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,29 @@
11
module Common exposing
2-
( BasicType(..)
3-
, ConstValue(..)
4-
, Field
5-
, Module(..)
6-
, Object
7-
, OneOfData
8-
, Package(..)
9-
, Type(..)
10-
, TypeName
11-
, UnsafeName(..)
12-
, VariantName
13-
, base64PackageName
14-
, basicTypeToString
15-
, commonModuleName
16-
, enum
17-
, moduleToNamespace
18-
, ref
19-
, reservedList
20-
, toTypeName
21-
, toValueName
22-
, unwrapUnsafe
2+
( BasicType(..), commonModuleName, base64PackageName
3+
, ConstValue(..), Field, Module(..), Object, OneOfData, Package(..), Type(..), TypeName, UnsafeName(..), VariantName, basicTypeToString, enum, moduleToNamespace, ref, reservedList, toTypeName, toValueName, unwrapUnsafe
234
)
245

6+
{-|
7+
8+
@docs BasicType, commonModuleName, base64PackageName
9+
10+
11+
# TODO: These should probably not be exposed.
12+
13+
@docs ConstValue, Field, Module, Object, OneOfData, Package, Type, TypeName, UnsafeName, VariantName, basicTypeToString, enum, moduleToNamespace, ref, reservedList, toTypeName, toValueName, unwrapUnsafe
14+
15+
-}
16+
2517
import Regex
2618
import Set exposing (Set)
2719
import String.Extra
2820

2921

22+
{-| An Elm module being generated
23+
24+
TODO: Don't expose this.
25+
26+
-}
3027
type Module
3128
= Json
3229
| Types
@@ -36,18 +33,28 @@ type Module
3633
| Servers
3734

3835

36+
{-| An Effects package we can target when code-generating API calls
37+
-}
3938
type Package
4039
= ElmHttp
4140
| DillonkearnsElmPages
4241
| LamderaProgramTest
4342

4443

4544
{-| An unsanitized name
45+
46+
TODO: Don't expose this.
47+
4648
-}
4749
type UnsafeName
4850
= UnsafeName String
4951

5052

53+
{-| Given a namespace and Module, generate the full module name
54+
55+
TODO: Don't expose this.
56+
57+
-}
5158
moduleToNamespace : List String -> Module -> List String
5259
moduleToNamespace namespace moduleName =
5360
case moduleName of
@@ -78,6 +85,8 @@ moduleToNamespace namespace moduleName =
7885
commonModuleName
7986

8087

88+
{-| Module where we generate common helper functions.
89+
-}
8190
commonModuleName : List String
8291
commonModuleName =
8392
[ "OpenApi", "Common" ]
@@ -87,6 +96,11 @@ commonModuleName =
8796
-- Names adaptation --
8897

8998

99+
{-| Convert an UnsafeName to a valid TypeName.
100+
101+
TODO: Don't expose this.
102+
103+
-}
90104
toTypeName : UnsafeName -> TypeName
91105
toTypeName (UnsafeName name) =
92106
name
@@ -134,6 +148,9 @@ replaceSpacesRegex =
134148

135149

136150
{-| Convert into a name suitable to be used in Elm as a variable.
151+
152+
TODO: Don't expose this.
153+
137154
-}
138155
toValueName : UnsafeName -> String
139156
toValueName (UnsafeName name) =
@@ -169,6 +186,11 @@ toValueName (UnsafeName name) =
169186
clean
170187

171188

189+
{-| Reserved words; these can't be used for Elm variable names.
190+
191+
TODO: Don't expose this.
192+
193+
-}
172194
reservedList : Set String
173195
reservedList =
174196
-- Copied from elm-syntax
@@ -314,6 +336,11 @@ initialUppercaseWordToLowercase input =
314336
input
315337

316338

339+
{-| Intermediate representation of an OpenAPI schema
340+
341+
TODO: Don't expose this.
342+
343+
-}
317344
type Type
318345
= Nullable Type
319346
| Object Object
@@ -335,20 +362,32 @@ type Type
335362
| Unit
336363

337364

365+
{-| A basic value
366+
-}
338367
type BasicType
339368
= Integer
340369
| Boolean
341370
| String
342371
| Number
343372

344373

374+
{-| A constant value
375+
376+
TODO: Don't expose this.
377+
378+
-}
345379
type ConstValue
346380
= ConstInteger Int
347381
| ConstBoolean Bool
348382
| ConstString String
349383
| ConstNumber Float
350384

351385

386+
{-| Convert BasicType to OpenAPI "type" string
387+
388+
TODO: Don't expose this. Move to CliMonad?
389+
390+
-}
352391
basicTypeToString : BasicType -> String
353392
basicTypeToString basicType =
354393
case basicType of
@@ -365,10 +404,20 @@ basicTypeToString basicType =
365404
"number"
366405

367406

407+
{-| An Object in a schema
408+
409+
TODO: Don't expose this.
410+
411+
-}
368412
type alias Object =
369413
List ( UnsafeName, Field )
370414

371415

416+
{-| A `oneOf` declaration
417+
418+
TODO: Don't expose this.
419+
420+
-}
372421
type alias OneOfData =
373422
List
374423
{ name : UnsafeName
@@ -377,31 +426,59 @@ type alias OneOfData =
377426
}
378427

379428

429+
{-| Name of a Type
430+
431+
TODO: Don't expose this.
432+
433+
-}
380434
type alias TypeName =
381435
String
382436

383437

438+
{-| Variant of a custom type
439+
440+
TODO: Don't expose this.
441+
442+
-}
384443
type alias VariantName =
385444
TypeName
386445

387446

447+
{-| An Object field
448+
TODO: Don't expose this.
449+
-}
388450
type alias Field =
389451
{ type_ : Type
390452
, required : Bool
391453
, documentation : Maybe String
392454
}
393455

394456

457+
{-| Create a "Ref", as in `$ref: "#/components/..."`.
458+
459+
TODO: Don't expose this.
460+
461+
-}
395462
ref : String -> Type
396463
ref str =
397464
Ref (String.split "/" str)
398465

399466

467+
{-| Get the value inside of an UnsafeName.
468+
469+
TODO: Don't expose this.
470+
471+
-}
400472
unwrapUnsafe : UnsafeName -> String
401473
unwrapUnsafe (UnsafeName name) =
402474
name
403475

404476

477+
{-| Generate an "enum" from a list of variants.
478+
479+
TODO: Don't expose this.
480+
481+
-}
405482
enum : List String -> Type
406483
enum variants =
407484
variants
@@ -410,6 +487,8 @@ enum variants =
410487
|> Enum
411488

412489

490+
{-| Name of the package needed for Base64.
491+
-}
413492
base64PackageName : String
414493
base64PackageName =
415494
"danfishgold/base64-bytes"

0 commit comments

Comments
 (0)