Skip to content

Commit

Permalink
Refactor enums (#289)
Browse files Browse the repository at this point in the history
Refactor enum implemenation by keeping things DRY. This PR adds
better foundation over furhter development of features concerning enums.

Aslo remove the limitation of not allowing `schema` attribute to be used on
`oneOf` complex enum type. This allows defining of `default` and `example`
attribute over complex enum via `schema` attribute of `ToSchema` derive macro.

The enum refactoring is not complete but this PR will be first one in the serie of 
coming improvements and new features.

relates to #285
  • Loading branch information
juhaku authored Sep 19, 2022
1 parent 503042f commit e0b383f
Show file tree
Hide file tree
Showing 11 changed files with 624 additions and 334 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ jobs:
if [[ "${{ matrix.testset }}" == "utoipa" ]] && [[ ${{ steps.changes.outputs.utoipa_changed }} == true ]]; then
cargo test -p utoipa --features openapi_extensions,yaml
elif [[ "${{ matrix.testset }}" == "utoipa-gen" ]] && [[ ${{ steps.changes.outputs.gen_changed }} == true ]]; then
cargo test -p utoipa-gen --features utoipa/actix_extras,chrono,decimal,json,utoipa/uuid,utoipa/json,utoipa/time,time
cargo test -p utoipa-gen --features utoipa/actix_extras,chrono,decimal,json,utoipa/uuid,utoipa/json,utoipa/time,time,utoipa/repr
cargo test -p utoipa-gen --test path_response_derive_test_no_serde_json --no-default-features
cargo test -p utoipa-gen --test schema_derive_no_serde_json --no-default-features
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ and the `ipa` is _api_ reversed. Aaand... `ipa` is also awesome type of beer :be
- **smallvec** Add support for [smallvec](https://crates.io/crates/smallvec). `SmallVec` will be treated as `Vec`.
- **openapi_extensions** Adds traits and functions that provide extra convenience functions.
See the [`request_body` docs](https://docs.rs/utoipa/latest/utoipa/openapi/request_body) for an example.
- **repr** Add support for `repr(u*)` and `repr(i*)` attributes for fieldless enums.
See [docs](https://docs.rs/utoipa/latest/utoipa/derive.ToSchema.html) for more details.
- **repr** Add support for [repr_serde](https://github.com/dtolnay/serde-repr)'s `repr(u*)` and `repr(i*)` attributes to unit type enums for
C-like enum representation. See [docs](https://docs.rs/utoipa/latest/utoipa/derive.ToSchema.html) for more details.

Utoipa implicitly has partial support for `serde` attributes. See [docs](https://docs.rs/utoipa/latest/utoipa/derive.ToSchema.html#partial-serde-attributes-support) for more details.

Expand Down
2 changes: 1 addition & 1 deletion scripts/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ echo "Testing crate: $crate..."
if [[ "$crate" == "utoipa" ]]; then
cargo test -p utoipa --features openapi_extensions
elif [[ "$crate" == "utoipa-gen" ]]; then
cargo test -p utoipa-gen --features utoipa/actix_extras,chrono,decimal,json,utoipa/uuid,utoipa/json,utoipa/time,time
cargo test -p utoipa-gen --features utoipa/actix_extras,chrono,decimal,json,utoipa/uuid,utoipa/json,utoipa/time,time,utoipa/repr

cargo test -p utoipa-gen --test path_response_derive_test_no_serde_json --no-default-features
cargo test -p utoipa-gen --test schema_derive_no_serde_json --no-default-features
Expand Down
Loading

0 comments on commit e0b383f

Please sign in to comment.