Skip to content

Commit a839203

Browse files
jminiwing328
authored andcommitted
[java][client][restassured] add getAllOperations() (#4631)
* [java][client][restassured] add getAllOperations() * Update samples
1 parent 3626aaf commit a839203

10 files changed

Lines changed: 184 additions & 38 deletions

File tree

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaClientCodegen.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,7 @@ public void processOpts() {
380380
supportingFiles.add(new SupportingFile("JSON.mustache", invokerFolder, "JSON.java"));
381381
supportingFiles.add(new SupportingFile("GsonObjectMapper.mustache", invokerFolder, "GsonObjectMapper.java"));
382382
}
383+
supportingFiles.add(new SupportingFile("Oper.mustache", apiFolder, "Oper.java"));
383384
additionalProperties.put("convert", new CaseFormatLambda(LOWER_CAMEL, UPPER_UNDERSCORE));
384385
apiTemplateFiles.put("api.mustache", ".java");
385386
supportingFiles.add(new SupportingFile("ResponseSpecBuilders.mustache", invokerFolder, "ResponseSpecBuilders.java"));
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{{>licenseInfo}}
2+
3+
package {{apiPackage}};
4+
5+
import io.restassured.response.Response;
6+
7+
import java.util.function.Function;
8+
9+
public interface Oper {
10+
11+
<T> T execute(Function<Response, T> handler);
12+
13+
}

modules/openapi-generator/src/main/resources/Java/libraries/rest-assured/api.mustache

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,15 @@ public class {{classname}} {
5656
return reqSpec;
5757
}
5858

59+
public List<Oper> getAllOperations() {
60+
return Arrays.asList(
61+
{{#operations}}
62+
{{#operation}}
63+
{{operationId}}(){{^-last}},{{/-last}}
64+
{{/operation}}
65+
{{/operations}}
66+
);
67+
}
5968
{{#operations}}
6069
{{#operation}}
6170

@@ -107,7 +116,7 @@ public class {{classname}} {
107116
{{#isDeprecated}}
108117
@Deprecated
109118
{{/isDeprecated}}
110-
public static class {{operationIdCamelCase}}Oper {
119+
public static class {{operationIdCamelCase}}Oper implements Oper {
111120
112121
public static final Method REQ_METHOD = {{httpMethod}};
113122
public static final String REQ_URI = "{{path}}";
@@ -134,6 +143,7 @@ public class {{classname}} {
134143
* @param <T> type
135144
* @return type
136145
*/
146+
@Override
137147
public <T> T execute(Function<Response, T> handler) {
138148
return handler.apply(RestAssured.given().spec(reqSpec.build()).expect().spec(respSpec.build()).when().request(REQ_METHOD, REQ_URI));
139149
}

samples/client/petstore/java/rest-assured/src/main/java/org/openapitools/client/api/AnotherFakeApi.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ private RequestSpecBuilder createReqSpec() {
5757
return reqSpec;
5858
}
5959

60+
public List<Oper> getAllOperations() {
61+
return Arrays.asList(
62+
call123testSpecialTags()
63+
);
64+
}
6065

6166
@ApiOperation(value = "To test special tags",
6267
notes = "To test special tags and operation ID starting with number",
@@ -85,7 +90,7 @@ public AnotherFakeApi reqSpec(Consumer<RequestSpecBuilder> reqSpecCustomizer) {
8590
* @see #body client model (required)
8691
* return Client
8792
*/
88-
public static class Call123testSpecialTagsOper {
93+
public static class Call123testSpecialTagsOper implements Oper {
8994

9095
public static final Method REQ_METHOD = PATCH;
9196
public static final String REQ_URI = "/another-fake/dummy";
@@ -106,6 +111,7 @@ public Call123testSpecialTagsOper(RequestSpecBuilder reqSpec) {
106111
* @param <T> type
107112
* @return type
108113
*/
114+
@Override
109115
public <T> T execute(Function<Response, T> handler) {
110116
return handler.apply(RestAssured.given().spec(reqSpec.build()).expect().spec(respSpec.build()).when().request(REQ_METHOD, REQ_URI));
111117
}

samples/client/petstore/java/rest-assured/src/main/java/org/openapitools/client/api/FakeApi.java

Lines changed: 46 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,24 @@ private RequestSpecBuilder createReqSpec() {
6565
return reqSpec;
6666
}
6767

68+
public List<Oper> getAllOperations() {
69+
return Arrays.asList(
70+
createXmlItem(),
71+
fakeOuterBooleanSerialize(),
72+
fakeOuterCompositeSerialize(),
73+
fakeOuterNumberSerialize(),
74+
fakeOuterStringSerialize(),
75+
testBodyWithFileSchema(),
76+
testBodyWithQueryParams(),
77+
testClientModel(),
78+
testEndpointParameters(),
79+
testEnumParameters(),
80+
testGroupParameters(),
81+
testInlineAdditionalProperties(),
82+
testJsonFormData(),
83+
testQueryParameterCollectionFormat()
84+
);
85+
}
6886

6987
@ApiOperation(value = "creates an XmlItem",
7088
notes = "this route creates an XmlItem",
@@ -224,7 +242,7 @@ public FakeApi reqSpec(Consumer<RequestSpecBuilder> reqSpecCustomizer) {
224242
*
225243
* @see #body XmlItem Body (required)
226244
*/
227-
public static class CreateXmlItemOper {
245+
public static class CreateXmlItemOper implements Oper {
228246

229247
public static final Method REQ_METHOD = POST;
230248
public static final String REQ_URI = "/fake/create_xml_item";
@@ -245,6 +263,7 @@ public CreateXmlItemOper(RequestSpecBuilder reqSpec) {
245263
* @param <T> type
246264
* @return type
247265
*/
266+
@Override
248267
public <T> T execute(Function<Response, T> handler) {
249268
return handler.apply(RestAssured.given().spec(reqSpec.build()).expect().spec(respSpec.build()).when().request(REQ_METHOD, REQ_URI));
250269
}
@@ -285,7 +304,7 @@ public CreateXmlItemOper respSpec(Consumer<ResponseSpecBuilder> respSpecCustomiz
285304
* @see #body Input boolean as post body (optional)
286305
* return Boolean
287306
*/
288-
public static class FakeOuterBooleanSerializeOper {
307+
public static class FakeOuterBooleanSerializeOper implements Oper {
289308

290309
public static final Method REQ_METHOD = POST;
291310
public static final String REQ_URI = "/fake/outer/boolean";
@@ -306,6 +325,7 @@ public FakeOuterBooleanSerializeOper(RequestSpecBuilder reqSpec) {
306325
* @param <T> type
307326
* @return type
308327
*/
328+
@Override
309329
public <T> T execute(Function<Response, T> handler) {
310330
return handler.apply(RestAssured.given().spec(reqSpec.build()).expect().spec(respSpec.build()).when().request(REQ_METHOD, REQ_URI));
311331
}
@@ -356,7 +376,7 @@ public FakeOuterBooleanSerializeOper respSpec(Consumer<ResponseSpecBuilder> resp
356376
* @see #body Input composite as post body (optional)
357377
* return OuterComposite
358378
*/
359-
public static class FakeOuterCompositeSerializeOper {
379+
public static class FakeOuterCompositeSerializeOper implements Oper {
360380

361381
public static final Method REQ_METHOD = POST;
362382
public static final String REQ_URI = "/fake/outer/composite";
@@ -377,6 +397,7 @@ public FakeOuterCompositeSerializeOper(RequestSpecBuilder reqSpec) {
377397
* @param <T> type
378398
* @return type
379399
*/
400+
@Override
380401
public <T> T execute(Function<Response, T> handler) {
381402
return handler.apply(RestAssured.given().spec(reqSpec.build()).expect().spec(respSpec.build()).when().request(REQ_METHOD, REQ_URI));
382403
}
@@ -427,7 +448,7 @@ public FakeOuterCompositeSerializeOper respSpec(Consumer<ResponseSpecBuilder> re
427448
* @see #body Input number as post body (optional)
428449
* return BigDecimal
429450
*/
430-
public static class FakeOuterNumberSerializeOper {
451+
public static class FakeOuterNumberSerializeOper implements Oper {
431452

432453
public static final Method REQ_METHOD = POST;
433454
public static final String REQ_URI = "/fake/outer/number";
@@ -448,6 +469,7 @@ public FakeOuterNumberSerializeOper(RequestSpecBuilder reqSpec) {
448469
* @param <T> type
449470
* @return type
450471
*/
472+
@Override
451473
public <T> T execute(Function<Response, T> handler) {
452474
return handler.apply(RestAssured.given().spec(reqSpec.build()).expect().spec(respSpec.build()).when().request(REQ_METHOD, REQ_URI));
453475
}
@@ -498,7 +520,7 @@ public FakeOuterNumberSerializeOper respSpec(Consumer<ResponseSpecBuilder> respS
498520
* @see #body Input string as post body (optional)
499521
* return String
500522
*/
501-
public static class FakeOuterStringSerializeOper {
523+
public static class FakeOuterStringSerializeOper implements Oper {
502524

503525
public static final Method REQ_METHOD = POST;
504526
public static final String REQ_URI = "/fake/outer/string";
@@ -519,6 +541,7 @@ public FakeOuterStringSerializeOper(RequestSpecBuilder reqSpec) {
519541
* @param <T> type
520542
* @return type
521543
*/
544+
@Override
522545
public <T> T execute(Function<Response, T> handler) {
523546
return handler.apply(RestAssured.given().spec(reqSpec.build()).expect().spec(respSpec.build()).when().request(REQ_METHOD, REQ_URI));
524547
}
@@ -568,7 +591,7 @@ public FakeOuterStringSerializeOper respSpec(Consumer<ResponseSpecBuilder> respS
568591
*
569592
* @see #body (required)
570593
*/
571-
public static class TestBodyWithFileSchemaOper {
594+
public static class TestBodyWithFileSchemaOper implements Oper {
572595

573596
public static final Method REQ_METHOD = PUT;
574597
public static final String REQ_URI = "/fake/body-with-file-schema";
@@ -589,6 +612,7 @@ public TestBodyWithFileSchemaOper(RequestSpecBuilder reqSpec) {
589612
* @param <T> type
590613
* @return type
591614
*/
615+
@Override
592616
public <T> T execute(Function<Response, T> handler) {
593617
return handler.apply(RestAssured.given().spec(reqSpec.build()).expect().spec(respSpec.build()).when().request(REQ_METHOD, REQ_URI));
594618
}
@@ -629,7 +653,7 @@ public TestBodyWithFileSchemaOper respSpec(Consumer<ResponseSpecBuilder> respSpe
629653
* @see #queryQuery (required)
630654
* @see #body (required)
631655
*/
632-
public static class TestBodyWithQueryParamsOper {
656+
public static class TestBodyWithQueryParamsOper implements Oper {
633657

634658
public static final Method REQ_METHOD = PUT;
635659
public static final String REQ_URI = "/fake/body-with-query-params";
@@ -650,6 +674,7 @@ public TestBodyWithQueryParamsOper(RequestSpecBuilder reqSpec) {
650674
* @param <T> type
651675
* @return type
652676
*/
677+
@Override
653678
public <T> T execute(Function<Response, T> handler) {
654679
return handler.apply(RestAssured.given().spec(reqSpec.build()).expect().spec(respSpec.build()).when().request(REQ_METHOD, REQ_URI));
655680
}
@@ -701,7 +726,7 @@ public TestBodyWithQueryParamsOper respSpec(Consumer<ResponseSpecBuilder> respSp
701726
* @see #body client model (required)
702727
* return Client
703728
*/
704-
public static class TestClientModelOper {
729+
public static class TestClientModelOper implements Oper {
705730

706731
public static final Method REQ_METHOD = PATCH;
707732
public static final String REQ_URI = "/fake";
@@ -722,6 +747,7 @@ public TestClientModelOper(RequestSpecBuilder reqSpec) {
722747
* @param <T> type
723748
* @return type
724749
*/
750+
@Override
725751
public <T> T execute(Function<Response, T> handler) {
726752
return handler.apply(RestAssured.given().spec(reqSpec.build()).expect().spec(respSpec.build()).when().request(REQ_METHOD, REQ_URI));
727753
}
@@ -784,7 +810,7 @@ public TestClientModelOper respSpec(Consumer<ResponseSpecBuilder> respSpecCustom
784810
* @see #passwordForm None (optional)
785811
* @see #paramCallbackForm None (optional)
786812
*/
787-
public static class TestEndpointParametersOper {
813+
public static class TestEndpointParametersOper implements Oper {
788814

789815
public static final Method REQ_METHOD = POST;
790816
public static final String REQ_URI = "/fake";
@@ -805,6 +831,7 @@ public TestEndpointParametersOper(RequestSpecBuilder reqSpec) {
805831
* @param <T> type
806832
* @return type
807833
*/
834+
@Override
808835
public <T> T execute(Function<Response, T> handler) {
809836
return handler.apply(RestAssured.given().spec(reqSpec.build()).expect().spec(respSpec.build()).when().request(REQ_METHOD, REQ_URI));
810837
}
@@ -996,7 +1023,7 @@ public TestEndpointParametersOper respSpec(Consumer<ResponseSpecBuilder> respSpe
9961023
* @see #enumFormStringArrayForm Form parameter enum test (string array) (optional, default to $)
9971024
* @see #enumFormStringForm Form parameter enum test (string) (optional, default to -efg)
9981025
*/
999-
public static class TestEnumParametersOper {
1026+
public static class TestEnumParametersOper implements Oper {
10001027

10011028
public static final Method REQ_METHOD = GET;
10021029
public static final String REQ_URI = "/fake";
@@ -1017,6 +1044,7 @@ public TestEnumParametersOper(RequestSpecBuilder reqSpec) {
10171044
* @param <T> type
10181045
* @return type
10191046
*/
1047+
@Override
10201048
public <T> T execute(Function<Response, T> handler) {
10211049
return handler.apply(RestAssured.given().spec(reqSpec.build()).expect().spec(respSpec.build()).when().request(REQ_METHOD, REQ_URI));
10221050
}
@@ -1140,7 +1168,7 @@ public TestEnumParametersOper respSpec(Consumer<ResponseSpecBuilder> respSpecCus
11401168
* @see #booleanGroupHeader Boolean in group parameters (optional)
11411169
* @see #int64GroupQuery Integer in group parameters (optional)
11421170
*/
1143-
public static class TestGroupParametersOper {
1171+
public static class TestGroupParametersOper implements Oper {
11441172

11451173
public static final Method REQ_METHOD = DELETE;
11461174
public static final String REQ_URI = "/fake";
@@ -1160,6 +1188,7 @@ public TestGroupParametersOper(RequestSpecBuilder reqSpec) {
11601188
* @param <T> type
11611189
* @return type
11621190
*/
1191+
@Override
11631192
public <T> T execute(Function<Response, T> handler) {
11641193
return handler.apply(RestAssured.given().spec(reqSpec.build()).expect().spec(respSpec.build()).when().request(REQ_METHOD, REQ_URI));
11651194
}
@@ -1256,7 +1285,7 @@ public TestGroupParametersOper respSpec(Consumer<ResponseSpecBuilder> respSpecCu
12561285
*
12571286
* @see #body request body (required)
12581287
*/
1259-
public static class TestInlineAdditionalPropertiesOper {
1288+
public static class TestInlineAdditionalPropertiesOper implements Oper {
12601289

12611290
public static final Method REQ_METHOD = POST;
12621291
public static final String REQ_URI = "/fake/inline-additionalProperties";
@@ -1277,6 +1306,7 @@ public TestInlineAdditionalPropertiesOper(RequestSpecBuilder reqSpec) {
12771306
* @param <T> type
12781307
* @return type
12791308
*/
1309+
@Override
12801310
public <T> T execute(Function<Response, T> handler) {
12811311
return handler.apply(RestAssured.given().spec(reqSpec.build()).expect().spec(respSpec.build()).when().request(REQ_METHOD, REQ_URI));
12821312
}
@@ -1317,7 +1347,7 @@ public TestInlineAdditionalPropertiesOper respSpec(Consumer<ResponseSpecBuilder>
13171347
* @see #paramForm field1 (required)
13181348
* @see #param2Form field2 (required)
13191349
*/
1320-
public static class TestJsonFormDataOper {
1350+
public static class TestJsonFormDataOper implements Oper {
13211351

13221352
public static final Method REQ_METHOD = GET;
13231353
public static final String REQ_URI = "/fake/jsonFormData";
@@ -1338,6 +1368,7 @@ public TestJsonFormDataOper(RequestSpecBuilder reqSpec) {
13381368
* @param <T> type
13391369
* @return type
13401370
*/
1371+
@Override
13411372
public <T> T execute(Function<Response, T> handler) {
13421373
return handler.apply(RestAssured.given().spec(reqSpec.build()).expect().spec(respSpec.build()).when().request(REQ_METHOD, REQ_URI));
13431374
}
@@ -1394,7 +1425,7 @@ public TestJsonFormDataOper respSpec(Consumer<ResponseSpecBuilder> respSpecCusto
13941425
* @see #urlQuery (required)
13951426
* @see #contextQuery (required)
13961427
*/
1397-
public static class TestQueryParameterCollectionFormatOper {
1428+
public static class TestQueryParameterCollectionFormatOper implements Oper {
13981429

13991430
public static final Method REQ_METHOD = PUT;
14001431
public static final String REQ_URI = "/fake/test-query-paramters";
@@ -1414,6 +1445,7 @@ public TestQueryParameterCollectionFormatOper(RequestSpecBuilder reqSpec) {
14141445
* @param <T> type
14151446
* @return type
14161447
*/
1448+
@Override
14171449
public <T> T execute(Function<Response, T> handler) {
14181450
return handler.apply(RestAssured.given().spec(reqSpec.build()).expect().spec(respSpec.build()).when().request(REQ_METHOD, REQ_URI));
14191451
}

samples/client/petstore/java/rest-assured/src/main/java/org/openapitools/client/api/FakeClassnameTags123Api.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ private RequestSpecBuilder createReqSpec() {
5757
return reqSpec;
5858
}
5959

60+
public List<Oper> getAllOperations() {
61+
return Arrays.asList(
62+
testClassname()
63+
);
64+
}
6065

6166
@ApiOperation(value = "To test class name in snake case",
6267
notes = "To test class name in snake case",
@@ -85,7 +90,7 @@ public FakeClassnameTags123Api reqSpec(Consumer<RequestSpecBuilder> reqSpecCusto
8590
* @see #body client model (required)
8691
* return Client
8792
*/
88-
public static class TestClassnameOper {
93+
public static class TestClassnameOper implements Oper {
8994

9095
public static final Method REQ_METHOD = PATCH;
9196
public static final String REQ_URI = "/fake_classname_test";
@@ -106,6 +111,7 @@ public TestClassnameOper(RequestSpecBuilder reqSpec) {
106111
* @param <T> type
107112
* @return type
108113
*/
114+
@Override
109115
public <T> T execute(Function<Response, T> handler) {
110116
return handler.apply(RestAssured.given().spec(reqSpec.build()).expect().spec(respSpec.build()).when().request(REQ_METHOD, REQ_URI));
111117
}

0 commit comments

Comments
 (0)