Allow request and path parameters to be marked as optional

Closes gh-169
This commit is contained in:
Andy Wilkinson
2016-04-13 12:36:50 +01:00
parent ecdc1971c2
commit ae53a4e8eb
5 changed files with 64 additions and 5 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2015 the original author or authors.
* Copyright 2014-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -71,6 +71,22 @@ public class PathParametersSnippetTests extends AbstractSnippetTests {
"/{a}/{b}").build());
}
@Test
public void missingOptionalPathParameter() throws IOException {
this.snippet
.expectPathParameters(
"missing-optional-path-parameter")
.withContents(tableWithTitleAndHeader(
this.templateFormat == TemplateFormats.asciidoctor() ? "/{a}"
: "`/{a}`",
"Parameter", "Description").row("a", "one").row("b", "two"));
new PathParametersSnippet(Arrays.asList(parameterWithName("a").description("one"),
parameterWithName("b").description("two").optional())).document(
operationBuilder("missing-optional-path-parameter").attribute(
RestDocumentationGenerator.ATTRIBUTE_NAME_URL_TEMPLATE,
"/{a}").build());
}
@Test
public void pathParametersWithQueryString() throws IOException {
this.snippet.expectPathParameters("path-parameters-with-query-string")

View File

@@ -80,6 +80,19 @@ public class RequestParametersSnippetTests extends AbstractSnippetTests {
.param("b", "bravo").build());
}
@Test
public void missingOptionalRequestParameter() throws IOException {
this.snippet.expectRequestParameters("missing-optional-request-parameter")
.withContents(tableWithHeader("Parameter", "Description").row("a", "one")
.row("b", "two"));
new RequestParametersSnippet(
Arrays.asList(parameterWithName("a").description("one").optional(),
parameterWithName("b").description("two"))).document(
operationBuilder("missing-optional-request-parameter")
.request("http://localhost").param("b", "bravo")
.build());
}
@Test
public void requestParametersWithCustomAttributes() throws IOException {
TemplateResourceResolver resolver = mock(TemplateResourceResolver.class);