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

Support 'int' as a type for 'id' #30

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

dharmatech
Copy link

This pull request is to add support for having id be of type int. See the following issue: #29 (int not supported as type for id).

@dharmatech
Copy link
Author

dharmatech commented Feb 9, 2021

In summary, the function generateModel is changed from:

let generateModel name names (fields : Parameter []) =
    let id = fields.[0].name
    let fields = fields |> Array.map (fun f -> sprintf "%s: %s" f.name f.FSharpType) |> String.concat "\n  "

    sprintf """namespace %s
[<CLIMutable>]
type %s = {
  %s
}
module Validation =
  let validate v =
    let validators = [
      fun u -> if isNull u.%s then Some ("%s", "%s shouldn't be empty") else None
    ]
    validators
    |> List.fold (fun acc e ->
      match e v with
      | Some (k,v) -> Map.add k v acc
      | None -> acc
    ) Map.empty
"""     names name fields id id (upper id)

to:

let generateModel name names (fields : Parameter []) =
    let id = fields.[0].name

    let id_type = fields.[0].typ

    let fields = fields |> Array.map (fun f -> sprintf "%s: %s" f.name f.FSharpType) |> String.concat "\n    "

    let template_int = sprintf """namespace %s
    
[<CLIMutable>]
type %s = {
    %s
}
    
module Validation =
    let validate v =
        let validators = []
    
        validators
        |> List.fold (fun acc e ->
            match e v with
            | Some (k,v) -> Map.add k v acc
            | None -> acc
        ) Map.empty
"""

    let template_string = sprintf """namespace %s
[<CLIMutable>]
type %s = {
    %s
}
module Validation =
    let validate v =
        let validators = [
            fun u -> if isNull u.%s then Some ("%s", "%s shouldn't be empty") else None
            ]
        validators
        |> List.fold (fun acc e ->
            match e v with
            | Some (k,v) -> Map.add k v acc
            | None -> acc
        ) Map.empty
"""

    if id_type = Int then
        template_int names name fields
    else
        template_string names name fields id id (upper id)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant