Skip to content

Commit e5f7312

Browse files
K5qu4r3dewaostrowska
authored andcommitted
test: add test cases for updated OpenAPI 3.1 "type"/"types" value schemas
1 parent dfbbc62 commit e5f7312

File tree

2 files changed

+371
-0
lines changed

2 files changed

+371
-0
lines changed
Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
package io.swagger.v3.jaxrs2;
2+
3+
import io.swagger.v3.jaxrs2.resources.APIResponsesResource;
4+
import io.swagger.v3.oas.integration.SwaggerConfiguration;
5+
import io.swagger.v3.oas.models.OpenAPI;
6+
import io.swagger.v3.oas.models.Operation;
7+
import io.swagger.v3.oas.models.media.Schema;
8+
import org.testng.annotations.BeforeMethod;
9+
import org.testng.annotations.Test;
10+
11+
import static org.testng.AssertJUnit.assertEquals;
12+
13+
public class APIResponsesResourceTest {
14+
private OpenAPI openAPI;
15+
16+
@BeforeMethod
17+
public void setUp() {
18+
SwaggerConfiguration config = new SwaggerConfiguration().openAPI31(true);
19+
Reader reader = new Reader(config);
20+
openAPI = reader.read(APIResponsesResource.class);
21+
}
22+
23+
private Schema getResponseSchema(String path) {
24+
Operation postOperation = openAPI.getPaths().get(path).getPost();
25+
return postOperation.getResponses().get("200").getContent().get("*/*").getSchema();
26+
}
27+
28+
@Test
29+
public void testStringOrEmailSchemaAPIResource31() {
30+
Schema responseSchema = getResponseSchema("/postStringOrEmailSchemaContent");
31+
32+
// Value of field "type" must equal value of field "types"
33+
assertEquals(responseSchema.getType(), responseSchema.getTypes().iterator().next());
34+
}
35+
36+
@Test
37+
public void testBooleanSchemaAPIResource31() {
38+
Schema responseSchema = getResponseSchema("/postBooleanSchemaContent");
39+
40+
// Value of field "type" must equal value of field "types"
41+
assertEquals(responseSchema.getType(), responseSchema.getTypes().iterator().next());
42+
}
43+
44+
@Test
45+
public void testByteOrBinarySchemaAPIResource31() {
46+
Schema responseSchema = getResponseSchema("/postByteOrBinarySchemaContent");
47+
48+
// Value of field "type" must equal value of field "types"
49+
assertEquals(responseSchema.getType(), responseSchema.getTypes().iterator().next());
50+
}
51+
52+
@Test
53+
public void testURISchemaAPIResource31() {
54+
Schema responseSchema = getResponseSchema("/postURISchemaContent");
55+
56+
// Value of field "type" must equal value of field "types"
57+
assertEquals(responseSchema.getType(), responseSchema.getTypes().iterator().next());
58+
}
59+
60+
@Test
61+
public void testURLSchemaAPIResource31() {
62+
Schema responseSchema = getResponseSchema("/postURLSchemaContent");
63+
64+
// Value of field "type" must equal value of field "types"
65+
assertEquals(responseSchema.getType(), responseSchema.getTypes().iterator().next());
66+
}
67+
68+
@Test
69+
public void testUUIDSchemaAPIResource31() {
70+
Schema responseSchema = getResponseSchema("/postUUIDSchemaContent");
71+
72+
// Value of field "type" must equal value of field "types"
73+
assertEquals(responseSchema.getType(), responseSchema.getTypes().iterator().next());
74+
}
75+
76+
@Test
77+
public void testIntegerSchemaAPIResource31() {
78+
Schema responseSchema = getResponseSchema("/postIntegerSchemaContent");
79+
80+
// Value of field "type" must equal value of field "types"
81+
assertEquals(responseSchema.getType(), responseSchema.getTypes().iterator().next());
82+
}
83+
84+
@Test
85+
public void testLongSchemaAPIResource31() {
86+
Schema responseSchema = getResponseSchema("/postLongSchemaContent");
87+
88+
// Value of field "type" must equal value of field "types"
89+
assertEquals(responseSchema.getType(), responseSchema.getTypes().iterator().next());
90+
}
91+
92+
@Test
93+
public void testFloatSchemaAPIResource31() {
94+
Schema responseSchema = getResponseSchema("/postFloatSchemaContent");
95+
96+
// Value of field "type" must equal value of field "types"
97+
assertEquals(responseSchema.getType(), responseSchema.getTypes().iterator().next());
98+
}
99+
100+
@Test
101+
public void testDoubleSchemaAPIResource31() {
102+
Schema responseSchema = getResponseSchema("/postDoubleSchemaContent");
103+
104+
// Value of field "type" must equal value of field "types"
105+
assertEquals(responseSchema.getType(), responseSchema.getTypes().iterator().next());
106+
}
107+
108+
@Test
109+
public void testBigIntegerSchemaAPIResource31() {
110+
Schema responseSchema = getResponseSchema("/postBigIntegerSchemaContent");
111+
112+
// Value of field "type" must equal value of field "types"
113+
assertEquals(responseSchema.getType(), responseSchema.getTypes().iterator().next());
114+
}
115+
116+
@Test
117+
public void testBigDecimalSchemaAPIResource31() {
118+
Schema responseSchema = getResponseSchema("/postBigDecimalSchemaContent");
119+
120+
// Value of field "type" must equal value of field "types"
121+
assertEquals(responseSchema.getType(), responseSchema.getTypes().iterator().next());
122+
}
123+
124+
@Test
125+
public void testNumberSchemaAPIResource31() {
126+
Schema responseSchema = getResponseSchema("/postNumberSchemaContent");
127+
128+
// Value of field "type" must equal value of field "types"
129+
assertEquals(responseSchema.getType(), responseSchema.getTypes().iterator().next());
130+
}
131+
132+
@Test
133+
public void testDateStubSchemaAPIResource31() {
134+
Schema responseSchema = getResponseSchema("/postDateStubSchemaContent");
135+
136+
// Value of field "type" must equal value of field "types"
137+
assertEquals(responseSchema.getType(), responseSchema.getTypes().iterator().next());
138+
}
139+
140+
@Test
141+
public void testDateSchemaAPIResource31() {
142+
Schema responseSchema = getResponseSchema("/postDateSchemaContent");
143+
144+
// Value of field "type" must equal value of field "types"
145+
assertEquals(responseSchema.getType(), responseSchema.getTypes().iterator().next());
146+
}
147+
148+
@Test
149+
public void testLocalTimeSchemaAPIResource31() {
150+
Schema responseSchema = getResponseSchema("/postLocalTimeSchemaContent");
151+
152+
// Value of field "type" must equal value of field "types"
153+
assertEquals(responseSchema.getType(), responseSchema.getTypes().iterator().next());
154+
}
155+
156+
@Test
157+
public void testFileSchemaAPIResource31() {
158+
Schema responseSchema = getResponseSchema("/postFileSchemaContent");
159+
160+
// Value of field "type" must equal value of field "types"
161+
assertEquals(responseSchema.getType(), responseSchema.getTypes().iterator().next());
162+
}
163+
164+
@Test
165+
public void testObjectSchemaAPIResource31() {
166+
Schema responseSchema = getResponseSchema("/postObjectSchemaContent");
167+
168+
// Value of field "type" must equal value of field "types"
169+
assertEquals(responseSchema.getType(), responseSchema.getTypes().iterator().next());
170+
}
171+
}
Lines changed: 200 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
1+
package io.swagger.v3.jaxrs2.resources;
2+
3+
import io.swagger.v3.core.util.PrimitiveType;
4+
import io.swagger.v3.oas.annotations.media.Content;
5+
import io.swagger.v3.oas.annotations.media.Schema;
6+
import io.swagger.v3.oas.annotations.responses.ApiResponse;
7+
import io.swagger.v3.oas.annotations.responses.ApiResponses;
8+
9+
import javax.ws.rs.POST;
10+
import javax.ws.rs.Path;
11+
import java.io.File;
12+
import java.math.BigDecimal;
13+
import java.math.BigInteger;
14+
import java.net.URI;
15+
import java.net.URL;
16+
import java.time.LocalTime;
17+
import java.util.Date;
18+
import java.util.UUID;
19+
20+
public class APIResponsesResource {
21+
@POST
22+
@Path("postStringOrEmailSchemaContent")
23+
@ApiResponses({
24+
@ApiResponse(
25+
responseCode = "200",
26+
content = @Content(schema = @Schema(implementation = String.class))
27+
)
28+
})
29+
public void postStringOrEmailSchemaContent() { }
30+
31+
@POST
32+
@Path("postBooleanSchemaContent")
33+
@ApiResponses({
34+
@ApiResponse(
35+
responseCode = "200",
36+
content = @Content(schema = @Schema(implementation = Boolean.class))
37+
)
38+
})
39+
public void postBooleanSchemaContent() { }
40+
41+
@POST
42+
@Path("postByteOrBinarySchemaContent")
43+
@ApiResponses({
44+
@ApiResponse(
45+
responseCode = "200",
46+
content = @Content(schema = @Schema(implementation = Byte.class))
47+
)
48+
})
49+
public void postByteOrBinarySchemaContent() { }
50+
51+
@POST
52+
@Path("postURISchemaContent")
53+
@ApiResponses({
54+
@ApiResponse(
55+
responseCode = "200",
56+
content = @Content(schema = @Schema(implementation = URI.class))
57+
)
58+
})
59+
public void postURISchemaContent() { }
60+
61+
@POST
62+
@Path("postURLSchemaContent")
63+
@ApiResponses({
64+
@ApiResponse(
65+
responseCode = "200",
66+
content = @Content(schema = @Schema(implementation = URL.class))
67+
)
68+
})
69+
public void postURLSchemaContent() { }
70+
71+
@POST
72+
@Path("postUUIDSchemaContent")
73+
@ApiResponses({
74+
@ApiResponse(
75+
responseCode = "200",
76+
content = @Content(schema = @Schema(implementation = UUID.class))
77+
)
78+
})
79+
public void postUUIDSchemaContent() { }
80+
81+
@POST
82+
@Path("postIntegerSchemaContent")
83+
@ApiResponses({
84+
@ApiResponse(
85+
responseCode = "200",
86+
content = @Content(schema = @Schema(implementation = Integer.class))
87+
)
88+
})
89+
public void postIntegerSchemaContent() { }
90+
91+
@POST
92+
@Path("postLongSchemaContent")
93+
@ApiResponses({
94+
@ApiResponse(
95+
responseCode = "200",
96+
content = @Content(schema = @Schema(implementation = Long.class))
97+
)
98+
})
99+
public void postLongSchemaContent() { }
100+
101+
@POST
102+
@Path("postFloatSchemaContent")
103+
@ApiResponses({
104+
@ApiResponse(
105+
responseCode = "200",
106+
content = @Content(schema = @Schema(implementation = Float.class))
107+
)
108+
})
109+
public void postFloatSchemaContent() { }
110+
111+
@POST
112+
@Path("postDoubleSchemaContent")
113+
@ApiResponses({
114+
@ApiResponse(
115+
responseCode = "200",
116+
content = @Content(schema = @Schema(implementation = Double.class))
117+
)
118+
})
119+
public void postDoubleSchemaContent() { }
120+
121+
@POST
122+
@Path("postBigIntegerSchemaContent")
123+
@ApiResponses({
124+
@ApiResponse(
125+
responseCode = "200",
126+
content = @Content(schema = @Schema(implementation = BigInteger.class))
127+
)
128+
})
129+
public void postBigIntegerSchemaContent() { }
130+
131+
@POST
132+
@Path("postBigDecimalSchemaContent")
133+
@ApiResponses({
134+
@ApiResponse(
135+
responseCode = "200",
136+
content = @Content(schema = @Schema(implementation = BigDecimal.class))
137+
)
138+
})
139+
public void postBigDecimalSchemaContent() { }
140+
141+
@POST
142+
@Path("postNumberSchemaContent")
143+
@ApiResponses({
144+
@ApiResponse(
145+
responseCode = "200",
146+
content = @Content(schema = @Schema(implementation = Number.class))
147+
)
148+
})
149+
public void postNumberSchemaContent() { }
150+
151+
@POST
152+
@Path("postDateStubSchemaContent")
153+
@ApiResponses({
154+
@ApiResponse(
155+
responseCode = "200",
156+
content = @Content(schema = @Schema(implementation = PrimitiveType.DateStub.class))
157+
)
158+
})
159+
public void postDateStubSchemaContent() { }
160+
161+
@POST
162+
@Path("postDateSchemaContent")
163+
@ApiResponses({
164+
@ApiResponse(
165+
responseCode = "200",
166+
content = @Content(schema = @Schema(implementation = Date.class))
167+
)
168+
})
169+
public void postDateSchemaContent() { }
170+
171+
@POST
172+
@Path("postLocalTimeSchemaContent")
173+
@ApiResponses({
174+
@ApiResponse(
175+
responseCode = "200",
176+
content = @Content(schema = @Schema(implementation = LocalTime.class))
177+
)
178+
})
179+
public void postLocalTimeSchemaContent() { }
180+
181+
@POST
182+
@Path("postFileSchemaContent")
183+
@ApiResponses({
184+
@ApiResponse(
185+
responseCode = "200",
186+
content = @Content(schema = @Schema(implementation = File.class))
187+
)
188+
})
189+
public void postFileSchemaContent() { }
190+
191+
@POST
192+
@Path("postObjectSchemaContent")
193+
@ApiResponses({
194+
@ApiResponse(
195+
responseCode = "200",
196+
content = @Content(schema = @Schema(implementation = Object.class))
197+
)
198+
})
199+
public void postObjectSchemaContent() { }
200+
}

0 commit comments

Comments
 (0)