poem icon indicating copy to clipboard operation
poem copied to clipboard

Can't fill in examples in rapidoc when using Oneof types

Open saintazunya opened this issue 3 years ago • 6 comments

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

Screen Shot 2022-02-14 at 9 45 17 PM can do nothing here

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:

saintazunya avatar Feb 15 '22 05:02 saintazunya

I also don't understand why this is happening, it looks like the generated spec is correct. 😂

sunli829 avatar Feb 15 '22 08:02 sunli829

I hope someone will tell me why. 🙂

sunli829 avatar Feb 15 '22 08:02 sunli829

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 avatar Feb 15 '22 15:02 Christoph-AK

@Christoph-AK Thanks a lot, this tool definitely helps me.

sunli829 avatar Feb 16 '22 01:02 sunli829

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. 🙂

sunli829 avatar Feb 16 '22 01:02 sunli829

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.

github-actions[bot] avatar Aug 10 '22 02:08 github-actions[bot]

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.

github-actions[bot] avatar Sep 10 '22 03:09 github-actions[bot]

This issue was closed because it has been stalled for 5 days with no activity.

github-actions[bot] avatar Sep 15 '22 04:09 github-actions[bot]