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

@@ -85,7 +85,13 @@ public abstract class AbstractParametersSnippet extends TemplatedSnippet {
private void verifyParameterDescriptors(Operation operation) {
Set<String> actualParameters = extractActualParameters(operation);
Set<String> expectedParameters = this.descriptorsByName.keySet();
Set<String> expectedParameters = new HashSet<>();
for (Entry<String, ParameterDescriptor> entry : this.descriptorsByName
.entrySet()) {
if (!entry.getValue().isOptional()) {
expectedParameters.add(entry.getKey());
}
}
Set<String> undocumentedParameters = new HashSet<>(actualParameters);
undocumentedParameters.removeAll(expectedParameters);
Set<String> missingParameters = new HashSet<>(expectedParameters);

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.
@@ -29,6 +29,8 @@ public class ParameterDescriptor extends IgnorableDescriptor<ParameterDescriptor
private final String name;
private boolean optional;
/**
* Creates a new {@code ParameterDescriptor} describing the parameter with the given
* {@code name}.
@@ -39,6 +41,16 @@ public class ParameterDescriptor extends IgnorableDescriptor<ParameterDescriptor
this.name = name;
}
/**
* Marks the parameter as optional.
*
* @return {@code this}
*/
public final ParameterDescriptor optional() {
this.optional = true;
return this;
}
/**
* Returns the name of the parameter being described by this descriptor.
*
@@ -48,4 +60,15 @@ public class ParameterDescriptor extends IgnorableDescriptor<ParameterDescriptor
return this.name;
}
/**
* Returns {@code true} if the described parameter is optional, otherwise
* {@code false}.
*
* @return {@code true} if the described parameter is optional, otherwise
* {@code false}
*/
public final boolean isOptional() {
return this.optional;
}
}