Skip to content

Commit

Permalink
[SCB-925]allow disable required check for a while
Browse files Browse the repository at this point in the history
  • Loading branch information
liubao68 committed Jan 8, 2019
1 parent 8d2e6e8 commit 1a50486
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.type.TypeFactory;
import com.netflix.config.DynamicPropertyFactory;

import io.swagger.models.parameters.HeaderParameter;
import io.swagger.models.parameters.Parameter;
Expand All @@ -42,6 +43,10 @@ public class HeaderProcessorCreator implements ParamValueProcessorCreator {
public static final String PARAMTYPE = "header";

public static class HeaderProcessor extends AbstractParamProcessor {
// This configuration is used for temporary use only. Do not use it if you are sure how it works. And may be deleted in future.
private boolean ignoreRequiredCheck = DynamicPropertyFactory.getInstance()
.getBooleanProperty("servicecomb.rest.parameter.header.ignoreRequiredCheck", false).get();

public HeaderProcessor(String paramPath, JavaType targetType, Object defaultValue, boolean required) {
super(paramPath, targetType, defaultValue, required);
}
Expand All @@ -67,7 +72,7 @@ public Object getValue(HttpServletRequest request) {
}

private Object checkRequiredAndDefaultValue() {
if (isRequired()) {
if (!ignoreRequiredCheck && isRequired()) {
throw new InvocationException(Status.BAD_REQUEST, "Parameter is required.");
}
return getDefaultValue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ public static class QueryProcessor extends AbstractParamProcessor {
private boolean ignoreDefaultValue = DynamicPropertyFactory.getInstance()
.getBooleanProperty("servicecomb.rest.parameter.query.ignoreDefaultValue", false).get();

// This configuration is used for temporary use only. Do not use it if you are sure how it works. And may be deleted in future.
private boolean ignoreRequiredCheck = DynamicPropertyFactory.getInstance()
.getBooleanProperty("servicecomb.rest.parameter.query.ignoreRequiredCheck", false).get();

private SwaggerParamCollectionFormat collectionFormat;

public QueryProcessor(String paramPath, JavaType targetType, Object defaultValue, boolean required,
Expand Down Expand Up @@ -83,7 +87,7 @@ public Object getValue(HttpServletRequest request) {
}

private Object checkRequiredAndDefaultValue() {
if (isRequired()) {
if (!ignoreRequiredCheck && isRequired()) {
throw new InvocationException(Status.BAD_REQUEST, "Parameter is required.");
}
Object defaultValue = getDefaultValue();
Expand Down

0 comments on commit 1a50486

Please sign in to comment.