Skip to content

Commit 74584eb

Browse files
authored
migrate apex samples to use oas3 spec (#6488)
1 parent 5ef626b commit 74584eb

File tree

5 files changed

+46
-43
lines changed

5 files changed

+46
-43
lines changed

bin/apex-petstore.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@ fi
2727

2828
# if you've executed sbt assembly previously it will use that instead.
2929
export JAVA_OPTS="${JAVA_OPTS} -Xmx1024M -DloggerPath=conf/log4j.properties"
30-
ags="generate -t modules/openapi-generator/src/main/resources/apex -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -g apex -o samples/client/petstore/apex $@"
30+
ags="generate -t modules/openapi-generator/src/main/resources/apex -i modules/openapi-generator/src/test/resources/3_0/petstore.yaml -g apex -o samples/client/petstore/apex -DskipFormModel=true $@"
3131

3232
java $JAVA_OPTS -jar $executable $ags

samples/client/petstore/apex/README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,13 @@ OASClient client = api.getClient();
4747

4848

4949
Map<String, Object> params = new Map<String, Object>{
50-
'body' => ''
50+
'oaSPet' => ''
5151
};
5252

5353
try {
5454
// cross your fingers
55-
api.addPet(params);
55+
OASPet result = api.addPet(params);
56+
System.debug(result);
5657
} catch (OAS.ApiException e) {
5758
// ...handle your exceptions
5859
}

samples/client/petstore/apex/force-app/main/default/classes/OASPetApi.cls

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,24 +28,25 @@ public class OASPetApi {
2828
/**
2929
* Add a new pet to the store
3030
*
31-
* @param body Pet object that needs to be added to the store (required)
31+
* @param oaSPet Pet object that needs to be added to the store (required)
32+
* @return OASPet
3233
* @throws OAS.ApiException if fails to make API call
3334
*/
34-
public void addPet(Map<String, Object> params) {
35-
client.assertNotNull(params.get('body'), 'body');
35+
public OASPet addPet(Map<String, Object> params) {
36+
client.assertNotNull(params.get('oaSPet'), 'oaSPet');
3637
List<OAS.Param> query = new List<OAS.Param>();
3738
List<OAS.Param> form = new List<OAS.Param>();
3839

39-
client.invoke(
40+
return (OASPet) client.invoke(
4041
'POST', '/pet',
41-
(OASPet) params.get('body'),
42+
(OASPet) params.get('oaSPet'),
4243
query, form,
4344
new Map<String, Object>(),
4445
new Map<String, Object>(),
45-
new List<String>(),
46+
new List<String>{ 'application/xml', 'application/json' },
4647
new List<String>{ 'application/json', 'application/xml' },
4748
new List<String> { 'petstore_auth' },
48-
null
49+
OASPet.class
4950
);
5051
}
5152
/**
@@ -157,24 +158,25 @@ public class OASPetApi {
157158
/**
158159
* Update an existing pet
159160
*
160-
* @param body Pet object that needs to be added to the store (required)
161+
* @param oaSPet Pet object that needs to be added to the store (required)
162+
* @return OASPet
161163
* @throws OAS.ApiException if fails to make API call
162164
*/
163-
public void updatePet(Map<String, Object> params) {
164-
client.assertNotNull(params.get('body'), 'body');
165+
public OASPet updatePet(Map<String, Object> params) {
166+
client.assertNotNull(params.get('oaSPet'), 'oaSPet');
165167
List<OAS.Param> query = new List<OAS.Param>();
166168
List<OAS.Param> form = new List<OAS.Param>();
167169

168-
client.invoke(
170+
return (OASPet) client.invoke(
169171
'PUT', '/pet',
170-
(OASPet) params.get('body'),
172+
(OASPet) params.get('oaSPet'),
171173
query, form,
172174
new Map<String, Object>(),
173175
new Map<String, Object>(),
174-
new List<String>(),
176+
new List<String>{ 'application/xml', 'application/json' },
175177
new List<String>{ 'application/json', 'application/xml' },
176178
new List<String> { 'petstore_auth' },
177-
null
179+
OASPet.class
178180
);
179181
}
180182
/**

samples/client/petstore/apex/force-app/main/default/classes/OASStoreApi.cls

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,23 +98,23 @@ public class OASStoreApi {
9898
/**
9999
* Place an order for a pet
100100
*
101-
* @param body order placed for purchasing the pet (required)
101+
* @param oaSOrder order placed for purchasing the pet (required)
102102
* @return OASOrder
103103
* @throws OAS.ApiException if fails to make API call
104104
*/
105105
public OASOrder placeOrder(Map<String, Object> params) {
106-
client.assertNotNull(params.get('body'), 'body');
106+
client.assertNotNull(params.get('oaSOrder'), 'oaSOrder');
107107
List<OAS.Param> query = new List<OAS.Param>();
108108
List<OAS.Param> form = new List<OAS.Param>();
109109

110110
return (OASOrder) client.invoke(
111111
'POST', '/store/order',
112-
(OASOrder) params.get('body'),
112+
(OASOrder) params.get('oaSOrder'),
113113
query, form,
114114
new Map<String, Object>(),
115115
new Map<String, Object>(),
116116
new List<String>{ 'application/xml', 'application/json' },
117-
new List<String>(),
117+
new List<String>{ 'application/json' },
118118
new List<String>(),
119119
OASOrder.class
120120
);

samples/client/petstore/apex/force-app/main/default/classes/OASUserApi.cls

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -28,69 +28,69 @@ public class OASUserApi {
2828
/**
2929
* Create user
3030
* This can only be done by the logged in user.
31-
* @param body Created user object (required)
31+
* @param oaSUser Created user object (required)
3232
* @throws OAS.ApiException if fails to make API call
3333
*/
3434
public void createUser(Map<String, Object> params) {
35-
client.assertNotNull(params.get('body'), 'body');
35+
client.assertNotNull(params.get('oaSUser'), 'oaSUser');
3636
List<OAS.Param> query = new List<OAS.Param>();
3737
List<OAS.Param> form = new List<OAS.Param>();
3838

3939
client.invoke(
4040
'POST', '/user',
41-
(OASUser) params.get('body'),
41+
(OASUser) params.get('oaSUser'),
4242
query, form,
4343
new Map<String, Object>(),
4444
new Map<String, Object>(),
4545
new List<String>(),
46-
new List<String>(),
47-
new List<String>(),
46+
new List<String>{ 'application/json' },
47+
new List<String> { 'api_key' },
4848
null
4949
);
5050
}
5151
/**
5252
* Creates list of users with given input array
5353
*
54-
* @param body List of user object (required)
54+
* @param oaSUser List of user object (required)
5555
* @throws OAS.ApiException if fails to make API call
5656
*/
5757
public void createUsersWithArrayInput(Map<String, Object> params) {
58-
client.assertNotNull(params.get('body'), 'body');
58+
client.assertNotNull(params.get('oaSUser'), 'oaSUser');
5959
List<OAS.Param> query = new List<OAS.Param>();
6060
List<OAS.Param> form = new List<OAS.Param>();
6161

6262
client.invoke(
6363
'POST', '/user/createWithArray',
64-
(List<OASUser>) params.get('body'),
64+
(List<OASUser>) params.get('oaSUser'),
6565
query, form,
6666
new Map<String, Object>(),
6767
new Map<String, Object>(),
6868
new List<String>(),
69-
new List<String>(),
70-
new List<String>(),
69+
new List<String>{ 'application/json' },
70+
new List<String> { 'api_key' },
7171
null
7272
);
7373
}
7474
/**
7575
* Creates list of users with given input array
7676
*
77-
* @param body List of user object (required)
77+
* @param oaSUser List of user object (required)
7878
* @throws OAS.ApiException if fails to make API call
7979
*/
8080
public void createUsersWithListInput(Map<String, Object> params) {
81-
client.assertNotNull(params.get('body'), 'body');
81+
client.assertNotNull(params.get('oaSUser'), 'oaSUser');
8282
List<OAS.Param> query = new List<OAS.Param>();
8383
List<OAS.Param> form = new List<OAS.Param>();
8484

8585
client.invoke(
8686
'POST', '/user/createWithList',
87-
(List<OASUser>) params.get('body'),
87+
(List<OASUser>) params.get('oaSUser'),
8888
query, form,
8989
new Map<String, Object>(),
9090
new Map<String, Object>(),
9191
new List<String>(),
92-
new List<String>(),
93-
new List<String>(),
92+
new List<String>{ 'application/json' },
93+
new List<String> { 'api_key' },
9494
null
9595
);
9696
}
@@ -114,7 +114,7 @@ public class OASUserApi {
114114
new Map<String, Object>(),
115115
new List<String>(),
116116
new List<String>(),
117-
new List<String>(),
117+
new List<String> { 'api_key' },
118118
null
119119
);
120120
}
@@ -189,34 +189,34 @@ public class OASUserApi {
189189
new Map<String, Object>(),
190190
new List<String>(),
191191
new List<String>(),
192-
new List<String>(),
192+
new List<String> { 'api_key' },
193193
null
194194
);
195195
}
196196
/**
197197
* Updated user
198198
* This can only be done by the logged in user.
199199
* @param username name that need to be deleted (required)
200-
* @param body Updated user object (required)
200+
* @param oaSUser Updated user object (required)
201201
* @throws OAS.ApiException if fails to make API call
202202
*/
203203
public void updateUser(Map<String, Object> params) {
204204
client.assertNotNull(params.get('username'), 'username');
205-
client.assertNotNull(params.get('body'), 'body');
205+
client.assertNotNull(params.get('oaSUser'), 'oaSUser');
206206
List<OAS.Param> query = new List<OAS.Param>();
207207
List<OAS.Param> form = new List<OAS.Param>();
208208

209209
client.invoke(
210210
'PUT', '/user/{username}',
211-
(OASUser) params.get('body'),
211+
(OASUser) params.get('oaSUser'),
212212
query, form,
213213
new Map<String, Object>{
214214
'username' => (String) params.get('username')
215215
},
216216
new Map<String, Object>(),
217217
new List<String>(),
218-
new List<String>(),
219-
new List<String>(),
218+
new List<String>{ 'application/json' },
219+
new List<String> { 'api_key' },
220220
null
221221
);
222222
}

0 commit comments

Comments
 (0)