question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support for ValueTuple type in response body type

See original GitHub issue

Describe

Tuple and ValueTuple seem to have the same response. However, when ValueTuple type is used for Description, “Example” (or Schema) is not described normally.

For example, I wrote the code like this, (check body Type). Then I check the response && swagger.

code
[Function(nameof(PetStoreHttpTrigger.SystemTupleHandler))]
[OpenApiOperation(operationId: "SystemTupleHandler", tags: new[] { "tuple" })]
[OpenApiResponseWithBody(statusCode: HttpStatusCode.OK, contentType: "application/json", bodyType: typeof(Tuple<int,double,string>))]
public async Task<Tuple<int,double,string>> SystemTupleHandler(
   [HttpTrigger(AuthorizationLevel.Function, "GET", Route = "system-tuple")] HttpRequestData req,
   FunctionContext executionContext)
{
    var tuple = Tuple.Create(1,1.5,"3");
    return await Task.FromResult(tuple).ConfigureAwait(false);
}

[Function(nameof(PetStoreHttpTrigger.SystemValueTupleHandler))]
[OpenApiOperation(operationId: "SystemValueTupleHandler", tags: new[] { "tuple" })]
[OpenApiResponseWithBody(statusCode: HttpStatusCode.OK, contentType: "application/json", bodyType: typeof(ValueTuple<int, double, string>))]
public async Task<ValueTuple<int, double, string>> SystemValueTupleHandler(
   [HttpTrigger(AuthorizationLevel.Function, "GET", Route = "system-valuetuple")] HttpRequestData req,
   FunctionContext executionContext)
{
    var tuple = ValueTuple.Create(1, 1.5, "3");
    return await Task.FromResult(tuple).ConfigureAwait(false);
}

[Function(nameof(PetStoreHttpTrigger.SystemValueTupleSyntaxHandler))]
[OpenApiOperation(operationId: "SystemValueTupleSyntaxHandler", tags: new[] { "tuple" })]
[OpenApiResponseWithBody(statusCode: HttpStatusCode.OK, contentType: "application/json", bodyType: typeof((int,double,string)))]
public async Task<(int,double,string)> SystemValueTupleSyntaxHandler(
  [HttpTrigger(AuthorizationLevel.Function, "GET", Route = "system-valuetuplesyntax")] HttpRequestData req,
  FunctionContext executionContext)
{
    var tuple = (1, 1.5, "3");
    return await Task.FromResult(tuple).ConfigureAwait(false);
}

Response / swagger

image

Env Information

  • Windows 10 Education (21H1)
  • Azure Function Local Test

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
Lee-WonJuncommented, Sep 5, 2021

I found the reason. in the document “Members like Item1 and Item2 are fields, not properties.” content can be found

So it is not automatically serialized. I’ll be able to make new visitor for ValueTuple.

1reaction
justinyoocommented, Aug 27, 2021

@Lee-WonJun I’ll assign this to you to take a look.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Is params Keyword supports with ValueTuple as a ...
A value tuple is a struct with variable length generic parameters and has been given a special syntax for initialization and usage (most...
Read more >
ValueTuple Struct (System)
The ValueTuple structure represents a tuple that has no elements. It is useful primarily for its static methods that let you create and...
Read more >
Use ValueTuple element names in minimal route handlers
The problem is that the schema for the lives with the methods and not with the type. This means that we need to...
Read more >
Request and response objects
Django uses request and response objects to pass state through the system. When a page is requested, ... CONTENT_TYPE – The MIME type...
Read more >
C# 7 ValueTuple types and their limitations - Joseph Woodward
C# 7's Tuple type is now a value type, meaning there's no heap allocation and one less de-allocation to worry about when compacting...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found