poem icon indicating copy to clipboard operation
poem copied to clipboard

Union of 2 apis with same endpoint but different methods are not shown

Open rsfunc opened this issue 1 year ago • 0 comments

Expected Behavior

Expected 4 endpoints, 2 from one api and 2 from another

Actual Behavior

Only three pop up

Steps to Reproduce the Problem

use poem::listener::TcpListener;
use poem::Route;
use poem_openapi::payload;
use poem_openapi::OpenApi;
use poem_openapi::OpenApiService;

struct Api1;

#[OpenApi]
impl Api1 {
    /// Get
    ///
    #[oai(path = "/resource", method = "get")]
    async fn resource(&self) -> payload::PlainText<String> {
        payload::PlainText("get".to_owned())
    }
    /// Get1
    ///
    #[oai(path = "/resource1", method = "get")]
    async fn resource1(&self) -> payload::PlainText<String> {
        payload::PlainText("get1".to_owned())
    }
}

struct Api2;

#[OpenApi]
impl Api2 {
    /// Post
    ///
    #[oai(path = "/resource", method = "post")]
    async fn resource(&self) -> payload::PlainText<String> {
        payload::PlainText("post".to_owned())
    }

    /// Post2
    ///
    #[oai(path = "/resource2", method = "post")]
    async fn resource2(&self) -> payload::PlainText<String> {
        payload::PlainText("post2".to_owned())
    }
}

#[tokio::main]
async fn main() {
    let port = 80;
    let api_service = OpenApiService::new((Api1, Api2), "Apis", "1.0")
        .server(format!("http://localhost:{port}/"));

    let ui_swagger = api_service.swagger_ui();
    let ui_openapi_explorer = api_service.openapi_explorer();
    let ui_rapidoc = api_service.rapidoc();
    let ui_redoc = api_service.redoc();

    let app = Route::new()
        //
        .nest("/", api_service)
        .nest("/api/swagger", ui_swagger)
        .nest("/api/openapi_explorer", ui_openapi_explorer)
        .nest("/api/rapid", ui_rapidoc)
        .nest("/api/redoc", ui_redoc);

    poem::Server::new(TcpListener::bind(format!("0.0.0.0:{port}")))
        .run(app)
        .await
        .expect("a server")
}

Cargo.toml:

[package]
name = "api_union"
version = "0.1.0"
edition = "2021"


[[bin]]
path = "src/main.rs"
name = "main"

[dependencies]
poem = { version = "1.3.58", features = ["rustls"] }
poem-openapi = { version = "3.0.5", features = [
    "swagger-ui",
    "rapidoc",
    "openapi-explorer",
    "redoc",
] }
tokio = { version = "1.33.0", features = ["full"] }

Specifications

  • Version: poem-openapi 3.0.5
  • Platform: osx (m1)
  • Subsystem:

rsfunc avatar Nov 26 '23 11:11 rsfunc