Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
This repository was archived by the owner on Feb 26, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -330,16 +330,6 @@ public int numberOfElementParameterHasAnnotation(ExecutableElement element, Clas
return count;
}

public int numberOfNotAnnotatedElementParameter(ExecutableElement element) {
int count = 0;
for (VariableElement parameter : element.getParameters()) {
if (parameter.getAnnotationMirrors().size() == 0) {
count++;
}
}
return count;
}

public void doesntThrowException(Element element, ElementValidation valid) {
ExecutableElement executableElement = (ExecutableElement) element;
if (executableElement.getThrownTypes().size() > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,77 +60,77 @@ public interface MyService {
@RequiresCookie("xt")
@Get("/events/{year}/{location}")
@Accept(MediaType.APPLICATION_JSON)
EventList getEvents(String location, int year);
EventList getEvents(@Path String location, @Path int year);

@Get("/events/{year}/{location}")
@Accept("application/json")
Event[] getEventsArray(String location, int year);
Event[] getEventsArray(@Path String location, @Path int year);

@Get("/events/{year}/{year}")
@Accept(MediaType.APPLICATION_JSON)
Event[][] urlWithAParameterDeclaredTwice(int year);
Event[][] urlWithAParameterDeclaredTwice(@Path int year);

@Get("/events/{year}/{location}")
@Accept(MediaType.APPLICATION_JSON)
Event[][] getEventsArrayOfArrays(String location, int year);
Event[][] getEventsArrayOfArrays(@Path String location, @Path int year);

// The response can be a ResponseEntity<T>
@Get("/events/{year}/{location}")
/*
* You may (or may not) declare throwing RestClientException (as a reminder, since it's a RuntimeException), but nothing else.
*/
ResponseEntity<EventList> getEvents2(String location, int year) throws RestClientException;
ResponseEntity<EventList> getEvents2(@Path String location, @Path int year) throws RestClientException;

@Get("/events/{year}/{location}")
ResponseEntity<Event[]> getEventsArray2(String location, int year) throws RestClientException;
ResponseEntity<Event[]> getEventsArray2(@Path String location, @Path int year) throws RestClientException;

@Get("/events/{year}/{location}")
ResponseEntity<Event[][]> getEventsArrayOfArrays2(String location, int year) throws RestClientException;
ResponseEntity<Event[][]> getEventsArrayOfArrays2(@Path String location, @Path int year) throws RestClientException;

@Get("/events/{year}/{location}")
List<Event> getEventsGenericsList(String location, int year) throws RestClientException;
List<Event> getEventsGenericsList(@Path String location, @Path int year) throws RestClientException;

@Get("/events/{year}/{location}")
List<Event>[] getEventsGenericsArrayList(String location, int year) throws RestClientException;
List<Event>[] getEventsGenericsArrayList(@Path String location, @Path int year) throws RestClientException;

@Get("/events/{year}/{location}")
List<Event>[][] getEventsGenericsArrayList2(String location, int year) throws RestClientException;
List<Event>[][] getEventsGenericsArrayList2(@Path String location, @Path int year) throws RestClientException;

@Get("/events/{year}/{location}")
List<List<Event>> getEventsGenericsListListEvent(String location, int year) throws RestClientException;
List<List<Event>> getEventsGenericsListListEvent(@Path String location, @Path int year) throws RestClientException;

@Get("/events/{year}/{location}")
List<List<Event[]>> getEventsGenericsListListEvents(String location, int year) throws RestClientException;
List<List<Event[]>> getEventsGenericsListListEvents(@Path String location, @Path int year) throws RestClientException;

@Get("/events/{year}/{location}")
List<Event[]> getEventsGenericsListArray(String location, int year) throws RestClientException;
List<Event[]> getEventsGenericsListArray(@Path String location, @Path int year) throws RestClientException;

@Get("/events/{year}/{location}")
List<Event[][]> getEventsGenericsListArrayArray(String location, int year) throws RestClientException;
List<Event[][]> getEventsGenericsListArrayArray(@Path String location, @Path int year) throws RestClientException;

@Get("/events/{year}/{location}")
Set<Event> getEventsGenericsSet(String location, int year) throws RestClientException;
Set<Event> getEventsGenericsSet(@Path String location, @Path int year) throws RestClientException;

@Get("/events/{year}/{location}")
GenericEvent<String> getEventsGenericString(String location, int year) throws RestClientException;
GenericEvent<String> getEventsGenericString(@Path String location, @Path int year) throws RestClientException;

@Get("/events/{year}/{location}")
GenericEvent<Integer> getEventsGenericInteger(String location, int year) throws RestClientException;
GenericEvent<Integer> getEventsGenericInteger(@Path String location, @Path int year) throws RestClientException;

@Get("/events/{year}/{location}")
GenericEvent<List<Event>> getEventsGenericListEvent(String location, int year) throws RestClientException;
GenericEvent<List<Event>> getEventsGenericListEvent(@Path String location, @Path int year) throws RestClientException;

@Get("/events/{year}/{location}")
GenericEvent<GenericEvent<GenericEvent<String>>> getEventsGenericsInception(String location, int year) throws RestClientException;
GenericEvent<GenericEvent<GenericEvent<String>>> getEventsGenericsInception(@Path String location, @Path int year) throws RestClientException;

@Get("/events/{year}/{location}")
@SetsCookie({ "xt", "sjsaid" })
Map<String, Event> getEventsGenericsMap(String location, int year) throws RestClientException;
Map<String, Event> getEventsGenericsMap(@Path String location, @Path int year) throws RestClientException;

@RequiresCookie("sjsaid")
@RequiresCookieInUrl("xt")
@Get("/events/{year}/{location}?xt={xt}")
void getEventsVoid(String location, int year) throws RestClientException;
void getEventsVoid(@Path String location, @Path int year) throws RestClientException;

// *** POST ***
@RequiresHeader("SomeFancyHeader")
Expand All @@ -147,10 +147,10 @@ public interface MyService {
Event addEvent(@Body String event);

@Post("/events/{year}/")
Event addEvent(@Body Event event, int year);
Event addEvent(@Body Event event, @Path int year);

@Post("/events/{year}/")
Event addEvent(int year);
Event addEvent(@Path int year);

@Post("/events/")
ResponseEntity<Event> addEvent2(@Body Event event);
Expand All @@ -159,13 +159,13 @@ public interface MyService {
@RequiresHeader("SomeFancyHeader")
@RequiresCookie("myCookie")
@RequiresCookieInUrl("myCookieInUrl")
void addEventWithParameters(String date, @Field String parameter, @Field String otherParameter);
void addEventWithParameters(@Path String date, @Field String parameter, @Field String otherParameter);

@Post("/events/{date}?myCookieInUrl={myCookieInUrl}")
@RequiresHeader("SomeFancyHeader")
@RequiresCookie("myCookie")
@RequiresCookieInUrl("myCookieInUrl")
void addEventWithParts(String date, @Part String parameter, @Part String otherParameter);
void addEventWithParts(@Path String date, @Part String parameter, @Part String otherParameter);

@Post("/events/{date}?myCookieInUrl={myCookieInUrl}")
@RequiresHeader("SomeFancyHeader")
Expand All @@ -178,13 +178,13 @@ public interface MyService {
@Header(name = "SomeFancyHeader", value = "fancy")
@RequiresCookie("myCookie")
@RequiresCookieInUrl("myCookieInUrl")
void addEventWithHeaders(String date, @Body String parameter);
void addEventWithHeaders(@Path String date, @Body String parameter);

@Post("/events/{date}?myCookieInUrl={myCookieInUrl}")
@Headers(@Header(name = "SomeFancyHeader", value = "fancy"))
@RequiresCookie("myCookie")
@RequiresCookieInUrl("myCookieInUrl")
void addEventWithHeadersHeadersAnnotation(String date, @Body String parameter);
void addEventWithHeadersHeadersAnnotation(@Path String date, @Body String parameter);

/**
* Output different then input
Expand Down Expand Up @@ -222,78 +222,78 @@ public interface MyService {

@Post("/events/{year}/")
@Accept(MediaType.APPLICATION_JSON)
ResponseEntity<Event> addEvent2(@Body Event event, int year);
ResponseEntity<Event> addEvent2(@Body Event event, @Path int year);

// *** PUT ***

@Put("/events/{id}")
void updateEvent(@Body Event event, int id);
void updateEvent(@Body Event event, @Path int id);

@Put("/events/{date}")
void updateEvent(long date);
void updateEvent(@Path long date);

@Put("/events/{date}")
Event updateEventWithResponse(long date);
Event updateEventWithResponse(@Path long date);

@Put("/events/{date}?myCookieInUrl={myCookieInUrl}")
@RequiresHeader("SomeFancyHeader")
@RequiresCookie("myCookie")
@RequiresCookieInUrl("myCookieInUrl")
Event updateEventWithRequires(long date);
Event updateEventWithRequires(@Path long date);

// *** DELETE ***

@Delete("/events/{id}")
void removeEvent(long id);
void removeEvent(@Path long id);

@Delete("/events/{id}")
Event removeEventWithResponse(long id);
Event removeEventWithResponse(@Path long id);

@Delete("/events/{id}?myCookieInUrl={myCookieInUrl}")
@RequiresHeader("SomeFancyHeader")
@RequiresCookie("myCookie")
@RequiresCookieInUrl("myCookieInUrl")
void removeEventWithRequires(long id);
void removeEventWithRequires(@Path long id);

@Delete("/events/{id}")
@RequiresAuthentication
void removeEventWithAuthentication(long id);
void removeEventWithAuthentication(@Path long id);

// *** HEAD ***

@Head("/events/{year}/{location}")
HttpHeaders getEventHeaders(String location, int year);
HttpHeaders getEventHeaders(@Path String location, @Path int year);

@Head("/events/{date}")
HttpHeaders getEventheaders(long date);
HttpHeaders getEventheaders(@Path long date);

@Head("/events/{date}?myCookieInUrl={myCookieInUrl}")
@RequiresHeader("SomeFancyHeader")
@RequiresCookie("myCookie")
@RequiresCookieInUrl("myCookieInUrl")
HttpHeaders getEventheadersWithRequires(long date);
HttpHeaders getEventheadersWithRequires(@Path long date);

@Head("/events/{date}")
@RequiresAuthentication
HttpHeaders getEventheadersWithAuthentication(long date);
HttpHeaders getEventheadersWithAuthentication(@Path long date);

// *** OPTIONS ***

@Options("/events/{year}/{location}")
Set<HttpMethod> getEventOptions(String location, int year);
Set<HttpMethod> getEventOptions(@Path String location, @Path int year);

@Options("/events/{date}")
Set<HttpMethod> getEventOptions(long date);
Set<HttpMethod> getEventOptions(@Path long date);

@Options("/events/{date}?myCookieInUrl={myCookieInUrl}")
@RequiresHeader("SomeFancyHeader")
@RequiresCookie("myCookie")
@RequiresCookieInUrl("myCookieInUrl")
Set<HttpMethod> getEventOptionsWithRequires(long date);
Set<HttpMethod> getEventOptionsWithRequires(@Path long date);

@Options("/events/{date}")
@RequiresAuthentication
Set<HttpMethod> getEventOptionsWithAuthentication(long date);
Set<HttpMethod> getEventOptionsWithAuthentication(@Path long date);

// if you need to add some configuration to the Spring RestTemplate.
RestTemplate getRestTemplate();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@
public interface PathRestService extends RestClientSupport {

@Get(value = "{hello}{bye}{parameterName}")
void get(@Path("hello") String bye, @Path("bye") String hello, String parameterName);
void get(@Path("hello") String bye, @Path("bye") String hello, @Path String parameterName);
}
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public Set<String> extractUrlVariableNames(String uriTemplate) {
public JVar declareUrlVariables(ExecutableElement element, RestHolder holder, JBlock methodBody, SortedMap<String, JVar> methodParams) {
Map<String, String> urlNameToElementName = new HashMap<String, String>();
for (VariableElement variableElement : element.getParameters()) {
if (!hasPostParameterAnnotation(variableElement)) {
if (variableElement.getAnnotation(Path.class) != null) {
urlNameToElementName.put(getUrlVariableCorrespondingTo(variableElement), variableElement.getSimpleName().toString());
}
}
Expand Down Expand Up @@ -331,14 +331,7 @@ public JVar getEntitySentToServer(ExecutableElement element, SortedMap<String, J
}

public String getUrlVariableCorrespondingTo(VariableElement parameter) {
Path path = parameter.getAnnotation(Path.class);
String parameterName;
if (path != null && !path.value().equals("")) {
parameterName = path.value();
} else {
parameterName = parameter.getSimpleName().toString();
}
return parameterName;
return extractParameter(parameter, Path.class);
}

public IJExpression declareHttpEntity(JBlock body, JVar entitySentToServer, JVar httpHeaders) {
Expand Down Expand Up @@ -598,11 +591,7 @@ private String extractParameter(VariableElement parameter, Class<? extends Annot
return !value.equals("") ? value : parameter.getSimpleName().toString();
}

public boolean hasPostParameterAnnotation(VariableElement variableElement) {
return hasOneOfClassAnnotations(variableElement, Arrays.asList(Field.class, Part.class, Body.class));
}

public boolean hasRequestParameterAnnotation(VariableElement variableElement) {
public boolean hasRestApiMethodParameterAnnotation(VariableElement variableElement) {
return hasOneOfClassAnnotations(variableElement, Arrays.asList(Field.class, Part.class, Body.class, Path.class));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ public void urlVariableNamesExistInParameters(ExecutableElement element, Set<Str

Set<String> parametersName = new HashSet<>();
for (VariableElement parameter : parameters) {
if (restAnnotationHelper.hasPostParameterAnnotation(parameter)) {
if (parameter.getAnnotation(Path.class) == null) {
continue;
}

Expand Down Expand Up @@ -441,8 +441,7 @@ public void urlVariableNameExistsInEnclosingAnnotation(Element element, ElementV

Set<String> urlVariableNames = restAnnotationHelper.extractUrlVariableNames(url);

String annotationValue = restAnnotationHelper.extractAnnotationValueParameter(element);
String expectedUrlVariableName = !annotationValue.equals("") ? annotationValue : element.getSimpleName().toString();
String expectedUrlVariableName = restAnnotationHelper.getUrlVariableCorrespondingTo((VariableElement) element);

if (!urlVariableNames.contains(expectedUrlVariableName)) {
validation.addError(element, "%s annotated parameter is has no corresponding url variable");
Expand Down Expand Up @@ -601,17 +600,12 @@ public void hasAnnotatedAllParameters(ExecutableElement element, ElementValidati
}

Set<String> urlVariableNames = restAnnotationHelper.extractUrlVariableNames(element);
if (urlVariableNames.size() != numberOfNotAnnotatedElementParameter(element) + numberOfPathAnnotatedParameter(element) + numberOfRequiresCookieInUrl(element)) {
validation.addError(element, "%s parameters must add annotations or define as @Path placeholders");
if (urlVariableNames.size() != numberOfPathAnnotatedParameter(element) + numberOfRequiresCookieInUrl(element)) {
validation.addError(element, "%s must have url variables corresponding to the @Path or @RequiresCookieInUrl annotation");
}

for (VariableElement variableElement : element.getParameters()) {
List<? extends AnnotationMirror> annotationMirrors = variableElement.getAnnotationMirrors();
if (annotationMirrors.size() == 0) {
if (!urlVariableNames.contains(variableElement.getSimpleName().toString())) {
validation.addError(element, "%s method parameters '" + variableElement + "' must be annotated");
}
} else if (!restAnnotationHelper.hasRequestParameterAnnotation(variableElement)) {
if (!restAnnotationHelper.hasRestApiMethodParameterAnnotation(variableElement)) {
validation.addError(element, "%s method parameters '" + variableElement + "' must be annotated");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package org.androidannotations.rest.spring;

import org.androidannotations.rest.spring.annotations.Field;
import org.androidannotations.rest.spring.annotations.Path;
import org.androidannotations.rest.spring.annotations.Put;
import org.androidannotations.rest.spring.annotations.Rest;
import org.springframework.http.converter.FormHttpMessageConverter;
Expand All @@ -33,6 +34,6 @@ public interface ClientWithParameters {
void moreParameter(@Field int id, @Field String str);

@Put("/{url}")
void oneParameterWithUrl(@Field int id, String url);
void oneParameterWithUrl(@Field int id, @Path String url);

}
Original file line number Diff line number Diff line change
Expand Up @@ -33,29 +33,26 @@
public interface ClientWithPathVariable {

@Delete("/test/{v1}/{v2}")
void deleteWithParameterEntity(int v1, String v2);
void deleteWithParameterEntity(@Path int v1, @Path String v2);

@Get("/test/{v1}/{v2}")
void getWithParameterEntity(int v1, String v2);
void getWithParameterEntity(@Path int v1, @Path String v2);

@Head("/test/{v1}/{v2}")
HttpHeaders headWithParameterEntity(int v1, String v2);
HttpHeaders headWithParameterEntity(@Path int v1, @Path String v2);

@Options("/test/{v1}/{v2}")
Set<HttpMethod> optionsWithParameterEntity(int v1, String v2);
Set<HttpMethod> optionsWithParameterEntity(@Path int v1, @Path String v2);

@Post("/test/{v1}/{v2}")
void postWithParameterEntity(int v1, String v2);
void postWithParameterEntity(@Path int v1, @Path String v2);

@Put("/test/{v1}/{v2}")
void putWithParameterEntity(int v1, String v2);
void putWithParameterEntity(@Path int v1, @Path String v2);

@Get("/test/{v1}")
void getWithPathAnnotation(@Path("v1") int version);

@Get("/test/{v1}/{v2}")
void getWithPathAnnotationAndParam(@Path("v1") int v1, String v2);

@Get("/test/{v1}/{v2}")
void getWithCrossParamAnnotations(@Path("v1") int v2, @Path("v2") int v1);
}
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.