Skip to content

Commit 36fcf38

Browse files
committed
next implementation cycle
additional test coverage
1 parent dd1eaf7 commit 36fcf38

File tree

4 files changed

+109
-2
lines changed

4 files changed

+109
-2
lines changed

‎pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
<groupId>com.amartus.sonata</groupId>
2626
<artifactId>blender</artifactId>
2727
<description>SonataBlendingTool</description>
28-
<version>1.11.0</version>
28+
<version>1.11.1-SNAPSHOT</version>
2929
<properties>
3030
<openapi.generator.version>6.2.0</openapi.generator.version>
3131
<jackson.version>2.14.2</jackson.version>

‎src/test/java/com/amartus/sonata/blender/impl/ValidateSpecificationTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ private void log(Collection<ValidationMessage> msgs) {
265265
.map(ValidationMessage::getMessage)
266266
.collect(Collectors.joining("\n"));
267267
if (!msgs.isEmpty()) {
268-
log.warn("Validaiton issues:\n{}\n", msg);
268+
log.warn("Validation issues:\n{}\n", msg);
269269
}
270270
}
271271

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
package com.amartus.sonata.blender.impl.postprocess;
2+
3+
import com.amartus.sonata.blender.impl.util.OasUtils;
4+
import io.swagger.v3.oas.models.OpenAPI;
5+
import io.swagger.v3.oas.models.media.Schema;
6+
import org.assertj.core.api.Assertions;
7+
import org.assertj.core.api.Condition;
8+
import org.junit.jupiter.api.BeforeEach;
9+
import org.junit.jupiter.api.Test;
10+
11+
import java.util.ArrayList;
12+
import java.util.List;
13+
import java.util.Map;
14+
15+
import static org.apache.commons.collections4.IterableUtils.isEmpty;
16+
17+
18+
class SortTypesByNameTest {
19+
private OpenAPI oas;
20+
21+
@BeforeEach
22+
public void readOas() {
23+
var uri = SortTypesByNameTest.class.getResource("/ref-model/unsorted.yaml");
24+
assert uri != null;
25+
oas = OasUtils.readOas(uri.toString());
26+
}
27+
@Test
28+
public void typesAreSorted() {
29+
Assertions.assertThat(schemaNames(oas)).is(new Condition<>(this::notSorted, "not sorted"));
30+
new SortTypesByName().accept(oas);
31+
Assertions.assertThat(schemaNames(oas)).isSorted();
32+
}
33+
34+
@Test
35+
public void propertiesAreNotSorted() {
36+
var schema = oas.getComponents().getSchemas().get("B");
37+
List<String> keysBefore = schemaKeys(schema.getProperties());
38+
new SortTypesByName().accept(oas);
39+
schema = oas.getComponents().getSchemas().get("B");
40+
List<String> keysAfter = schemaKeys(schema.getProperties());
41+
Assertions.assertThat(keysAfter)
42+
.is(new Condition<>(this::notSorted, "not sorted"))
43+
.isEqualTo(keysBefore);
44+
}
45+
46+
private <T extends Comparable<T>> boolean notSorted(List<? extends T> list) {
47+
if (isEmpty(list) || list.size() == 1) {
48+
return false;
49+
}
50+
51+
var iter = list.iterator();
52+
T current, previous = iter.next();
53+
while (iter.hasNext()) {
54+
current = iter.next();
55+
if (previous.compareTo(current) > 0) {
56+
return true;
57+
}
58+
previous = current;
59+
}
60+
return false;
61+
}
62+
63+
private static List<String> schemaNames(OpenAPI oas) {
64+
return schemaKeys(oas.getComponents().getSchemas());
65+
}
66+
private static List<String> schemaKeys(Map<String, Schema> schema) {
67+
return new ArrayList<>(schema.keySet());
68+
}
69+
}
+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
openapi: "3.0.2"
2+
info:
3+
title: API Title
4+
version: "1.0"
5+
servers:
6+
- url: https://api.server.test/v1
7+
paths:
8+
/example:
9+
get:
10+
responses:
11+
"200":
12+
description: "example"
13+
content:
14+
default:
15+
schema:
16+
$ref: "#/components/schemas/B"
17+
components:
18+
schemas:
19+
B:
20+
type: object
21+
properties:
22+
d:
23+
$ref: "external.json"
24+
a:
25+
type: string
26+
b:
27+
$ref: "#/components/schemas/A"
28+
c:
29+
$ref: "#/components/schemas/A"
30+
e:
31+
$ref: "./specific/specific.json"
32+
A:
33+
type: object
34+
properties:
35+
y:
36+
type: string
37+
x:
38+
type: string

0 commit comments

Comments
 (0)