Skip to content

Commit e7495aa

Browse files
committed
Fix: inconsistent naming of contract parts in javadoc
1 parent c8858f8 commit e7495aa

File tree

2 files changed

+60
-58
lines changed

2 files changed

+60
-58
lines changed

src/main/java/io/vertx/openapi/contract/OpenAPIContract.java

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import io.vertx.core.http.HttpMethod;
2020
import io.vertx.core.json.JsonObject;
2121
import io.vertx.json.schema.SchemaRepository;
22+
2223
import java.util.List;
2324
import java.util.Map;
2425

@@ -55,8 +56,8 @@ static Future<OpenAPIContract> from(Vertx vertx, String contractPath) {
5556
*/
5657
static Future<OpenAPIContract> from(Vertx vertx, JsonObject contract) {
5758
return builder(vertx)
58-
.setContract(contract)
59-
.build();
59+
.setContract(contract)
60+
.build();
6061
}
6162

6263
/**
@@ -71,12 +72,12 @@ static Future<OpenAPIContract> from(Vertx vertx, JsonObject contract) {
7172
* @return A succeeded {@link Future} holding an {@link OpenAPIContract} instance, otherwise a failed {@link Future}.
7273
*/
7374
static Future<OpenAPIContract> from(Vertx vertx, String contract,
74-
Map<String, String> additionalContractPartPaths) {
75+
Map<String, String> additionalContractPartPaths) {
7576

7677
return builder(vertx)
77-
.setContractPath(contract)
78-
.setAdditionalContractPartPaths(additionalContractPartPaths)
79-
.build();
78+
.setContractPath(contract)
79+
.setAdditionalContractPartPaths(additionalContractPartPaths)
80+
.build();
8081
}
8182

8283
/**
@@ -85,17 +86,17 @@ static Future<OpenAPIContract> from(Vertx vertx, String contract,
8586
* This method can be used in case that the contract is split into several files. These files can be passed in a
8687
* Map that has the reference as key and the path to the file as value.
8788
*
88-
* @param vertx The related Vert.x instance.
89-
* @param contract The unresolved contract.
90-
* @param additionalContractPartPaths The additional contract part paths
89+
* @param vertx The related Vert.x instance.
90+
* @param contract The unresolved contract.
91+
* @param additionalContractParts The additional contract parts
9192
* @return A succeeded {@link Future} holding an {@link OpenAPIContract} instance, otherwise a failed {@link Future}.
9293
*/
9394
static Future<OpenAPIContract> from(Vertx vertx, JsonObject contract,
94-
Map<String, JsonObject> additionalContractPartPaths) {
95+
Map<String, JsonObject> additionalContractParts) {
9596
return builder(vertx)
96-
.setContract(contract)
97-
.setAdditionalContractParts(additionalContractPartPaths)
98-
.build();
97+
.setContract(contract)
98+
.setAdditionalContractParts(additionalContractParts)
99+
.build();
99100

100101
}
101102

src/main/java/io/vertx/openapi/contract/OpenAPIContractBuilder.java

Lines changed: 46 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@
1111
*/
1212
package io.vertx.openapi.contract;
1313

14-
import static io.vertx.core.Future.failedFuture;
15-
import static io.vertx.openapi.contract.OpenAPIContractException.createInvalidContract;
16-
1714
import io.vertx.codegen.annotations.GenIgnore;
1815
import io.vertx.core.Future;
1916
import io.vertx.core.Promise;
@@ -24,13 +21,17 @@
2421
import io.vertx.json.schema.JsonSchemaValidationException;
2522
import io.vertx.openapi.contract.impl.OpenAPIContractImpl;
2623
import io.vertx.openapi.impl.Utils;
24+
2725
import java.util.HashMap;
2826
import java.util.Map;
2927
import java.util.stream.Collectors;
3028

29+
import static io.vertx.core.Future.failedFuture;
30+
import static io.vertx.openapi.contract.OpenAPIContractException.createInvalidContract;
31+
3132
/**
3233
* Builder for OpenAPIContracts.<br>
33-
*
34+
* <p>
3435
* In the simplest case (you only have one contract) you must either provide a path to your openapi-contract in json
3536
* or yaml format or an already parsed openapi-spec as a {@link JsonObject}.
3637
* See {@link OpenAPIContractBuilder#setContractPath(String)} and {@link OpenAPIContractBuilder#setContract(JsonObject)}.
@@ -89,8 +90,8 @@ public OpenAPIContractBuilder setContract(JsonObject contract) {
8990

9091
/**
9192
* Puts a contract that is referenced by the main contract. This method can be
92-
* called multiple times to add multiple referenced contracts. Overrides a previously
93-
* added contract when the same key is used.
93+
* called multiple times to add multiple referenced additional contract parts. Overrides a previously
94+
* added additional contract part when the same key is used.
9495
*
9596
* @param key The unique key for the contract.
9697
* @param path The path to the contract.
@@ -121,11 +122,11 @@ public OpenAPIContractBuilder setAdditionalContractPartPaths(Map<String, String>
121122
}
122123

123124
/**
124-
* Puts a contract that is referenced by the main contract. This method can be
125+
* Puts aa additional contract part that is referenced by the main contract. This method can be
125126
* called multiple times to add multiple referenced contracts.
126127
*
127128
* @param key The unique key for the contract.
128-
* @param contractPart The contract object.
129+
* @param contractPart The additional contract part.
129130
* @return The builder, for a fluent interface
130131
*/
131132
public OpenAPIContractBuilder putAdditionalContractPart(String key, JsonObject contractPart) {
@@ -135,9 +136,9 @@ public OpenAPIContractBuilder putAdditionalContractPart(String key, JsonObject c
135136
}
136137

137138
/**
138-
* Uses the contracts from the provided map to resolve referenced contracts.
139-
* Replaces all previously put contracts by {@link #putAdditionalContractPart(String, JsonObject)}.
140-
* If the same key is used also replaces the contracts set by {@link #putAdditionalContractPartPath(String, String)}
139+
* Uses the addtitional contract parts from the provided map to resolve referenced additional contract parts.
140+
* Replaces all previously put additional contract parts by {@link #putAdditionalContractPart(String, JsonObject)}.
141+
* If the same key is used also replaces the addtional contract part paths set by {@link #putAdditionalContractPartPath(String, String)}
141142
* and {@link #setAdditionalContractPartPaths(Map)}.
142143
*
143144
* @param contractParts A map that contains additional contract parts.
@@ -161,62 +162,62 @@ public Future<OpenAPIContract> build() {
161162

162163
if (contractPath == null && contract == null) {
163164
return Future.failedFuture(new OpenAPIContractBuilderException(
164-
"Neither a contract path or a contract is set. One of them must be set."));
165+
"Neither a contract path or a contract is set. One of them must be set."));
165166
}
166167

167168
Future<JsonObject> readContract = contractPath == null
168-
? Future.succeededFuture(contract)
169-
: Utils.readYamlOrJson(vertx, contractPath);
169+
? Future.succeededFuture(contract)
170+
: Utils.readYamlOrJson(vertx, contractPath);
170171

171172
var resolvedContractParts = readContractPaths()
172-
.map(r -> {
173-
var all = new HashMap<>(additionalContractParts);
174-
all.putAll(r);
175-
return all;
176-
});
173+
.map(r -> {
174+
var all = new HashMap<>(additionalContractParts);
175+
all.putAll(r);
176+
return all;
177+
});
177178

178179
return Future.all(readContract, resolvedContractParts)
179-
.compose(composite -> {
180-
JsonObject contract = composite.resultAt(0);
181-
Map<String, JsonObject> contractParts = composite.resultAt(1);
182-
return buildOpenAPIContract(contract, contractParts);
183-
});
180+
.compose(composite -> {
181+
JsonObject contract = composite.resultAt(0);
182+
Map<String, JsonObject> contractParts = composite.resultAt(1);
183+
return buildOpenAPIContract(contract, contractParts);
184+
});
184185
}
185186

186187
private Future<OpenAPIContract> buildOpenAPIContract(JsonObject resolvedContract,
187-
Map<String, JsonObject> additionalContractParts) {
188+
Map<String, JsonObject> additionalContractParts) {
188189
OpenAPIVersion version = OpenAPIVersion.fromContract(resolvedContract);
189190
String baseUri = "app://";
190191

191192
ContextInternal ctx = (ContextInternal) vertx.getOrCreateContext();
192193
Promise<OpenAPIContract> promise = ctx.promise();
193194

194195
version.getRepository(vertx, baseUri)
195-
.compose(repository -> {
196-
var validationFutures = additionalContractParts.entrySet()
197-
.stream()
198-
.map(entry -> version.validateAdditionalContractPart(vertx, repository, entry.getValue())
199-
.compose(v -> vertx.executeBlocking(
200-
() -> repository.dereference(entry.getKey(), JsonSchema.of(entry.getKey(), entry.getValue())))))
201-
.collect(Collectors.toList());
202-
return Future.all(validationFutures).map(repository);
203-
}).compose(repository -> version.validateContract(vertx, repository, resolvedContract).compose(res -> {
196+
.compose(repository -> {
197+
var validationFutures = additionalContractParts.entrySet()
198+
.stream()
199+
.map(entry -> version.validateAdditionalContractPart(vertx, repository, entry.getValue())
200+
.compose(v -> vertx.executeBlocking(
201+
() -> repository.dereference(entry.getKey(), JsonSchema.of(entry.getKey(), entry.getValue())))))
202+
.collect(Collectors.toList());
203+
return Future.all(validationFutures).map(repository);
204+
}).compose(repository -> version.validateContract(vertx, repository, resolvedContract).compose(res -> {
204205
try {
205206
res.checkValidity();
206207
return version.resolve(vertx, repository, resolvedContract);
207208
} catch (JsonSchemaValidationException | UnsupportedOperationException e) {
208209
return failedFuture(createInvalidContract(null, e));
209210
}
210211
})
211-
.map(resolvedSpec -> new OpenAPIContractImpl(resolvedSpec, version, repository)))
212-
.recover(e -> {
213-
// Convert any non-openapi exceptions into an OpenAPIContractException
214-
if (e instanceof OpenAPIContractException) {
215-
return failedFuture(e);
216-
}
217-
return failedFuture(
218-
createInvalidContract("Found issue in specification for reference: " + e.getMessage(), e));
219-
}).onComplete(promise);
212+
.map(resolvedSpec -> new OpenAPIContractImpl(resolvedSpec, version, repository)))
213+
.recover(e -> {
214+
// Convert any non-openapi exceptions into an OpenAPIContractException
215+
if (e instanceof OpenAPIContractException) {
216+
return failedFuture(e);
217+
}
218+
return failedFuture(
219+
createInvalidContract("Found issue in specification for reference: " + e.getMessage(), e));
220+
}).onComplete(promise);
220221

221222
return promise.future();
222223
}
@@ -228,9 +229,9 @@ private Future<Map<String, JsonObject>> readContractPaths() {
228229
var read = new HashMap<String, JsonObject>();
229230
return Future.all(additionalContractPartPaths.entrySet().stream()
230231
.map(e -> Utils.readYamlOrJson(vertx, e.getValue())
231-
.map(c -> read.put(e.getKey(), c)))
232+
.map(c -> read.put(e.getKey(), c)))
232233
.collect(Collectors.toList()))
233-
.map(ign -> read);
234+
.map(ign -> read);
234235
}
235236

236237
}

0 commit comments

Comments
 (0)