Closed
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator (example)?
- Have you tested with the latest master to confirm the issue still exists?
- Have you searched for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
Currently any binaries in generate client for rust (with reqwest library at least) uses std::path::PathBuf
.
And several issues here:
- it's supposed to use FS, but it's not necessary
- it doesn't support streaming
- and more important: it just doesn't work
E.g for request it generates the following code:
local_var_req_builder.json(&body); // assumes it's json content
And for response it's even worse:
let local_var_content = local_var_resp.text().await?; // reads all content to `String`
// ... omitted
serde_json::from_str(&local_var_content).map_err(Error::from) // it tries to de-serialize `PathBuf` from `String`
// moreover, headers not accessible, but it can be useful to check them before starting to consume the body
openapi-generator version
7.4.0
/7.3.0
and likely earlier versions
OpenAPI declaration file content or url
openapi: 3.0.1
info:
title: My title
description: My description
version: 1.0.0
paths:
/upload:
post:
requestBody:
required: true
content:
application/octet-stream:
schema:
type: string
format: binary
responses:
'200':
description: 'OK'
/download:
get:
responses:
'200':
description: 'OK'
content:
application/octet-stream:
schema:
type: string
format: binary
headers:
Content-Length:
schema:
type: integer
Content-Range:
required: true
schema:
type: string
Generation Details
No special configs, just generate -i ./test.yaml -g rust --package-name stream-test -o ./out --library reqwest
Steps to reproduce
- Take provided openapi schema
- generate a client for rust using
reqwest
library
Related issues/PRs
Suggest a fix
First thought could be to use reqwest::Body - but it doesn't cover streaming of response (at least for reqwest 0.11.x
). Only Response
itself can be converted with bytes_stream. As well as into bytes.
But it's possible to wrap a Stream
to reqwest::Body
.
So I think it would be correct to go with this way:
- expect
reqwest::Body
(orInto<Body>
) if it's expected as a body of the request - return
reqwest::Response
if output type is binary (could be wrapper though, which containsStream
+headers
for example)