Add PATCH/HEAD/OPTIONS support; fix trait method visibility and enum query params - #14
Merged
Conversation
Contributor
Author
|
@dxx 😄 O(∩_∩)O 😄 |
Owner
|
@LiJoeAllen Thanks for your PR. |
Owner
|
@LiJoeAllen Hi, I think |
Contributor
Author
|
ok |
Contributor
Author
|
Sure! Since feignhttp can't retrieve response headers, HEAD/OPTIONS indeed aren't useful here. I've removed them in #15, keeping only PATCH. Thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Three improvements developed while building an OpenAPI-to-feignhttp code generator (feignhttp-generator) that emits
#[feign]trait clients and exercises them with wire-level integration tests.1. PATCH / HEAD / OPTIONS method support (c9d5d69)
codegen/src/enu.rs: addPatch/Head/Optionsto theMethodenum plusfrom_str/to_strmappings.codegen/src/lib.rs: expose#[patch],#[head],#[options]attribute macros.func.rsneeded no changes.examples/method.rs.2. Generated trait client methods were private (f5cd066)
The
#[feign]macro on a trait generates a shadow struct plus an inherentimpl TraitName { ... }containing the request methods.trait_method_to_item_fnhard-coded method visibility toVisibility::Inherited(private), so:E0624: method is private— which makes externally generated clients unusable.Fix: pass the trait's visibility into
fn_to_streams_for_trait->trait_method_to_item_fnand use it for the emitted methods.3. Enums could not be used as query parameters (2902696)
filter_structclassifies any non-primitive type as "struct", routing enum query args intoser::to_map.MapSerializer::serialize_unit_variantreturnsSerialize("not support unit_variant"), so#[query("granularity")] g: MyEnumalways failed at runtime, even thoughValueSerializeralready handles unit variants.Fix:
ser::to_pairs(PairsSerializer): ordered key-value collection where structs emit one pair per field, bare scalars/unit variants emit a single empty-key pair,Noneemits nothing, and newtype variants emit(variant, inner).to_pairsin both struct-query sites offunc.rs; an empty key falls back to the Rust argument name. Behavior for real structs is unchanged.Testing
os error 10013) unrelated to these changes; all examples compile.ErrorKind::Status.