Automatically deriving Jason.Encoder #11
Replies: 3 comments 4 replies
-
Here's a possible solution: What if we add a setting like |
Beta Was this translation helpful? Give feedback.
2 replies
-
Amazing! Thank you for the quick follow up. Will give it a shot on tgi.ex
this week and report back.
…On Sun, May 28, 2023 at 12:49 AJ Foster ***@***.***> wrote:
Commit c33d617
<c33d617>
added a new configuration option, schema_use, as described above. I
thought about your feedback around using the module name, and luckily this
is possible using the __MODULE__ value from the macro environment. In the
docs I left it open that there *may* be options passed in the future, but
none right now. If we think of anything, we can always add it.
With it, you can do something like this:
# with schema_use: MyModule
defmodule MyModule do
defmacro __using__(_opts) do
quote do
@derive {Jason.Encoder, except: [:__info__]}
end
endend
(In this example, __info__ is part of the extra_fields configuration that
shouldn't be encoded.
—
Reply to this email directly, view it on GitHub
<#11 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAHRW5KR6FGSMPPAIRUHLI3XIOT3TANCNFSM6AAAAAAYIOICBQ>
.
You are receiving this because you authored the thread.Message ID:
***@***.***
com>
|
Beta Was this translation helpful? Give feedback.
0 replies
-
This resolves moving the Encoder derivation into the library, thank you @aj-foster.
|
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
When an HTTP client (Tesla+Finch in our case) uses Jason to SerDe HTTP bodies, lack of a
Jason.Encoder
protocol implementation results in the following error:For Tesla, one solution is to just use maps rather than the generated structs but this sacrifices type checking.
Our current workaround is to derive these encoders in clients importing the autogenerated libraries i.e.
Instead, it would be better if the autogenerated libraries worked out of the box without additional end-user effort.
Question: Is there an easy way to modify code generation to insert a [derive](require Protocol
Protocol.derive(Jason.Encoder, TextGenerationInference.GenerateResponse)) (I think
@derive {Jason.Encoder}
would suffice for our use case, as everything published in OpenAPI specifications is public right?) before alldefstruct
s emitted by open-api-generator?I realize that the client is left abstract and not everyone is using
Jason
for their JSON needs. So maybe this should be opt in.Beta Was this translation helpful? Give feedback.
All reactions