11module 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+
2517import Regex
2618import Set exposing (Set )
2719import String.Extra
2820
2921
22+ {- | An Elm module being generated
23+
24+ TODO: Don't expose this.
25+
26+ -}
3027type 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+ -}
3938type Package
4039 = ElmHttp
4140 | DillonkearnsElmPages
4241 | LamderaProgramTest
4342
4443
4544{- | An unsanitized name
45+
46+ TODO: Don't expose this.
47+
4648-}
4749type 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+ -}
5158moduleToNamespace : List String -> Module -> List String
5259moduleToNamespace 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+ -}
8190commonModuleName : List String
8291commonModuleName =
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+ -}
90104toTypeName : UnsafeName -> TypeName
91105toTypeName ( 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-}
138155toValueName : UnsafeName -> String
139156toValueName ( 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+ -}
172194reservedList : Set String
173195reservedList =
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+ -}
317344type Type
318345 = Nullable Type
319346 | Object Object
@@ -335,20 +362,32 @@ type Type
335362 | Unit
336363
337364
365+ {- | A basic value
366+ -}
338367type BasicType
339368 = Integer
340369 | Boolean
341370 | String
342371 | Number
343372
344373
374+ {- | A constant value
375+
376+ TODO: Don't expose this.
377+
378+ -}
345379type 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+ -}
352391basicTypeToString : BasicType -> String
353392basicTypeToString 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+ -}
368412type alias Object =
369413 List ( UnsafeName , Field )
370414
371415
416+ {- | A `oneOf` declaration
417+
418+ TODO: Don't expose this.
419+
420+ -}
372421type 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+ -}
380434type alias TypeName =
381435 String
382436
383437
438+ {- | Variant of a custom type
439+
440+ TODO: Don't expose this.
441+
442+ -}
384443type alias VariantName =
385444 TypeName
386445
387446
447+ {- | An Object field
448+ TODO: Don't expose this.
449+ -}
388450type 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+ -}
395462ref : String -> Type
396463ref 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+ -}
400472unwrapUnsafe : UnsafeName -> String
401473unwrapUnsafe ( UnsafeName name) =
402474 name
403475
404476
477+ {- | Generate an "enum" from a list of variants.
478+
479+ TODO: Don't expose this.
480+
481+ -}
405482enum : List String -> Type
406483enum variants =
407484 variants
@@ -410,6 +487,8 @@ enum variants =
410487 |> Enum
411488
412489
490+ {- | Name of the package needed for Base64.
491+ -}
413492base64PackageName : String
414493base64PackageName =
415494 " danfishgold/base64-bytes"
0 commit comments