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

AnyType + BodySerializationMethod #423

Open
MeikelLP opened this issue Jul 22, 2024 · 4 comments
Open

AnyType + BodySerializationMethod #423

MeikelLP opened this issue Jul 22, 2024 · 4 comments
Assignees
Labels
enhancement New feature, bug fix, or request

Comments

@MeikelLP
Copy link

Is your feature request related to a problem? Please describe.
I want to send and receive AnyType as System.Text.Json.JsonElement for max convinience

Describe the solution you'd like
Add a property alongside anyType like anyTypeBodySerializationMethod and let us adjust how the body is send.

Describe alternatives you've considered
Writing the interface myself :(

Additional context
System.Text.Json.JsonElement is send as a stream. This might work in some cases but most of the time we just wanna send it as string which is only possible with BodySerializationMethod.Json from what I can tell

Maybe my assumption is wrong - I'm new to Refit

@MeikelLP MeikelLP added the enhancement New feature, bug fix, or request label Jul 22, 2024
@christianhelle
Copy link
Owner

@MeikelLP thanks for taking the time to suggest this

If you know what the Refit interface should look like in such a scenario, then it would be easier for me to add support. If what you need, has to be done on the contracts/models/dto then Refitter is limited by what NSwag can do for generating contracts/models/dto

@MeikelLP
Copy link
Author

@MeikelLP thanks for taking the time to suggest this

If you know what the Refit interface should look like in such a scenario, then it would be easier for me to add support. If what you need, has to be done on the contracts/models/dto then Refitter is limited by what NSwag can do for generating contracts/models/dto

Thanks for the quick response!

Currently the interface method is generated as

Task<IApiResponse<System.Text.Json.JsonElement>> CreateMessageAsync([Body] System.Text.Json.JsonElement body, CancellationToken cancellationToken = default);

however I'd like it to be like this:

Task<IApiResponse<System.Text.Json.JsonElement>> CreateMessageAsync([Body(BodySerializationMethod.Serialized)] System.Text.Json.JsonElement body, CancellationToken cancellationToken = default);

This will cause the body to be serialized as json and send as StringContent rather than a StreamContent if I assume correctly.

@christianhelle
Copy link
Owner

@MeikelLP I have never used BodySerializationMethod.Json so I'm not sure what it does. But I can try it out and set some sort of HttpClient delegating handler to look at what payload type is on the HttpRequestMessage

Would you mind providing an example OpenAPI spec I can use to try things out?

@MeikelLP
Copy link
Author

I'm currently working with a closed source proprietary API thus I cannot share the original schema.
However I tried to mask everything unnecessary:

{
  "openapi": "3.0.0",
  "info": {
    "title": "Example",
    "version": "1.0.0"
  },
  "paths": {
    "/some/endpoint": {
      "post": {
        "summary": "Example",
        "operationId": "someThing",
        "requestBody": {
          "required": true,
          "content": {
            "application/ld+json": {
              "schema": {
                "type": "object",
                "additionalProperties": true
              }
            }
          }
        }
      }
    }
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature, bug fix, or request
Projects
None yet
Development

No branches or pull requests

2 participants