poem-web / poem

A full-featured and easy-to-use web framework with the Rust programming language.
Apache License 2.0
3.47k stars 282 forks source link

Union doesn't implement `IsObjectType` #800

Open vpikulik opened 5 months ago

vpikulik commented 5 months ago

Expected Behavior

https://github.com/poem-web/poem/compare/master...vpikulik:poem:union_is_object_type

Actual Behavior

$ -> cargo check
    Checking example-openapi-union v0.1.0 (/Users/promo/wd/poem/examples/openapi/union)
error[E0277]: the trait bound `MyObj: IsObjectType` is not satisfied
  --> openapi/union/src/main.rs:25:8
   |
25 |     My(MyObj),
   |        ^^^^^ the trait `IsObjectType` is not implemented for `MyObj`
   |
   = help: the following other types implement trait `IsObjectType`:
             A
             B
note: required by a bound in `<TopObj as Type>::register::{closure#0}::_::{closure#0}::assert_impl_all`
  --> openapi/union/src/main.rs:22:10
   |
22 | #[derive(Union, Debug, PartialEq)]
   |          ^^^^^ required by this bound in `assert_impl_all`
   = note: this error originates in the macro `poem_openapi::__private::static_assertions::assert_impl_all` which comes from the expansion of the derive macro `Union` (in Nightly builds, run with -Z macro-backtrace for more info)

For more information about this error, try `rustc --explain E0277`.
error: could not compile `example-openapi-union` (bin "example-openapi-union") due to 1 previous error

Steps to Reproduce the Problem

  1. switch to https://github.com/poem-web/poem/compare/master...vpikulik:poem:union_is_object_type
  2. cd poem/examples/openapi/union
  3. cargo check

Specifications

How to solve

impl IsObjectType for MyObj {} solves the problem Should it be added to Union derive macro?

DDtKey commented 3 months ago

I guess it can be closed now as well as #799? Thank you @sunli829 !