From 74584eb734f54ec0e7028aa643e68d1adeb3f014 Mon Sep 17 00:00:00 2001 From: William Cheng Date: Sat, 30 May 2020 11:17:19 +0800 Subject: [PATCH] migrate apex samples to use oas3 spec (#6488) --- bin/apex-petstore.sh | 2 +- samples/client/petstore/apex/README.md | 5 ++- .../main/default/classes/OASPetApi.cls | 30 +++++++------ .../main/default/classes/OASStoreApi.cls | 8 ++-- .../main/default/classes/OASUserApi.cls | 44 +++++++++---------- 5 files changed, 46 insertions(+), 43 deletions(-) diff --git a/bin/apex-petstore.sh b/bin/apex-petstore.sh index c4a2e6e0daa..28863b97d24 100755 --- a/bin/apex-petstore.sh +++ b/bin/apex-petstore.sh @@ -27,6 +27,6 @@ fi # if you've executed sbt assembly previously it will use that instead. export JAVA_OPTS="${JAVA_OPTS} -Xmx1024M -DloggerPath=conf/log4j.properties" -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 $@" +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 $@" java $JAVA_OPTS -jar $executable $ags diff --git a/samples/client/petstore/apex/README.md b/samples/client/petstore/apex/README.md index 45720bb0ab3..60da087e3fb 100644 --- a/samples/client/petstore/apex/README.md +++ b/samples/client/petstore/apex/README.md @@ -47,12 +47,13 @@ OASClient client = api.getClient(); Map params = new Map{ - 'body' => '' + 'oaSPet' => '' }; try { // cross your fingers - api.addPet(params); + OASPet result = api.addPet(params); + System.debug(result); } catch (OAS.ApiException e) { // ...handle your exceptions } diff --git a/samples/client/petstore/apex/force-app/main/default/classes/OASPetApi.cls b/samples/client/petstore/apex/force-app/main/default/classes/OASPetApi.cls index 1ad41d52ab5..75d79a76882 100644 --- a/samples/client/petstore/apex/force-app/main/default/classes/OASPetApi.cls +++ b/samples/client/petstore/apex/force-app/main/default/classes/OASPetApi.cls @@ -28,24 +28,25 @@ public class OASPetApi { /** * Add a new pet to the store * - * @param body Pet object that needs to be added to the store (required) + * @param oaSPet Pet object that needs to be added to the store (required) + * @return OASPet * @throws OAS.ApiException if fails to make API call */ - public void addPet(Map params) { - client.assertNotNull(params.get('body'), 'body'); + public OASPet addPet(Map params) { + client.assertNotNull(params.get('oaSPet'), 'oaSPet'); List query = new List(); List form = new List(); - client.invoke( + return (OASPet) client.invoke( 'POST', '/pet', - (OASPet) params.get('body'), + (OASPet) params.get('oaSPet'), query, form, new Map(), new Map(), - new List(), + new List{ 'application/xml', 'application/json' }, new List{ 'application/json', 'application/xml' }, new List { 'petstore_auth' }, - null + OASPet.class ); } /** @@ -157,24 +158,25 @@ public class OASPetApi { /** * Update an existing pet * - * @param body Pet object that needs to be added to the store (required) + * @param oaSPet Pet object that needs to be added to the store (required) + * @return OASPet * @throws OAS.ApiException if fails to make API call */ - public void updatePet(Map params) { - client.assertNotNull(params.get('body'), 'body'); + public OASPet updatePet(Map params) { + client.assertNotNull(params.get('oaSPet'), 'oaSPet'); List query = new List(); List form = new List(); - client.invoke( + return (OASPet) client.invoke( 'PUT', '/pet', - (OASPet) params.get('body'), + (OASPet) params.get('oaSPet'), query, form, new Map(), new Map(), - new List(), + new List{ 'application/xml', 'application/json' }, new List{ 'application/json', 'application/xml' }, new List { 'petstore_auth' }, - null + OASPet.class ); } /** diff --git a/samples/client/petstore/apex/force-app/main/default/classes/OASStoreApi.cls b/samples/client/petstore/apex/force-app/main/default/classes/OASStoreApi.cls index c5307e79fea..8ad6201cd16 100644 --- a/samples/client/petstore/apex/force-app/main/default/classes/OASStoreApi.cls +++ b/samples/client/petstore/apex/force-app/main/default/classes/OASStoreApi.cls @@ -98,23 +98,23 @@ public class OASStoreApi { /** * Place an order for a pet * - * @param body order placed for purchasing the pet (required) + * @param oaSOrder order placed for purchasing the pet (required) * @return OASOrder * @throws OAS.ApiException if fails to make API call */ public OASOrder placeOrder(Map params) { - client.assertNotNull(params.get('body'), 'body'); + client.assertNotNull(params.get('oaSOrder'), 'oaSOrder'); List query = new List(); List form = new List(); return (OASOrder) client.invoke( 'POST', '/store/order', - (OASOrder) params.get('body'), + (OASOrder) params.get('oaSOrder'), query, form, new Map(), new Map(), new List{ 'application/xml', 'application/json' }, - new List(), + new List{ 'application/json' }, new List(), OASOrder.class ); diff --git a/samples/client/petstore/apex/force-app/main/default/classes/OASUserApi.cls b/samples/client/petstore/apex/force-app/main/default/classes/OASUserApi.cls index 79adfc28ddd..021d6377d9d 100644 --- a/samples/client/petstore/apex/force-app/main/default/classes/OASUserApi.cls +++ b/samples/client/petstore/apex/force-app/main/default/classes/OASUserApi.cls @@ -28,69 +28,69 @@ public class OASUserApi { /** * Create user * This can only be done by the logged in user. - * @param body Created user object (required) + * @param oaSUser Created user object (required) * @throws OAS.ApiException if fails to make API call */ public void createUser(Map params) { - client.assertNotNull(params.get('body'), 'body'); + client.assertNotNull(params.get('oaSUser'), 'oaSUser'); List query = new List(); List form = new List(); client.invoke( 'POST', '/user', - (OASUser) params.get('body'), + (OASUser) params.get('oaSUser'), query, form, new Map(), new Map(), new List(), - new List(), - new List(), + new List{ 'application/json' }, + new List { 'api_key' }, null ); } /** * Creates list of users with given input array * - * @param body List of user object (required) + * @param oaSUser List of user object (required) * @throws OAS.ApiException if fails to make API call */ public void createUsersWithArrayInput(Map params) { - client.assertNotNull(params.get('body'), 'body'); + client.assertNotNull(params.get('oaSUser'), 'oaSUser'); List query = new List(); List form = new List(); client.invoke( 'POST', '/user/createWithArray', - (List) params.get('body'), + (List) params.get('oaSUser'), query, form, new Map(), new Map(), new List(), - new List(), - new List(), + new List{ 'application/json' }, + new List { 'api_key' }, null ); } /** * Creates list of users with given input array * - * @param body List of user object (required) + * @param oaSUser List of user object (required) * @throws OAS.ApiException if fails to make API call */ public void createUsersWithListInput(Map params) { - client.assertNotNull(params.get('body'), 'body'); + client.assertNotNull(params.get('oaSUser'), 'oaSUser'); List query = new List(); List form = new List(); client.invoke( 'POST', '/user/createWithList', - (List) params.get('body'), + (List) params.get('oaSUser'), query, form, new Map(), new Map(), new List(), - new List(), - new List(), + new List{ 'application/json' }, + new List { 'api_key' }, null ); } @@ -114,7 +114,7 @@ public class OASUserApi { new Map(), new List(), new List(), - new List(), + new List { 'api_key' }, null ); } @@ -189,7 +189,7 @@ public class OASUserApi { new Map(), new List(), new List(), - new List(), + new List { 'api_key' }, null ); } @@ -197,26 +197,26 @@ public class OASUserApi { * Updated user * This can only be done by the logged in user. * @param username name that need to be deleted (required) - * @param body Updated user object (required) + * @param oaSUser Updated user object (required) * @throws OAS.ApiException if fails to make API call */ public void updateUser(Map params) { client.assertNotNull(params.get('username'), 'username'); - client.assertNotNull(params.get('body'), 'body'); + client.assertNotNull(params.get('oaSUser'), 'oaSUser'); List query = new List(); List form = new List(); client.invoke( 'PUT', '/user/{username}', - (OASUser) params.get('body'), + (OASUser) params.get('oaSUser'), query, form, new Map{ 'username' => (String) params.get('username') }, new Map(), new List(), - new List(), - new List(), + new List{ 'application/json' }, + new List { 'api_key' }, null ); }