poem
poem copied to clipboard
Can't fill in examples in rapidoc when using Oneof types
Hi, First of all, thanks for all the work done. I recently found some issues when using the Oneof types: I can't fill in an example on the rapidoc ui.
Expected Behavior
developer should be able to choose and fill an example request on ui
Actual Behavior

Steps to Reproduce the Problem
a slight change in examples can reproduce this issue
use poem::{listener::TcpListener, Route, Server};
use poem_openapi::{payload::Json, Object, OpenApi, OpenApiService, Union};
#[derive(Object, Debug, PartialEq)]
struct A {
v1: i32,
v2: String,
}
#[derive(Object, Debug, PartialEq)]
struct B {
v3: f32,
}
#[derive(Union, Debug, PartialEq)]
#[oai(one_of = true, discriminator_name = "type")]
enum MyObj {
A(A),
B(B),
}
struct Api;
#[OpenApi]
impl Api {
#[oai(path = "/put", method = "post")]
async fn index(&self, obj: Json<MyObj>) -> Json<MyObj> {
obj
}
}
#[tokio::main]
async fn main() -> Result<(), std::io::Error> {
if std::env::var_os("RUST_LOG").is_none() {
std::env::set_var("RUST_LOG", "poem=debug");
}
tracing_subscriber::fmt::init();
let api_service = OpenApiService::new(Api, "Union", "1.0").server("http://localhost:3000/api");
let ui = api_service.rapidoc();
let spec = api_service.spec_endpoint();
Server::new(TcpListener::bind("127.0.0.1:3000"))
.run(
Route::new()
.nest("/api", api_service)
.nest("/", ui)
.at("/spec", spec),
)
.await
}
Specifications
- Version: poem-openapi = { version = "1.2.56", features = ["rapidoc"] }
- Platform: ProductName: macOS ProductVersion: 12.0.1 BuildVersion: 21A559
- Subsystem:
I also don't understand why this is happening, it looks like the generated spec is correct. 😂
I hope someone will tell me why. 🙂
There a some validators e.g. at https://apitools.dev/swagger-parser/online/ or https://editor.swagger.io/ (which funnily show some errors for the poem-generated spec, in my case they complain about an externalDocs: null
that isn't supposed to be included, if null, and the summary
being non standard, but probably I just made a mistake somewhere.)
Maybe some of these point out a mistake somewhere?
@Christoph-AK Thanks a lot, this tool definitely helps me.
I verified a project of my own, which uses almost all the functionality of poem-openapi
, generated about 10,000 lines of spec, and found no other errors except externalDocs
. 🙂
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.
This issue was closed because it has been stalled for 5 days with no activity.