-
Notifications
You must be signed in to change notification settings - Fork 215
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
Generating a client for an endpoint that downloads binary data #3855
Comments
Hi @kyleratti , |
Hey @baywet, Thanks for your speedy response! Unfortunately, a public async Task<string?> GetAsync(Action<BytesRequestBuilderGetRequestConfiguration>? requestConfiguration = default, CancellationToken cancellationToken = default) {
"openapi": "3.0.1",
"info": {
"title": "WebApi",
"version": "v1"
},
"paths": {
"/image/{imageId}/bytes": {
"get": {
"tags": [
"Image"
],
"parameters": [
{
"name": "imageId",
"in": "path",
"required": true,
"style": "simple",
"schema": {
"type": "string"
}
},
{
"name": "maxWidth",
"in": "query",
"style": "form",
"schema": {
"type": "integer",
"format": "int32"
}
},
{
"name": "maxHeight",
"in": "query",
"style": "form",
"schema": {
"type": "integer",
"format": "int32"
}
},
{
"name": "cropImage",
"in": "query",
"style": "form",
"schema": {
"type": "boolean"
}
}
],
"responses": {
"200": {
"description": "OK",
"content": {
"application/octet-stream": {
"schema": {
"type": "string",
"format": "binary"
}
}
}
},
"400": {
"description": "Bad Request",
"content": {
"text/plain": {
"schema": {
"$ref": "#/components/schemas/ImageNotFoundResult"
}
},
"application/json": {
"schema": {
"$ref": "#/components/schemas/ImageNotFoundResult"
}
},
"text/json": {
"schema": {
"$ref": "#/components/schemas/ImageNotFoundResult"
}
}
}
}
}
}
}
},
"components": {
"schemas": {
"ImageNotFoundResult": {
"type": "object",
"properties": {
"imageId": {
"type": "string",
"nullable": true
},
"message": {
"type": "string",
"nullable": true
}
},
"additionalProperties": false
}
},
"securitySchemes": {}
},
"security": []
} |
Thanks for the additional information. |
That's an interesting question! Unfortunately it looks like it still ends up with a {
"openapi": "3.0.1",
"info": {
"title": "WebApi",
"version": "v1"
},
"paths": {
"/image/{imageId}/bytes": {
"get": {
"tags": [
"Image"
],
"parameters": [
{
"name": "imageId",
"in": "path",
"required": true,
"style": "simple",
"schema": {
"type": "string"
}
},
{
"name": "maxWidth",
"in": "query",
"style": "form",
"schema": {
"type": "integer",
"format": "int32"
}
},
{
"name": "maxHeight",
"in": "query",
"style": "form",
"schema": {
"type": "integer",
"format": "int32"
}
},
{
"name": "cropImage",
"in": "query",
"style": "form",
"schema": {
"type": "boolean"
}
}
],
"responses": {
"200": {
"description": "OK",
"content": {
"application/octet-stream": { }
}
},
"400": {
"description": "Bad Request",
"content": {
"text/plain": {
"schema": {
"$ref": "#/components/schemas/ImageNotFoundResult"
}
},
"application/json": {
"schema": {
"$ref": "#/components/schemas/ImageNotFoundResult"
}
},
"text/json": {
"schema": {
"$ref": "#/components/schemas/ImageNotFoundResult"
}
}
}
}
}
}
}
},
"components": {
"schemas": {
"ImageNotFoundResult": {
"type": "object",
"properties": {
"imageId": {
"type": "string",
"nullable": true
},
"message": {
"type": "string",
"nullable": true
}
},
"additionalProperties": false
}
},
"securitySchemes": {}
},
"security": []
} |
This is strange since this is essentially what this unit test is testing for. Can you confirm which version of kiota you are using? Can you try to tweak the unit test into making it fail? |
Strange indeed! Here's my version output:
I'll try tweaking the unit test to see if I can get it to fail. I'll let you know what I find out! |
Something hinky is definitely going on here. I'm still digging, but it looks like the C# code method writer will handle This makes me think the issue is higher up the stack (which I think you are suspecting as well.) I'm still digging but figured I'd drop this incase it gave you any more ideas. |
I figured it out! This happens because my API spec has a I'm not sure if this is intentional or not? I have to imagine this is a difficulty with having different response types and models. Apologies if this is documented somewhere and I've just totally missed it. I appreciate your time! |
@kyleratti thanks for investigating this further. No it's not intentional, the return value is not supposed to be impacted by the error responses. Is this something that'd you like to submit a pull request for now that you have the unit test, I could give you pointers in the code to where this is being done. @sebastienlevert I believe this is orthogonal. |
@baywet sure, I can give it a go! Pointers would definitely be appreciated though 😀 |
Awesome! kiota/src/Kiota.Builder/KiotaBuilder.cs Line 1277 in 3c539c8
|
@kyleratti is this something you are still interested in contributing? Let us know and we'll support / adjust accordingly! Thanks! |
Hey @sebastienlevert! I am so sorry for the delay. The holidays really got away from me. I am still interested in taking a stab at this issue. I can prioritize putting some time to it over the next few weeks if that's still OK? |
Absolutely! Thanks for your participation in this! |
I have an OpenApi endpoint that serves binary data (e.g.,
image/jpeg
,image/png
,image/gif
, etc.) I am using Kiota to generate a C# API client. However, it seems that the generated client does not support endpoints that serve binary (OpenApi schema typefile
, formatbinary
.)As far as I can tell, this is the correct way to describe the endpoint. Is it possible to have Kiota generate a client function that can call this endpoint and return either a
Stream
(preferred) or abyte[]
? I see vague mentions of defaulting toStream
for unknown mimetypes on #1471, however that is not the behavior I am seeing now.I do see a warning about this when generating my client which makes me think my API description may be wrong?
Here's the signature of the generated function:
And here's my OpenApi Schema:
This snag aside, I do want to say this is a fantastic tool and I'm very appreciative of all of the contributors!
The text was updated successfully, but these errors were encountered: