Skip to content

Commit fdf1072

Browse files
committed
Report incompatibilities in HTML also
1 parent 4af1e6f commit fdf1072

File tree

1 file changed

+59
-3
lines changed

1 file changed

+59
-3
lines changed

src/main/java/com/qdesrame/openapi/diff/output/HtmlRender.java

Lines changed: 59 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -214,16 +214,72 @@ private ContainerTag li_missingRequest(String name, MediaType request) {
214214
}
215215

216216
private ContainerTag li_changedRequest(String name, ChangedMediaType request) {
217-
return li().withText(String.format("Changed body: '%s'", name))
218-
.with(div_changedSchema(request.getSchema()));
217+
ContainerTag li =
218+
li().with(div_changedSchema(request.getSchema()))
219+
.withText(String.format("Changed body: '%s'", name));
220+
if (request.isIncompatible()) {
221+
li = incompatibility(li, request, "");
222+
}
223+
return li;
219224
}
220225

221226
private ContainerTag div_changedSchema(ChangedSchema schema) {
222227
ContainerTag div = div();
223-
div.with(h3("Schema"));
228+
div.with(h3("Schema" + (schema.isIncompatible() ? " incompatible" : "")));
224229
return div;
225230
}
226231

232+
private ContainerTag incompatibility(
233+
final ContainerTag output, final ComposedChanged changed, final String propPrefix) {
234+
if (changed.isCoreChanged() == DiffResult.INCOMPATIBLE) {
235+
if (changed instanceof ChangedSchema) {
236+
ChangedSchema cs = (ChangedSchema) changed;
237+
238+
cs.getMissingProperties().keySet().stream()
239+
.forEach(
240+
(propName) -> {
241+
output.with(
242+
p(String.format(
243+
"Missing property: %s%s%s",
244+
propPrefix, propPrefix.isEmpty() ? "" : ".", propName))
245+
.withClass("missing"));
246+
});
247+
248+
if (cs.isChangedType()) {
249+
output.with(p("Changed property type: " + propPrefix).withClass("missing"));
250+
}
251+
}
252+
}
253+
254+
if (changed instanceof ChangedSchema) {
255+
ChangedSchema cs = (ChangedSchema) changed;
256+
257+
String description = null;
258+
if (!cs.getChangedProperties().isEmpty()) {
259+
cs.getChangedProperties().entrySet().stream()
260+
.forEach(
261+
(entry) -> {
262+
incompatibility(
263+
output,
264+
entry.getValue(),
265+
propPrefix + (propPrefix.isEmpty() ? "" : ".") + entry.getKey());
266+
});
267+
} else if (cs.getItems() != null) {
268+
incompatibility(output, cs.getItems(), propPrefix + "[n]");
269+
}
270+
271+
return output;
272+
}
273+
274+
for (Changed child : changed.getChangedElements()) {
275+
if (child instanceof ComposedChanged) {
276+
incompatibility(output, (ComposedChanged) child, "");
277+
}
278+
}
279+
280+
return output;
281+
}
282+
227283
private ContainerTag ul_param(ChangedParameters changedParameters) {
228284
List<Parameter> addParameters = changedParameters.getIncreased();
229285
List<Parameter> delParameters = changedParameters.getMissing();

0 commit comments

Comments
 (0)