Skip to content

Commit 16e8941

Browse files
committed
Returning cache to life.
1 parent 500ddcf commit 16e8941

12 files changed

Lines changed: 211 additions & 199 deletions

File tree

springfox-core/src/main/java/springfox/documentation/schema/ModelRef.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,8 @@ public boolean equals(Object o) {
183183
&& Objects.equals(
184184
allowableValues,
185185
that.allowableValues)
186-
&& modelId.isPresent() == that.modelId.isPresent();
186+
&& Objects.equals(
187+
modelId,
188+
that.modelId);
187189
}
188190
}

springfox-schema/src/main/java/springfox/documentation/schema/ModelReferenceProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,6 @@ private String modelId(ModelContext context) {
119119
|| enumTypeDeterminer.isEnum(type.getErasedType())) {
120120
return null;
121121
}
122-
return context.getTypeId();
122+
return context.getModelId();
123123
}
124124
}

springfox-schema/src/main/java/springfox/documentation/schema/TypeNameIndexingAdapter.java

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,18 @@ public Map<String, String> getNames() {
4040
}
4141

4242
@Override
43-
public Optional<String> getTypeName(String modelId) {
44-
return Optional.ofNullable(knownNames.get(modelId));
43+
public Optional<String> getTypeName(String typeId) {
44+
return Optional.ofNullable(knownNames.get(typeId));
4545
}
4646

4747
private boolean checkTypeRegistration(
4848
String typeName,
49-
String modelId) {
50-
if (knownNames.containsKey(modelId)) {
51-
if (!knownNames.get(modelId).equals(typeName)) {
49+
String typeId) {
50+
if (knownNames.containsKey(typeId)) {
51+
if (!knownNames.get(typeId).equals(typeName)) {
5252
LOG.info("Rewriting type {} with model id: {} is not allowed, because it is already registered",
5353
typeName,
54-
modelId);
54+
typeId);
5555
throw new IllegalStateException("Model already registered with different name.");
5656
} else {
5757
return true;
@@ -64,24 +64,24 @@ private boolean checkTypeRegistration(
6464
@Override
6565
public void registerType(
6666
String typeName,
67-
String modelId) {
67+
String typeId) {
6868
if (checkTypeRegistration(
6969
typeName,
70-
modelId)) {
70+
typeId)) {
7171
return;
7272
}
7373
knownNames.put(
74-
modelId,
74+
typeId,
7575
typeName);
7676
}
7777

7878
@Override
7979
public void registerUniqueType(
8080
String typeName,
81-
String modelId) {
81+
String typeId) {
8282
if (checkTypeRegistration(
8383
typeName,
84-
modelId)) {
84+
typeId)) {
8585
return;
8686
}
8787
Integer nameIndex = 0;
@@ -94,29 +94,29 @@ public void registerUniqueType(
9494
toString();
9595
}
9696
knownNames.put(
97-
modelId,
97+
typeId,
9898
tempName);
9999
}
100100

101101
@Override
102102
public void setEqualityFor(
103-
String modelIdOf,
104-
String modelIdTo) {
105-
if (!knownNames.containsKey(modelIdTo)) {
103+
String typeIdOf,
104+
String typeIdTo) {
105+
if (!knownNames.containsKey(typeIdTo)) {
106106
LOG.warn(
107107
"Model with model id: {} was not found, because it is not registered",
108-
modelIdTo);
108+
typeIdTo);
109109
throw new IllegalStateException("Model was not found");
110110
}
111-
if (knownNames.containsKey(modelIdOf) && !knownNames.get(modelIdOf).equals(knownNames.get(modelIdTo))) {
111+
if (knownNames.containsKey(typeIdOf) && !knownNames.get(typeIdOf).equals(knownNames.get(typeIdTo))) {
112112
LOG.warn(
113113
"Model with model id: {} already has equality to other model",
114-
modelIdTo);
114+
typeIdTo);
115115
throw new IllegalStateException("Model already has equality to other model");
116116
}
117117
knownNames.put(
118-
modelIdOf,
119-
knownNames.get(modelIdTo));
118+
typeIdOf,
119+
knownNames.get(typeIdTo));
120120
}
121121

122122
}

springfox-spi/src/main/java/springfox/documentation/spi/schema/UniqueTypeNameAdapter.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,40 +35,40 @@ public interface UniqueTypeNameAdapter {
3535
/**
3636
* Returns type for the model
3737
*
38-
* @param modelId
39-
* - id of model
38+
* @param typeId
39+
* - id of model type
4040
* @return Optional of a model names
4141
*/
42-
Optional<String> getTypeName(String modelId);
42+
Optional<String> getTypeName(String typeId);
4343

4444
/**
4545
* Add model name as is without adjusting
4646
*
4747
* @param typeName
4848
* - string representation of the models name
49-
* @param modelId
50-
* - id of model
49+
* @param typeId
50+
* - id of model type
5151
*/
52-
void registerType(String typeName, String modelId);
52+
void registerType(String typeName, String typeId);
5353

5454
/**
5555
* Register model name to keep it unique
5656
*
5757
* @param typeName
5858
* - string representation of the models name
59-
* @param modelId
60-
* - id of model
59+
* @param typeId
60+
* - id of model type
6161
*/
62-
void registerUniqueType(String typeName, String modelId);
62+
void registerUniqueType(String typeName, String typeId);
6363

6464
/**
6565
* Sets equality of two models to make sure, that models will be treated as one
6666
*
6767
* @param modelIdOf
68-
* - id of the current model
68+
* - id of current model type
6969
* @param modelIdTo
70-
* - id of the existing model
70+
* - id of existing model type
7171
*/
72-
void setEqualityFor(String modelIdOf, String modelIdTo);
72+
void setEqualityFor(String typeIdOf, String typeIdTo);
7373

7474
}

springfox-spi/src/main/java/springfox/documentation/spi/schema/contexts/ModelContext.java

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,7 @@ private ModelContext(
7676
this.view = view;
7777
this.validationGroups = new HashSet<>(validationGroups);
7878
this.modelBuilder =
79-
new ModelBuilder(new StringBuilder(parameterId)
80-
.append("_")
81-
.append(type.getBriefDescription()).
82-
toString());
79+
new ModelBuilder(getModelId());
8380
}
8481

8582
@SuppressWarnings("ParameterNumber")
@@ -99,10 +96,7 @@ private ModelContext(
9996
this.registeredTypes = parentContext.registeredTypes;
10097
this.genericNamingStrategy = parentContext.getGenericNamingStrategy();
10198
this.modelBuilder =
102-
new ModelBuilder(new StringBuilder(parameterId)
103-
.append("_")
104-
.append(type.getBriefDescription()).
105-
toString());
99+
new ModelBuilder(getModelId());
106100
}
107101

108102
/**
@@ -120,12 +114,19 @@ public String getParameterId() {
120114
}
121115

122116
/**
123-
* @return type id behind this context
117+
* @return type id of model behind this context
118+
*/
119+
public String getModelId() {
120+
return type.getBriefDescription();
121+
}
122+
123+
/**
124+
* @return type id of type behind this context
124125
*/
125126
public String getTypeId() {
126127
return new StringBuilder(parameterId)
127128
.append("_")
128-
.append(type.getBriefDescription()).
129+
.append(getModelId()).
129130
toString();
130131
}
131132

@@ -324,8 +325,7 @@ public boolean equals(Object o) {
324325
ModelContext that = (ModelContext) o;
325326

326327
return
327-
Objects.equals(parameterId, that.parameterId)
328-
&& Objects.equals(groupName, that.groupName)
328+
Objects.equals(groupName, that.groupName)
329329
&& Objects.equals(type, that.type)
330330
&& Objects.equals(view, that.view)
331331
&& Objects.equals(validationGroups, that.validationGroups)
@@ -344,7 +344,6 @@ private String namingStrategy() {
344344
@Override
345345
public int hashCode() {
346346
return Objects.hash(
347-
parameterId,
348347
groupName,
349348
type,
350349
view,

springfox-spi/src/main/java/springfox/documentation/spi/service/contexts/OperationModelContextsBuilder.java

Lines changed: 32 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -62,96 +62,60 @@ public OperationModelContextsBuilder(
6262
}
6363

6464
public ModelContext addReturn(ResolvedType type) {
65-
return addReturn(
66-
type,
67-
Optional.empty());
65+
return addReturn(type, Optional.empty());
6866
}
6967

70-
public ModelContext addReturn(
71-
ResolvedType type,
72-
Optional<ResolvedType> view) {
73-
Optional<ModelContext> context =
74-
contexts.stream()
75-
.filter(ctx -> ctx.getType().equals(type)
76-
&& ctx.getView().equals(view)
77-
&& ctx.getValidationGroups().equals(new HashSet<ResolvedType>())
78-
&& ctx.isReturnType()).findFirst();
79-
80-
if (context.isPresent()) {
81-
return context.get();
82-
} else {
83-
ModelContext returnValue = ModelContext.returnValue(
84-
String.format(
85-
"%s_%s",
86-
requestMappingId,
87-
parameterIndex),
88-
group,
89-
type,
90-
view,
91-
documentationType,
92-
alternateTypeProvider,
93-
genericsNamingStrategy,
94-
ignorableTypes);
95-
this.contexts.add(returnValue);
68+
public ModelContext addReturn(ResolvedType type, Optional<ResolvedType> view) {
69+
ModelContext returnValue = ModelContext.returnValue(
70+
String.format("%s_%s", requestMappingId, parameterIndex),
71+
group,
72+
type,
73+
view,
74+
documentationType,
75+
alternateTypeProvider,
76+
genericsNamingStrategy,
77+
ignorableTypes);
78+
if (this.contexts.add(returnValue)) {
9679
++parameterIndex;
9780
return returnValue;
9881
}
82+
83+
return contexts.stream().filter(context -> context.equals(returnValue)).findFirst().get();
9984
}
10085

10186
public ModelContext addInputParam(ResolvedType type) {
102-
return addInputParam(
103-
type,
104-
Optional.empty(),
105-
new HashSet<>());
87+
return addInputParam(type, Optional.empty(), new HashSet<>());
10688
}
10789

10890
public ModelContext addInputParam(
10991
ResolvedType type,
11092
Optional<ResolvedType> view,
11193
Set<ResolvedType> validationGroups) {
11294
validationGroups = new HashSet<>(validationGroups);
113-
Set<ResolvedType> finalValidationGroups = validationGroups;
114-
Optional<ModelContext> context =
115-
contexts.stream()
116-
.filter(ctx -> ctx.getType().equals(type) &&
117-
ctx.getView().equals(view)
118-
&& ctx.getValidationGroups().equals(finalValidationGroups)
119-
&& !ctx.isReturnType())
120-
.findFirst();
121-
122-
if (context.isPresent()) {
123-
return context.get();
124-
} else {
125-
ModelContext inputParam = ModelContext.inputParam(
126-
String.format(
127-
"%s_%s",
128-
requestMappingId,
129-
parameterIndex),
130-
group,
131-
type,
132-
view,
133-
validationGroups,
134-
documentationType,
135-
alternateTypeProvider,
136-
genericsNamingStrategy,
137-
ignorableTypes);
138-
this.contexts.add(inputParam);
95+
ModelContext inputParam = ModelContext.inputParam(
96+
String.format("%s_%s", requestMappingId, parameterIndex),
97+
group,
98+
type,
99+
view,
100+
validationGroups,
101+
documentationType,
102+
alternateTypeProvider,
103+
genericsNamingStrategy,
104+
ignorableTypes);
105+
if (this.contexts.add(inputParam)) {
139106
++parameterIndex;
140107
return inputParam;
141108
}
109+
110+
return contexts.stream().filter(context -> context.equals(inputParam)).findFirst().get();
142111
}
143112

144113
public Set<ModelContext> build() {
145-
Comparator<ModelContext> byParameterId =
146-
Comparator.comparing(ModelContext::getParameterId);
114+
Comparator<ModelContext> byParameterId = Comparator.comparing(ModelContext::getParameterId);
147115

148-
Supplier<TreeSet<ModelContext>> supplier =
149-
() -> new TreeSet<>(byParameterId);
116+
Supplier<TreeSet<ModelContext>> supplier = () -> new TreeSet<>(byParameterId);
150117

151-
return contexts.stream()
152-
.collect(
153-
collectingAndThen(
154-
Collectors.toCollection(supplier),
155-
Collections::unmodifiableSet));
118+
return contexts.stream().collect(
119+
collectingAndThen(Collectors.toCollection(supplier), Collections::unmodifiableSet));
156120
}
157121
}

springfox-spring-web/src/main/java/springfox/documentation/spring/web/scanners/ApiListingScanner.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
import java.util.Objects;
4747
import java.util.Optional;
4848
import java.util.Set;
49-
import java.util.TreeMap;
5049
import java.util.function.Predicate;
5150
import java.util.stream.Stream;
5251

@@ -127,7 +126,7 @@ public Map<String, List<ApiListing>> scan(ApiListingScanningContext context) {
127126

128127
List<SecurityReference> securityReferences = new ArrayList<>();
129128

130-
Map<String, Set<Model>> globalModelMap = new TreeMap<>();
129+
Map<String, Set<Model>> globalModelMap = new HashMap<>();
131130
for (final ResourceGroup resourceGroup : sortedByName(allResourceGroups)) {
132131

133132
DocumentationContext documentationContext = context.getDocumentationContext();
@@ -150,7 +149,7 @@ public Map<String, List<ApiListing>> scan(ApiListingScanningContext context) {
150149
}
151150
});
152151
globalModelMap.putAll(currentModelMap);
153-
apiDescriptions.addAll(apiDescriptionReader.read(each.withKnownModels(globalModelMap)));
152+
apiDescriptions.addAll(apiDescriptionReader.read(each.withKnownModels(currentModelMap)));
154153
}
155154

156155
List<ApiDescription> additional = additionalListings.stream()

0 commit comments

Comments
 (0)