Skip to content
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

openapi Union does not properly use flatten in documentation #945

Open
rsfunc opened this issue Jan 5, 2025 · 0 comments
Open

openapi Union does not properly use flatten in documentation #945

rsfunc opened this issue Jan 5, 2025 · 0 comments
Labels
bug Something isn't working

Comments

@rsfunc
Copy link

rsfunc commented Jan 5, 2025

Expected Behavior

For redoc for flatten endpoint I expect some help about the fields:

"other": "flatten",
"type": "ValueB",
"value": true
}

NOTE: the actual output of the endpoint is correct, only the documentation is not!

Actual Behavior

image

Steps to Reproduce the Problem

  1. Compile the given sample

Cargo.toml

[package]
name = "example-openapi-flatten"
version.workspace = true
edition.workspace = true
publish.workspace = true

[dependencies]
poem = { version="3.1.6" }
poem-openapi = { version="5.1.5", features= ["redoc", "swagger-ui"]}
tokio = { version = "1.42.0", features = ["macros", "rt-multi-thread"] }
tracing-subscriber = {version = "0.3.19" }

Main.rs

use poem::{listener::TcpListener, Route, Server};
use poem_openapi::{
    param::Query,
    payload::{Json, PlainText},
    Object, OpenApi, OpenApiService, Union,
};

struct Api;

#[derive(Object)]
struct ValueA {
    pub value: bool,
}

#[derive(Object)]
struct ValueB {
    pub value: bool,
}

#[derive(Union)]
#[oai(one_of = true, discriminator_name = "type")]
enum UnionEnum {
    ValueA(ValueA),
    ValueB(ValueB),
}

#[derive(Object)]
struct Flatten {
    #[oai(flatten)]
    inner: UnionEnum,
    other: String,
}

#[OpenApi]
impl Api {
    #[oai(path = "/flatten", method = "get")]
    async fn flatten(&self) -> Json<Flatten> {
        Json(Flatten {
            inner: UnionEnum::ValueB(ValueB { value: true }),
            other: "flatten".into(),
        })
    }
}

#[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, "Hello World", "1.0").server("http://localhost:3000/api");
    let ui = api_service.redoc();

    Server::new(TcpListener::bind("0.0.0.0:3000"))
        .run(Route::new().nest("/api", api_service).nest("/", ui))
        .await
}

Specifications

  • Version: cargo 1.83.0 (5ffbef321 2024-10-29)
  • Platform: osx
  • Subsystem:
@rsfunc rsfunc added the bug Something isn't working label Jan 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant