Merge branch '1.2.x'

This commit is contained in:
Andy Wilkinson
2017-07-01 16:30:37 +01:00
5 changed files with 48 additions and 6 deletions

View File

@@ -287,6 +287,15 @@ public abstract class AbstractFieldsSnippet extends TemplatedSnippet {
return this.fieldDescriptors;
}
/**
* Returns whether or not this snippet ignores undocumented fields.
*
* @return {@code true} if undocumented fields are ignored, otherwise {@code false}
*/
protected final boolean isIgnoredUndocumentedFields() {
return this.ignoreUndocumentedFields;
}
/**
* Returns a model for the given {@code descriptor}.
*

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2016 the original author or authors.
* Copyright 2014-2017 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.
@@ -206,7 +206,8 @@ public class RequestFieldsSnippet extends AbstractFieldsSnippet {
combinedDescriptors.addAll(getFieldDescriptors());
combinedDescriptors.addAll(PayloadDocumentation.applyPathPrefix(pathPrefix,
Arrays.asList(additionalDescriptors)));
return new RequestFieldsSnippet(combinedDescriptors, this.getAttributes());
return new RequestFieldsSnippet(combinedDescriptors, getAttributes(),
isIgnoredUndocumentedFields());
}
/**
@@ -225,7 +226,8 @@ public class RequestFieldsSnippet extends AbstractFieldsSnippet {
getFieldDescriptors());
combinedDescriptors.addAll(
PayloadDocumentation.applyPathPrefix(pathPrefix, additionalDescriptors));
return new RequestFieldsSnippet(combinedDescriptors, this.getAttributes());
return new RequestFieldsSnippet(combinedDescriptors, getAttributes(),
isIgnoredUndocumentedFields());
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2016 the original author or authors.
* Copyright 2014-2017 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.
@@ -210,7 +210,8 @@ public class ResponseFieldsSnippet extends AbstractFieldsSnippet {
combinedDescriptors.addAll(getFieldDescriptors());
combinedDescriptors.addAll(PayloadDocumentation.applyPathPrefix(pathPrefix,
Arrays.asList(additionalDescriptors)));
return new ResponseFieldsSnippet(combinedDescriptors, this.getAttributes());
return new ResponseFieldsSnippet(combinedDescriptors, this.getAttributes(),
isIgnoredUndocumentedFields());
}
/**
@@ -229,7 +230,8 @@ public class ResponseFieldsSnippet extends AbstractFieldsSnippet {
getFieldDescriptors());
combinedDescriptors.addAll(
PayloadDocumentation.applyPathPrefix(pathPrefix, additionalDescriptors));
return new ResponseFieldsSnippet(combinedDescriptors, this.getAttributes());
return new ResponseFieldsSnippet(combinedDescriptors, this.getAttributes(),
isIgnoredUndocumentedFields());
}
}

View File

@@ -158,6 +158,20 @@ public class RequestFieldsSnippetTests extends AbstractSnippetTests {
.content("{\"a\": 5, \"b\": 4}").build());
}
@Test
public void allUndocumentedFieldsContinueToBeIgnoredAfterAddingDescriptors()
throws IOException {
this.snippets.expectRequestFields()
.withContents(tableWithHeader("Path", "Type", "Description")
.row("`b`", "`Number`", "Field b")
.row("`c.d`", "`Number`", "Field d"));
new RequestFieldsSnippet(Arrays.asList(fieldWithPath("b").description("Field b")),
true).andWithPrefix("c.", fieldWithPath("d").description("Field d"))
.document(this.operationBuilder.request("http://localhost")
.content("{\"a\":5,\"b\":4,\"c\":{\"d\": 3}}").build());
}
@Test
public void missingOptionalRequestField() throws IOException {
this.snippets.expectRequestFields()

View File

@@ -134,6 +134,21 @@ public class ResponseFieldsSnippetTests extends AbstractSnippetTests {
.content("{\"a\": 5, \"b\": 4}").build());
}
@Test
public void allUndocumentedFieldsContinueToBeIgnoredAfterAddingDescriptors()
throws IOException {
this.snippets.expectResponseFields()
.withContents(tableWithHeader("Path", "Type", "Description")
.row("`b`", "`Number`", "Field b")
.row("`c.d`", "`Number`", "Field d"));
new ResponseFieldsSnippet(
Arrays.asList(fieldWithPath("b").description("Field b")), true)
.andWithPrefix("c.", fieldWithPath("d").description("Field d"))
.document(this.operationBuilder.response()
.content("{\"a\":5,\"b\":4,\"c\":{\"d\": 3}}").build());
}
@Test
public void responseFieldsWithCustomAttributes() throws IOException {
TemplateResourceResolver resolver = mock(TemplateResourceResolver.class);