Swashbuckle.AspNetCore icon indicating copy to clipboard operation
Swashbuckle.AspNetCore copied to clipboard

Support C#7 value tuples

Open Soarc opened this issue 7 years ago • 5 comments

Add support for c# 7 value tuple. Example. Consider following action

        public (IEnumerable<string> Collection, string Token) TestAction()
        {
            return (new string[] { "value1", "value2" }, "TokenValue");
        }

expected definition:

 "definitions": {
    "ValueTuple[IEnumerable[String],String]": {
      "type": "object",
      "properties": {
        "Collection": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "Token": {
          "type": "string"
        }
      }
    }
  },

actual definition

 "definitions": {
    "ValueTuple[IEnumerable[String],String]": {
      "type": "object",
      "properties": {
        "item1": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "item2": {
          "type": "string"
        }
      }
    }
  },

Soarc avatar Oct 01 '17 16:10 Soarc

I'm note sure if this is swashbuckle's or aspnetcore ApiExplorer issue. @domaindrivendev can you give me some hints on implementing this?

Soarc avatar Oct 01 '17 16:10 Soarc

I don't think swagger has any way of describing tuples hence I hardly how swashbuckle could provide a standard implementation of that.

sandorfr avatar Nov 14 '17 03:11 sandorfr

ValueTuples can be treated as simple objects with well known property names matching values defined in generated TupleElementNamesAttribute. The only problem i can see is generating definition name.

Soarc avatar Nov 16 '17 19:11 Soarc

+1

GeorgeTsaplin avatar Feb 10 '20 08:02 GeorgeTsaplin

any news here? im kinda having a problem here also... It is worth noting that if you use List<KeyValuePair<string,string>> the output is field:[{key:string,value:string}], so why not have List<(string Name, string Email)> rendered as field:[{Name:string,Email:string}]

Leonardo-Ferreira avatar Oct 16 '22 01:10 Leonardo-Ferreira