Handling different response content types for same status code (continued)
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 3.8k
- Forks
- 333
- Avg merge
- 16h 29m
- Merged PRs (30d)
- 116
Description
### 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
```
```cs
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
```cs
await client.Tests.GetJsonAsync();
await client.Tests.GetOctetAsync();
```
### How to reproduce
1. `dotnet kiota generate -l CSharp -d --exclude-backward-compatible --clean-output`
2. observe you don't have access to the `application/octet-stream` response
### Open API description file
```yml
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
```
```
### Other information
_No response_
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the issue with the provided OpenAPI description and the `dotnet kiota generate -l CSharp` command, then inspect the generated `client.Tests.GetAsync` path and response handling. Compare the JSON and `application/octet-stream` responses; done means the generated C# client provides a supported way to access the stream for the same status code.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, openapi
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100