1313 */
1414package feign .spring ;
1515
16- import java .lang .annotation .Annotation ;
17- import java .lang .reflect .Method ;
1816import java .util .ArrayList ;
1917import java .util .Collection ;
20- import org .springframework .web .bind .annotation .ExceptionHandler ;
21- import org .springframework .web .bind .annotation .PathVariable ;
22- import org .springframework .web .bind .annotation .RequestBody ;
23- import org .springframework .web .bind .annotation .RequestMapping ;
24- import org .springframework .web .bind .annotation .RequestParam ;
25- import org .springframework .web .bind .annotation .ResponseBody ;
26- import feign .Contract .BaseContract ;
18+ import org .springframework .web .bind .annotation .*;
2719import feign .DeclarativeContract ;
2820import feign .MethodMetadata ;
21+ import feign .Request ;
2922
3023public class SpringContract extends DeclarativeContract {
3124
@@ -51,6 +44,42 @@ public SpringContract() {
5144 data .template ().method (requestMapping .method ()[0 ].name ());
5245 });
5346
47+
48+ registerMethodAnnotation (GetMapping .class , (mapping , data ) -> {
49+ appendMappings (data , mapping .value ());
50+ data .template ().method (Request .HttpMethod .GET );
51+ handleProducesAnnotation (data , mapping .produces ());
52+ handleConsumesAnnotation (data , mapping .consumes ());
53+ });
54+
55+ registerMethodAnnotation (PostMapping .class , (mapping , data ) -> {
56+ appendMappings (data , mapping .value ());
57+ data .template ().method (Request .HttpMethod .POST );
58+ handleProducesAnnotation (data , mapping .produces ());
59+ handleConsumesAnnotation (data , mapping .consumes ());
60+ });
61+
62+ registerMethodAnnotation (PutMapping .class , (mapping , data ) -> {
63+ appendMappings (data , mapping .value ());
64+ data .template ().method (Request .HttpMethod .PUT );
65+ handleProducesAnnotation (data , mapping .produces ());
66+ handleConsumesAnnotation (data , mapping .consumes ());
67+ });
68+
69+ registerMethodAnnotation (DeleteMapping .class , (mapping , data ) -> {
70+ appendMappings (data , mapping .value ());
71+ data .template ().method (Request .HttpMethod .DELETE );
72+ handleProducesAnnotation (data , mapping .produces ());
73+ handleConsumesAnnotation (data , mapping .consumes ());
74+ });
75+
76+ registerMethodAnnotation (PatchMapping .class , (mapping , data ) -> {
77+ appendMappings (data , mapping .value ());
78+ data .template ().method (Request .HttpMethod .PATCH );
79+ handleProducesAnnotation (data , mapping .produces ());
80+ handleConsumesAnnotation (data , mapping .consumes ());
81+ });
82+
5483 registerMethodAnnotation (ResponseBody .class , (body , data ) -> {
5584 handleConsumesAnnotation (data , "application/json" );
5685 });
0 commit comments