Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add configuration TaskBuilderNamespace option. #45

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/GiraffeGenerator.Core/CodeGen.fs
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ let giraffeAst (api: Api) =
(xml api.Docs)
moduleName
[ openDecl "System.ComponentModel.DataAnnotations"
openDecl "FSharp.Control.Tasks.V2.ContextInsensitive"
openDecl Configuration.value.TaskBuilderNamespace
openDecl "Giraffe"
openDecl "System.Threading.Tasks"
openDecl "Microsoft.AspNetCore.Http"
Expand Down
4 changes: 3 additions & 1 deletion src/GiraffeGenerator.Core/Configuration.fs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ type Configuration =
AllowUnqualifiedAccess: bool
MapDateTimeInto: DateTimeGeneratedType
ModuleName: string option
TaskBuilderNamespace: string
}

let mutable value =
{ UseNodaTime = false
AllowUnqualifiedAccess = false
MapDateTimeInto = OffsetDateTime
ModuleName = None }
ModuleName = None
TaskBuilderNamespace = "FSharp.Control.Tasks.V2.ContextInsensitive" }
3 changes: 3 additions & 0 deletions src/GiraffeGenerator/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type Config =
| Allow_Unqualified_Access
| Use_Noda_Time
| Map_Date_Time_Into of DateTimeGeneratedType
| Task_Builder_Namespace of string

interface IArgParserTemplate with
member this.Usage =
Expand All @@ -34,6 +35,7 @@ type Config =
| Allow_Unqualified_Access -> "Opts-out [<RequireQualifiedAccess>] generation for the module being generated"
| Use_Noda_Time -> "Opts-in usage of NodaTime types"
| Map_Date_Time_Into _ -> "Specifies NodaTime type used for date-time OpenAPI format"
| Task_Builder_Namespace _ -> "Control the task { } computation expression open statement.\nDefaults to FSharp.Control.Tasks.V2.ContextInsensitive"

let parser = ArgumentParser.Create<Config>("GiraffeGenerator")

Expand All @@ -52,6 +54,7 @@ let main argv =
| Allow_Unqualified_Access -> Configuration.value <- { Configuration.value with AllowUnqualifiedAccess = true }
| Use_Noda_Time -> Configuration.value <- { Configuration.value with UseNodaTime = true }
| Map_Date_Time_Into kind -> Configuration.value <- { Configuration.value with MapDateTimeInto = kind.ToConfigType() }
| Task_Builder_Namespace tbn -> Configuration.value <- { Configuration.value with TaskBuilderNamespace = tbn }

let doc, errors = read inputFile
if errors <> null && errors.Errors <> null && errors.Errors.Count > 0 then
Expand Down