Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
88 additions
and
68 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ | |
|
||
package com.linecorp.armeria.server.docs; | ||
|
||
import static com.google.common.base.Preconditions.checkArgument; | ||
import static java.util.Comparator.comparing; | ||
import static java.util.Objects.requireNonNull; | ||
|
||
|
@@ -36,6 +37,7 @@ | |
import com.linecorp.armeria.common.HttpHeaders; | ||
import com.linecorp.armeria.common.HttpMethod; | ||
import com.linecorp.armeria.common.util.UnstableApi; | ||
import com.linecorp.armeria.internal.common.PathAndQuery; | ||
import com.linecorp.armeria.server.Service; | ||
|
||
/** | ||
|
@@ -114,8 +116,18 @@ public MethodInfo(String name, | |
this.exampleHttpHeaders = ImmutableList.copyOf(requireNonNull(exampleHttpHeaders, | ||
"exampleHttpHeaders")); | ||
this.exampleRequests = ImmutableList.copyOf(requireNonNull(exampleRequests, "exampleRequests")); | ||
|
||
this.examplePaths = ImmutableList.copyOf(requireNonNull(examplePaths, "examplePaths")); | ||
this.examplePaths.forEach(path -> checkArgument(PathAndQuery.parse(path) != null, | ||
"examplePaths contains an invalid path: {}", path)); | ||
|
||
this.exampleQueries = ImmutableList.copyOf(requireNonNull(exampleQueries, "exampleQueries")); | ||
this.exampleQueries.forEach(query -> { | ||
final PathAndQuery pathAndQuery = PathAndQuery.parse(query.startsWith("?") ? query : '?' + query); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
trustin
Member
|
||
checkArgument(pathAndQuery != null, | ||
"exampleQueries contains an invalid query string: {}", query); | ||
}); | ||
|
||
this.httpMethod = requireNonNull(httpMethod, "httpMethod"); | ||
this.docString = Strings.emptyToNull(docString); | ||
} | ||
|
41 changes: 0 additions & 41 deletions
41
core/src/test/java/com/linecorp/armeria/server/docs/DocServiceBuilderTest.java
This file was deleted.
Oops, something went wrong.
55 changes: 55 additions & 0 deletions
55
core/src/test/java/com/linecorp/armeria/server/docs/MethodInfoTest.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* Copyright 2020 LINE Corporation | ||
* | ||
* LINE Corporation licenses this file to you under the Apache License, | ||
* version 2.0 (the "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at: | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package com.linecorp.armeria.server.docs; | ||
|
||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
|
||
import java.util.List; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
|
||
import com.linecorp.armeria.common.HttpMethod; | ||
|
||
class MethodInfoTest { | ||
|
||
private static MethodInfo newMethodInfo(List<String> examplePaths, List<String> exampleQueries) { | ||
return new MethodInfo("foo", TypeSignature.ofBase("T"), | ||
/* parameters */ ImmutableList.of(), /* exceptionSignatures */ ImmutableList.of(), | ||
/* endpoints */ ImmutableList.of(), /* exampleHeaders */ ImmutableList.of(), | ||
/* exampleRequests */ ImmutableList.of(), | ||
examplePaths, exampleQueries, | ||
HttpMethod.GET, null); | ||
} | ||
|
||
@Test | ||
void invalidQueryString() { | ||
final String invalidQuery = "?%x"; | ||
assertThatThrownBy(() -> newMethodInfo(ImmutableList.of(), ImmutableList.of(invalidQuery))) | ||
.isInstanceOf(IllegalArgumentException.class) | ||
.hasMessageContaining("contains an invalid query string"); | ||
} | ||
|
||
@Test | ||
void invalidPath() { | ||
final String invalidPath = "a/b"; | ||
assertThatThrownBy(() -> newMethodInfo(ImmutableList.of(invalidPath), ImmutableList.of())) | ||
.isInstanceOf(IllegalArgumentException.class) | ||
.hasMessageContaining("contains an invalid path"); | ||
} | ||
} |
PathAndQuery
can validate a path and a query at once.PathAndQuery.path()
andquery()
after parsing.