Skip to content
This repository has been archived by the owner on Sep 28, 2021. It is now read-only.

Add Route#withDocString(DocString) #133

Merged
merged 1 commit into from
Jul 18, 2016
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
5 changes: 5 additions & 0 deletions apollo-api/src/main/java/com/spotify/apollo/route/Route.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ default Route<H> withDocString(String summary, String description) {
method(), uri(), handler(), doc(summary, description));
}

default Route<H> withDocString(DocString doc) {
return copy(
method(), uri(), handler(), doc);
}

default <K> Route<K> withMiddleware(Middleware<? super H, ? extends K> middleware) {
return copy(
method(), uri(), middleware.apply(handler()), docString().orElse(null));
Expand Down
12 changes: 12 additions & 0 deletions apollo-api/src/test/java/com/spotify/apollo/route/RouteTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@
package com.spotify.apollo.route;

import com.spotify.apollo.RequestContext;
import com.spotify.apollo.route.Route.DocString;

import org.junit.Before;
import org.junit.Test;

import java.util.Optional;

import static org.hamcrest.CoreMatchers.equalTo;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.mock;
Expand All @@ -45,4 +48,13 @@ public void shouldSupportSyncEndpointHandler() throws Exception {
String actual = route.handler().invoke(requestContext).toCompletableFuture().get();
assertThat(actual, equalTo("this is the best response"));
}

@Test
public void shouldSupportSupplyingDocStringValueType() throws Exception {
Route<AsyncHandler<String>> route =
Route.sync("GET", "/foo", requestContext -> "this is the best response")
.withDocString(DocString.doc("summary", "description"));

assertThat(route.docString(), equalTo(Optional.of(DocString.doc("summary", "description"))));
}
}