You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
use poem_openapi::{ApiResponse,Object, payload::Json};#[derive(Object)]pubstructSuccessResponses<T>{status:i32,data:T,}#[derive(Object)]pubstructErrorMessage{code:i32,reason:String,}#[derive(ApiResponse)]pubenumCustomApiResponse<T>{#[oai(status = 200)]Ok(Json<SuccessResponses<T>>),/// Returns when the BadRequest.#[oai(status = 400)]BadRequest,}
this is error message:
error[E0412]: cannot find type`T`in this scope
--> src\main.rs:6:11
|
6 | data: T,
| ^ not found in this scope
error[E0412]: cannot find type`T`in this scope
--> src\main.rs:19:30
|
19 | Ok(Json<SuccessResponses<T>>),
| ^ not found in this scope
error[E0107]: missing generics for struct `SuccessResponses`
--> src\main.rs:4:12
|
4 | pub struct SuccessResponses<T> {
| ^^^^^^^^^^^^^^^^ expected 1 generic argument
|
note: struct defined here, with 1 generic parameter: `T`
--> src\main.rs:4:12
|
4 | pub struct SuccessResponses<T> {
| ^^^^^^^^^^^^^^^^ -
help: add missing generic argument
|
4 | pub struct SuccessResponses<T><T> {
|~~~~~~~~~~~~~~~~~~~
error[E0107]: missing generics for enum `CustomApiResponse`
--> src\main.rs:17:10
|
17 | pub enum CustomApiResponse<T> {
| ^^^^^^^^^^^^^^^^^ expected 1 generic argument
|
note: enum defined here, with 1 generic parameter: `T`
--> src\main.rs:17:10
|
17 | pub enum CustomApiResponse<T> {
| ^^^^^^^^^^^^^^^^^ -
help: add missing generic argument
|
17 | pub enum CustomApiResponse<T><T> {
|~~~~~~~~~~~~~~~~~~~~
Specifications
Version: latest
Platform: Windows
The text was updated successfully, but these errors were encountered:
#[derive(ApiResponse)]pubenumCustomApiResponse<T>{#[oai(status = 200)]Ok(Json<SuccessResponses<T>>),/// Returns when the BadRequest.#[oai(status = 400)]BadRequest,}
Because Object macro only implements the poem::types::Type trait for SuccessResponses<i32>.
So, you can do it like the following.
#[derive(ApiResponse)]pubenumCustomApiResponse{#[oai(status = 200)]Ok(Json<SuccessResponses<i32>>),/// Returns when the BadRequest.#[oai(status = 400)]BadRequest,}
Inline SuccessResponses
#[derive(Object)]#[oai(inline)]pubstructSuccessResponses<T:ParseFromJSON + ToJSON>{status:i32,data:T,}#[derive(ApiResponse)]pubenumCustomApiResponse<T:ParseFromJSON + ToJSON>{#[oai(status = 200)]Ok(poem_openapi::payload::Json<SuccessResponses<T>>),/// Returns when the BadRequest.#[oai(status = 400)]BadRequest,}
Steps to Reproduce the Problem
this is error message:
Specifications
The text was updated successfully, but these errors were encountered: