sdkgen icon indicating copy to clipboard operation
sdkgen copied to clipboard

Feature Request: Allow binding annotations variables to argument property

Open renato-macedo opened this issue 5 years ago • 1 comments

Currently, it is necessary to have an argument for each variable in the header, path or query in rest annotations. So, if we use 3 variables, we must have 3 arguments in the function and so on. I think that allowing values to be received by the properties of a struct argument will make the functions more concise.

Something like:

type CustomHeaders {
    userAgent: string
    lang: string
    token: string
}

type PostInfo {
    author: string
    slug: string
}

@rest GET /{post.author}/posts/{post.slug} [header user-agent: {headers.userAgent}] [header accept-language: {headers.lang}] [header x-token: {headers.token}]
fn getPost(post: PostInfo, headers: CustomHeaders): Post

What do you think? It would take some time, but I believe I can implement this.

renato-macedo avatar Nov 05 '20 15:11 renato-macedo

I like it!

Trick parts:

  1. Ensure all non-nullable properties shows up somewhere.
  2. Ensure no argument is repeated ({post} somewhere and {post.author} somewhere else)
  3. Property of a property? {post.author.id}? It gets complicated quickly. I don't think there is need for that.

lbguilherme avatar Nov 17 '20 11:11 lbguilherme