Skip to content

Commit

Permalink
Merge branch 'bug/956/fix-2d-arrays'
Browse files Browse the repository at this point in the history
fixes #956
  • Loading branch information
dilipkrish committed Jan 2, 2016
2 parents 572b0fc + ce13ade commit 38f14d1
Show file tree
Hide file tree
Showing 58 changed files with 843 additions and 563 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import org.springframework.http.HttpMethod;
import springfox.documentation.OperationNameGenerator;
import springfox.documentation.annotations.Incubating;
import springfox.documentation.schema.ModelRef;
import springfox.documentation.schema.ModelReference;
import springfox.documentation.service.Operation;
import springfox.documentation.service.Parameter;
import springfox.documentation.service.ResponseMessage;
Expand Down Expand Up @@ -58,7 +58,7 @@ public class OperationBuilder {
private Set<String> tags = newHashSet();
private String deprecated;
private boolean isHidden;
private ModelRef responseModel;
private ModelReference responseModel;
private List<VendorExtension> vendorExtensions = newArrayList();

public OperationBuilder(OperationNameGenerator nameGenerator) {
Expand Down Expand Up @@ -234,7 +234,7 @@ public OperationBuilder hidden(boolean isHidden) {
* @param responseType = response type model reference
* @return this
*/
public OperationBuilder responseModel(ModelRef responseType) {
public OperationBuilder responseModel(ModelReference responseType) {
this.responseModel = defaultIfAbsent(responseType, this.responseModel);
return this;
}
Expand All @@ -249,7 +249,7 @@ public OperationBuilder tags(Set<String> tags) {
this.tags = nullToEmptySet(tags);
return this;
}

/**
* Updates the operation extensions
*
Expand All @@ -263,8 +263,22 @@ public OperationBuilder extensions(List<VendorExtension> extensions) {

public Operation build() {
String uniqueOperationId = nameGenerator.startingWith(uniqueOperationIdStem());
return new Operation(method, summary, notes, responseModel, uniqueOperationId, position, tags, produces,
consumes, protocol, securityReferences, parameters, responseMessages, deprecated, isHidden,
return new Operation(
method,
summary,
notes,
responseModel,
uniqueOperationId,
position,
tags,
produces,
consumes,
protocol,
securityReferences,
parameters,
responseMessages,
deprecated,
isHidden,
vendorExtensions);
}

Expand All @@ -281,7 +295,7 @@ private Set<ResponseMessage> mergeResponseMessages(Set<ResponseMessage> response
if (responsesByCode.containsKey(each.getCode())) {
ResponseMessage responseMessage = responsesByCode.get(each.getCode());
String message = defaultIfAbsent(emptyToNull(each.getMessage()), responseMessage.getMessage());
ModelRef responseWithModel = defaultIfAbsent(each.getResponseModel(), responseMessage.getResponseModel());
ModelReference responseWithModel = defaultIfAbsent(each.getResponseModel(), responseMessage.getResponseModel());
merged.remove(responseMessage);
merged.add(new ResponseMessageBuilder()
.code(each.getCode())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

import com.fasterxml.classmate.ResolvedType;
import com.google.common.base.Optional;
import springfox.documentation.schema.ModelRef;
import springfox.documentation.schema.ModelReference;
import springfox.documentation.service.AllowableValues;
import springfox.documentation.service.Parameter;

Expand All @@ -37,11 +37,12 @@ public class ParameterBuilder {
private String paramType;
private String paramAccess;
private ResolvedType type;
private ModelRef modelRef;
private ModelReference modelRef;


/**
* Copy builder
*
* @param other parameter to copy from
* @return this
*/
Expand Down Expand Up @@ -165,14 +166,23 @@ public ParameterBuilder type(ResolvedType type) {
* @param modelRef
* @return
*/
public ParameterBuilder modelRef(ModelRef modelRef) {
public ParameterBuilder modelRef(ModelReference modelRef) {
this.modelRef = defaultIfAbsent(modelRef, this.modelRef);
return this;
}


public Parameter build() {
return new Parameter(name, description, defaultValue, required, allowMultiple,
modelRef, Optional.fromNullable(type), allowableValues, paramType, paramAccess);
return new Parameter(
name,
description,
defaultValue,
required,
allowMultiple,
modelRef,
Optional.fromNullable(type),
allowableValues,
paramType,
paramAccess);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@

package springfox.documentation.builders;

import springfox.documentation.schema.ModelRef;
import springfox.documentation.schema.ModelReference;
import springfox.documentation.service.ResponseMessage;

public class ResponseMessageBuilder {
private int code;
private String message;
private ModelRef responseModel;
private ModelReference responseModel;

/**
* Updates the http response code
Expand Down Expand Up @@ -55,7 +55,7 @@ public ResponseMessageBuilder message(String message) {
* @param responseModel - model reference
* @return this
*/
public ResponseMessageBuilder responseModel(ModelRef responseModel) {
public ResponseMessageBuilder responseModel(ModelReference responseModel) {
this.responseModel = BuilderDefaults.defaultIfAbsent(responseModel, this.responseModel);
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
import static springfox.documentation.schema.WildcardType.*;

public class AlternateTypeRule {
private final ResolvedType original;
private final ResolvedType alternate;
protected final ResolvedType original;
protected final ResolvedType alternate;

/**
* Instantiates a new Alternate type rule.
Expand All @@ -47,12 +47,12 @@ public AlternateTypeRule(ResolvedType original, ResolvedType alternate) {
public ResolvedType alternateFor(ResolvedType type) {
if (appliesTo(type)) {
if (hasWildcards(original)) {
return WildcardType.replaceWildcardsFrom(WildcardType.collectReplaceables(type, original), alternate);
return replaceWildcardsFrom(WildcardType.collectReplaceables(type, original), alternate);
} else {
return alternate;
}
}
return original;
return type;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,5 @@ public static AlternateTypeRule newMapRule(Class<?> key, Class<?> value) {
return new AlternateTypeRule(resolver.resolve(Map.class, key, value),
resolver.resolve(List.class, resolver.resolve(Entry.class, key, value)));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class ModelProperty {
private final Boolean readOnly;
private final String description;
private final AllowableValues allowableValues;
private ModelRef modelRef;
private ModelReference modelRef;
private final String example;

public ModelProperty(
Expand Down Expand Up @@ -92,15 +92,15 @@ public AllowableValues getAllowableValues() {
return allowableValues;
}

public ModelRef getModelRef() {
public ModelReference getModelRef() {
return modelRef;
}

public boolean isHidden() {
return isHidden;
}

public ModelProperty updateModelRef(Function<? super ResolvedType, ModelRef> modelRefFactory) {
public ModelProperty updateModelRef(Function<ResolvedType, ? extends ModelReference> modelRefFactory) {
modelRef = modelRefFactory.apply(type);
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,59 +19,79 @@

package springfox.documentation.schema;

import com.google.common.base.Function;
import com.google.common.base.Optional;
import springfox.documentation.service.AllowableValues;

public class ModelRef {
public class ModelRef implements ModelReference {
private final String type;
private final boolean isMap;
private final Optional<String> itemType;
private final Optional<ModelReference> itemModel;
private final Optional<AllowableValues> allowableValues;

public ModelRef(String type, String itemType) {
public ModelRef(String type, ModelReference itemType) {
this(type, itemType, false);
}

public ModelRef(String type, String itemType, AllowableValues allowableValues) {
public ModelRef(String type, ModelReference itemType, AllowableValues allowableValues) {
this(type, itemType, allowableValues, false);
}

public ModelRef(String type, AllowableValues allowableValues) {
this(type, null, allowableValues);
}

public ModelRef(String type, String itemType, boolean isMap) {
public ModelRef(String type, ModelReference itemType, boolean isMap) {
this(type, itemType, null, isMap);
}

public ModelRef(String type, String itemType, AllowableValues allowableValues, boolean isMap) {
public ModelRef(String type, ModelReference itemModel, AllowableValues allowableValues, boolean isMap) {
this.type = type;
this.isMap = isMap;
this.allowableValues = Optional.fromNullable(allowableValues);
this.itemType = Optional.fromNullable(itemType);
this.itemModel = Optional.fromNullable(itemModel);
}

public ModelRef(String type) {
this(type, null, null);
}

@Override
public String getType() {
return type;
}


@Override
public boolean isCollection() {
return itemType.isPresent() && !isMap;
return itemModel.isPresent() && !isMap;
}

public boolean isMap() {
return itemType.isPresent() && isMap;
@Override
public boolean isMap(){
return itemModel.isPresent() && isMap;
}

@Override
public String getItemType() {
return itemType.orNull();
return itemModel.transform(toName()).orNull();
}

@Override
public AllowableValues getAllowableValues() {
return allowableValues.orNull();
}

@Override
public Optional<ModelReference> itemModel() {
return itemModel;
}

private Function<? super ModelReference, String> toName() {
return new Function<ModelReference, String>() {
@Override
public String apply(ModelReference input) {
return input.getType();
}
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
*
* Copyright 2015 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.
* You may obtain a copy of the License at
*
* http://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 springfox.documentation.schema;

import com.google.common.base.Optional;
import springfox.documentation.service.AllowableValues;

public interface ModelReference {
String getType();

boolean isCollection();

boolean isMap();

String getItemType();

AllowableValues getAllowableValues();

Optional<ModelReference> itemModel();
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import com.google.common.base.Function;
import com.google.common.collect.Maps;
import org.springframework.http.HttpMethod;
import springfox.documentation.schema.ModelRef;
import springfox.documentation.schema.ModelReference;

import java.util.Collection;
import java.util.List;
Expand All @@ -36,7 +36,7 @@ public class Operation {
private final HttpMethod method;
private final String summary;
private final String notes;
private final ModelRef responseModel;
private final ModelReference responseModel;
private final String uniqueId;
private final int position;
private final Set<String> tags;
Expand All @@ -50,12 +50,24 @@ public class Operation {
private final String deprecated;
private final List<VendorExtension> vendorExtensions;

public Operation(HttpMethod method, String summary, String notes, ModelRef responseModel,
String uniqueId, int position,
Set<String> tags, Set<String> produces, Set<String> consumes, Set<String> protocol,
List<SecurityReference> securityReferences, List<Parameter> parameters,
Set<ResponseMessage> responseMessages, String deprecated, boolean isHidden,
Collection<VendorExtension> vendorExtensions) {
public Operation(
HttpMethod method,
String summary,
String notes,
ModelReference responseModel,
String uniqueId,
int position,
Set<String> tags,
Set<String> produces,
Set<String> consumes,
Set<String> protocol,
List<SecurityReference> securityReferences,
List<Parameter> parameters,
Set<ResponseMessage> responseMessages,
String deprecated,
boolean isHidden,
Collection<VendorExtension> vendorExtensions) {

this.method = method;
this.summary = summary;
this.notes = notes;
Expand All @@ -78,7 +90,7 @@ public boolean isHidden() {
return isHidden;
}

public ModelRef getResponseModel() {
public ModelReference getResponseModel() {
return responseModel;
}

Expand Down

0 comments on commit 38f14d1

Please sign in to comment.