Skip to content

Commit 2b1ce9d

Browse files
committed
openapi test: fix random output while producing yaml for server variables
1 parent 72a24b8 commit 2b1ce9d

2 files changed

Lines changed: 88 additions & 7 deletions

File tree

modules/jooby-openapi/src/test/java/io/jooby/openapi/OpenAPIExtension.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,8 @@
1616
import java.util.Optional;
1717
import java.util.Set;
1818

19-
import static java.util.Objects.requireNonNull;
20-
2119
public class OpenAPIExtension implements ParameterResolver, AfterEachCallback {
20+
2221
@Override public boolean supportsParameter(ParameterContext parameterContext,
2322
ExtensionContext extensionContext) throws ParameterResolutionException {
2423
Parameter parameter = parameterContext.getParameter();

modules/jooby-openapi/src/test/java/issues/Issue1601.java

Lines changed: 87 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
import issues.i1601.App1601;
66
import issues.i1601.App1601b;
77

8-
import static org.junit.jupiter.api.Assertions.assertEquals;
8+
import static org.junit.jupiter.api.Assertions.assertTrue;
99

1010
public class Issue1601 {
1111

1212
@OpenAPITest(value = App1601.class)
1313
public void shouldParseOpenAPIDefinition(OpenAPIResult result) {
14-
assertEquals("openapi: 3.0.1\n"
14+
String yaml1 = "openapi: 3.0.1\n"
1515
+ "info:\n"
1616
+ " title: Title\n"
1717
+ " description: description\n"
@@ -49,12 +49,53 @@ public void shouldParseOpenAPIDefinition(OpenAPIResult result) {
4949
+ " content:\n"
5050
+ " application/json:\n"
5151
+ " schema:\n"
52-
+ " type: string\n", result.toYaml());
52+
+ " type: string\n";
53+
String yaml2 = "openapi: 3.0.1\n"
54+
+ "info:\n"
55+
+ " title: Title\n"
56+
+ " description: description\n"
57+
+ " termsOfService: Terms\n"
58+
+ " contact:\n"
59+
+ " name: Jooby\n"
60+
+ " url: https://jooby.io\n"
61+
+ " email: support@jooby.io\n"
62+
+ " license:\n"
63+
+ " name: Apache\n"
64+
+ " url: https://jooby.io/LICENSE\n"
65+
+ " version: \"10\"\n"
66+
+ "servers:\n"
67+
+ "- url: serverurl\n"
68+
+ " description: '...'\n"
69+
+ " variables:\n"
70+
+ " env:\n"
71+
+ " description: environment\n"
72+
+ " enum:\n"
73+
+ " - stage\n"
74+
+ " - prod\n"
75+
+ " default: dev\n"
76+
+ "security:\n"
77+
+ "- oauth:\n"
78+
+ " - read:write\n"
79+
+ "tags:\n"
80+
+ "- name: mytag\n"
81+
+ "paths:\n"
82+
+ " /1601:\n"
83+
+ " get:\n"
84+
+ " operationId: get1601\n"
85+
+ " responses:\n"
86+
+ " \"200\":\n"
87+
+ " description: Success\n"
88+
+ " content:\n"
89+
+ " application/json:\n"
90+
+ " schema:\n"
91+
+ " type: string\n";
92+
String output = result.toYaml();
93+
assertTrue(output.equals(yaml1) || output.equals(yaml2));
5394
}
5495

5596
@OpenAPITest(value = App1601b.class)
5697
public void shouldParseOpenAPIDefinitionController(OpenAPIResult result) {
57-
assertEquals("openapi: 3.0.1\n"
98+
String yaml1 = "openapi: 3.0.1\n"
5899
+ "info:\n"
59100
+ " title: Title\n"
60101
+ " description: description\n"
@@ -92,6 +133,47 @@ public void shouldParseOpenAPIDefinitionController(OpenAPIResult result) {
92133
+ " content:\n"
93134
+ " application/json:\n"
94135
+ " schema:\n"
95-
+ " type: string\n", result.toYaml());
136+
+ " type: string\n";
137+
String yaml2 = "openapi: 3.0.1\n"
138+
+ "info:\n"
139+
+ " title: Title\n"
140+
+ " description: description\n"
141+
+ " termsOfService: Terms\n"
142+
+ " contact:\n"
143+
+ " name: Jooby\n"
144+
+ " url: https://jooby.io\n"
145+
+ " email: support@jooby.io\n"
146+
+ " license:\n"
147+
+ " name: Apache\n"
148+
+ " url: https://jooby.io/LICENSE\n"
149+
+ " version: \"10\"\n"
150+
+ "servers:\n"
151+
+ "- url: serverurl\n"
152+
+ " description: '...'\n"
153+
+ " variables:\n"
154+
+ " env:\n"
155+
+ " description: environment\n"
156+
+ " enum:\n"
157+
+ " - stage\n"
158+
+ " - prod\n"
159+
+ " default: dev\n"
160+
+ "security:\n"
161+
+ "- oauth:\n"
162+
+ " - read:write\n"
163+
+ "tags:\n"
164+
+ "- name: mytag\n"
165+
+ "paths:\n"
166+
+ " /1601:\n"
167+
+ " get:\n"
168+
+ " operationId: doSomething\n"
169+
+ " responses:\n"
170+
+ " \"200\":\n"
171+
+ " description: Success\n"
172+
+ " content:\n"
173+
+ " application/json:\n"
174+
+ " schema:\n"
175+
+ " type: string\n";
176+
String output = result.toYaml();
177+
assertTrue(output.equals(yaml1) || output.equals(yaml2));
96178
}
97179
}

0 commit comments

Comments
 (0)