Skip to content

Handling different response content types for same status code (continued) #7147

@esd-thg

Description

@esd-thg

What are you generating using Kiota, clients or plugins?

API Client/SDK

In what context or format are you using Kiota?

Nuget tool

Client library/SDK language

Csharp

Describe the bug

This is related to #4309

When an endpoint define multiple response types for the same status code, then we can't access the non-json content

Example:

GET /tests - Accept: application/json --> returns json
GET /tests - Accept: application/octet-stream --> returns a pdf
await client.Tests.GetAsync() --> return type is the expected json object
await client.Tests.GetAsync(x => 
  x.Headers.Add(HeaderNames.Accept, MediaTypeNames.Application.Json)) --> return type is the expected json object

await client.Tests.GetAsync(x => 
  x.Headers.Add(HeaderNames.Accept, MediaTypeNames.Application.Octet)) --> return type is still the json object, but a Stream was expected. Pretty sure this will fail runtime

I'm expecting a Stream due to https://learn.microsoft.com/en-us/openapi/kiota/serialization?tabs=csharp#types-mapping

Expected behavior

I was expecting await client.Tests.GetAsync(x => x.Headers.Add(HeaderNames.Accept, MediaTypeNames.Application.Octet)) to return a Stream
Though I can see how that would be hard to implement. So some way to access the Stream will suffice.

Could just be

await client.Tests.GetJsonAsync();
await client.Tests.GetOctetAsync();

How to reproduce

  1. dotnet kiota generate -l CSharp -d <provided openapi> --exclude-backward-compatible --clean-output
  2. observe you don't have access to the application/octet-stream response

Open API description file

openapi: 3.0.1
info:
  title: Test
  version: 1.0.0
paths:
  /tests:
    get:
      responses:
        200: 
          description: Success
          content: 
            application/json:
              schema:
                type: object
                properties:
                  name:
                    type: string
            application/octet-stream:
              schema:
                type: string
                format: binary

Kiota Version

1.29.0

Latest Kiota version known to work for scenario above?(Not required)

No response

Known Workarounds

No response

Configuration

No response

Debug output

Click to expand log ```
</details>


### Other information

_No response_

Metadata

Metadata

Assignees

No one assigned

    Labels

    CsharpPull requests that update .net codestatus:waiting-for-triageAn issue that is yet to be reviewed or assignedtype:bugA broken experience

    Type

    No type

    Projects

    Status

    Needs Triage 🔍

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions