-
Notifications
You must be signed in to change notification settings - Fork 348
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
feat: Middleware.PathParams: add OpenAPI params #628
feat: Middleware.PathParams: add OpenAPI params #628
Conversation
35e8dc3
to
7f8c19b
Compare
Related to #566 as well
I couldn't find docs about that in the Open API spec. Do you mind linking where is this possible? I didn't know that.
I would like
It is OK we have a working version without "nesting", and yes, we should move away from regex if possible, I like your proposal for the macro 🤯 |
I don't believe it is legal, but the implementation in this PR is naïve and will handle it oddly.
That is ugly. 'The value for these path parameters MUST NOT contain any unescaped "generic syntax" characters described by RFC3986: forward slashes (/), question marks (?), or hashes (#).' In other words, I think that
The macro approach has definite downsides, especially as the macro-style of Tesla client declaration is disfavoured (I am slowly trying to convert everything to runtime configured) and it would require Tesla's URL handling to be aware of such an iodata-ish approach. |
Keep going, get to a place where you are happy with things, open for code review, and we open up the discussion to figure out what should be the end-state. Thank you so much for the contribution thus far! |
I’ll do a quick once over this weekend; we are currently using a variant of this in production and it works very nicely, as long as you don't do silly things. |
7f8c19b
to
f103c35
Compare
Sorry for the delays, but this is now ready. There were a couple of issues we found in practice that I put back in place. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks great so far, I left couple questions about it.
I have a better fix in a second commit and will squash before merging. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not hate it thou!
Maybe avoiding the regex and add compile-time URL contractors that could speed up the situation?
But overall, it seems good to me!
Anything last words? ? |
We shouldn't see anything much worse in performance because the current solution uses a similar |
Tesla.Middleware.PathParams has been extended to support OpenAPI style parameters in addition to the existing Phoenix style parameters. - Phoenix parameters begin with `:` and a letter (`a-zA-Z`) and continue to the next non-word character (not `a-zA-Z0-9_`). Examples include `:id`, `:post_id`, `:idPost`. - OpenAPI parameters are contained in braces (`{}`), must begin with a letter (`a-zA-Z`) and may contain word characters and hyphens (`-a-zA-Z0-9_`). Examples inlucde `{id}`, `{post_id}`, `{IdPost}`. Parameter value objects may be provided as maps with atom or string keys, keyword lists, or structs. During path resolution, to avoid potential atom exhaustion, the parameter value object is transformed to a string-keyed map. Parameter values that are `nil` or that are not present in the value object are not replaced; all other values are converted to string (with `to_string`) and encoded with `application/x-www-form-urlencoded` formatting. If the value does not implement the `String.Chars` protocol, it is the caller's responsibility to convert it to a string prior to passing it to the Tesla client using this middleware. Execution time is determined by the number of parameter patterns in the path. Closes: #566
08ba25a
to
ddb9ec3
Compare
Squashed and main PR message ready to go. I think that having a mechanism to tokenize URLs / URL paths and pass that to Tesla is a slightly larger discussion because it is more invasive and may have negative impacts on other plug-ins if not supported. Probably better for a 2.0 discussion, but it would make specific path matching easier and more reliable, IMO. Although the code here is different than what we're using in production, it’s somewhat closer to the original implementation and has nothing but upsides, IMO. |
🚀 💜 |
Tesla.Middleware.PathParams has been extended to support OpenAPI style parameters in addition to the existing Phoenix style parameters.
Phoenix parameters begin with
:
and a letter (a-zA-Z
) and continue to the next non-word character (nota-zA-Z0-9_
). Examples include:id
,:post_id
,:idPost
.OpenAPI parameters are contained in braces (
{}
), must begin with a letter (a-zA-Z
) and may contain word characters and hyphens (-a-zA-Z0-9_
). Examples inlucde{id}
,{post_id}
,{IdPost}
.Parameter value objects may be provided as maps with atom or string keys, keyword lists, or structs. During path resolution, to avoid potential atom exhaustion, the parameter value object is transformed to a string-keyed map.
Parameter values that are
nil
or that are not present in the value object are not replaced; all other values are converted to string (withto_string
) and encoded withapplication/x-www-form-urlencoded
formatting. If the value does not implement theString.Chars
protocol, it is the caller's responsibility to convert it to a string prior to passing it to the Tesla client using this middleware.Execution time is determined by the number of parameter patterns in the path.
Closes: #566