migrate apex samples to use oas3 spec (#6488)

This commit is contained in:
William Cheng 2020-05-30 11:17:19 +08:00 committed by GitHub
parent 5ef626be53
commit 74584eb734
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 46 additions and 43 deletions

View File

@ -27,6 +27,6 @@ fi
# if you've executed sbt assembly previously it will use that instead. # if you've executed sbt assembly previously it will use that instead.
export JAVA_OPTS="${JAVA_OPTS} -Xmx1024M -DloggerPath=conf/log4j.properties" 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 java $JAVA_OPTS -jar $executable $ags

View File

@ -47,12 +47,13 @@ OASClient client = api.getClient();
Map<String, Object> params = new Map<String, Object>{ Map<String, Object> params = new Map<String, Object>{
'body' => '' 'oaSPet' => ''
}; };
try { try {
// cross your fingers // cross your fingers
api.addPet(params); OASPet result = api.addPet(params);
System.debug(result);
} catch (OAS.ApiException e) { } catch (OAS.ApiException e) {
// ...handle your exceptions // ...handle your exceptions
} }

View File

@ -28,24 +28,25 @@ public class OASPetApi {
/** /**
* Add a new pet to the store * 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 * @throws OAS.ApiException if fails to make API call
*/ */
public void addPet(Map<String, Object> params) { public OASPet addPet(Map<String, Object> params) {
client.assertNotNull(params.get('body'), 'body'); client.assertNotNull(params.get('oaSPet'), 'oaSPet');
List<OAS.Param> query = new List<OAS.Param>(); List<OAS.Param> query = new List<OAS.Param>();
List<OAS.Param> form = new List<OAS.Param>(); List<OAS.Param> form = new List<OAS.Param>();
client.invoke( return (OASPet) client.invoke(
'POST', '/pet', 'POST', '/pet',
(OASPet) params.get('body'), (OASPet) params.get('oaSPet'),
query, form, query, form,
new Map<String, Object>(), new Map<String, Object>(),
new Map<String, Object>(), new Map<String, Object>(),
new List<String>(), new List<String>{ 'application/xml', 'application/json' },
new List<String>{ 'application/json', 'application/xml' }, new List<String>{ 'application/json', 'application/xml' },
new List<String> { 'petstore_auth' }, new List<String> { 'petstore_auth' },
null OASPet.class
); );
} }
/** /**
@ -157,24 +158,25 @@ public class OASPetApi {
/** /**
* Update an existing pet * 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 * @throws OAS.ApiException if fails to make API call
*/ */
public void updatePet(Map<String, Object> params) { public OASPet updatePet(Map<String, Object> params) {
client.assertNotNull(params.get('body'), 'body'); client.assertNotNull(params.get('oaSPet'), 'oaSPet');
List<OAS.Param> query = new List<OAS.Param>(); List<OAS.Param> query = new List<OAS.Param>();
List<OAS.Param> form = new List<OAS.Param>(); List<OAS.Param> form = new List<OAS.Param>();
client.invoke( return (OASPet) client.invoke(
'PUT', '/pet', 'PUT', '/pet',
(OASPet) params.get('body'), (OASPet) params.get('oaSPet'),
query, form, query, form,
new Map<String, Object>(), new Map<String, Object>(),
new Map<String, Object>(), new Map<String, Object>(),
new List<String>(), new List<String>{ 'application/xml', 'application/json' },
new List<String>{ 'application/json', 'application/xml' }, new List<String>{ 'application/json', 'application/xml' },
new List<String> { 'petstore_auth' }, new List<String> { 'petstore_auth' },
null OASPet.class
); );
} }
/** /**

View File

@ -98,23 +98,23 @@ public class OASStoreApi {
/** /**
* Place an order for a pet * 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 * @return OASOrder
* @throws OAS.ApiException if fails to make API call * @throws OAS.ApiException if fails to make API call
*/ */
public OASOrder placeOrder(Map<String, Object> params) { public OASOrder placeOrder(Map<String, Object> params) {
client.assertNotNull(params.get('body'), 'body'); client.assertNotNull(params.get('oaSOrder'), 'oaSOrder');
List<OAS.Param> query = new List<OAS.Param>(); List<OAS.Param> query = new List<OAS.Param>();
List<OAS.Param> form = new List<OAS.Param>(); List<OAS.Param> form = new List<OAS.Param>();
return (OASOrder) client.invoke( return (OASOrder) client.invoke(
'POST', '/store/order', 'POST', '/store/order',
(OASOrder) params.get('body'), (OASOrder) params.get('oaSOrder'),
query, form, query, form,
new Map<String, Object>(), new Map<String, Object>(),
new Map<String, Object>(), new Map<String, Object>(),
new List<String>{ 'application/xml', 'application/json' }, new List<String>{ 'application/xml', 'application/json' },
new List<String>(), new List<String>{ 'application/json' },
new List<String>(), new List<String>(),
OASOrder.class OASOrder.class
); );

View File

@ -28,69 +28,69 @@ public class OASUserApi {
/** /**
* Create user * Create user
* This can only be done by the logged in 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 * @throws OAS.ApiException if fails to make API call
*/ */
public void createUser(Map<String, Object> params) { public void createUser(Map<String, Object> params) {
client.assertNotNull(params.get('body'), 'body'); client.assertNotNull(params.get('oaSUser'), 'oaSUser');
List<OAS.Param> query = new List<OAS.Param>(); List<OAS.Param> query = new List<OAS.Param>();
List<OAS.Param> form = new List<OAS.Param>(); List<OAS.Param> form = new List<OAS.Param>();
client.invoke( client.invoke(
'POST', '/user', 'POST', '/user',
(OASUser) params.get('body'), (OASUser) params.get('oaSUser'),
query, form, query, form,
new Map<String, Object>(), new Map<String, Object>(),
new Map<String, Object>(), new Map<String, Object>(),
new List<String>(), new List<String>(),
new List<String>(), new List<String>{ 'application/json' },
new List<String>(), new List<String> { 'api_key' },
null null
); );
} }
/** /**
* Creates list of users with given input array * 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 * @throws OAS.ApiException if fails to make API call
*/ */
public void createUsersWithArrayInput(Map<String, Object> params) { public void createUsersWithArrayInput(Map<String, Object> params) {
client.assertNotNull(params.get('body'), 'body'); client.assertNotNull(params.get('oaSUser'), 'oaSUser');
List<OAS.Param> query = new List<OAS.Param>(); List<OAS.Param> query = new List<OAS.Param>();
List<OAS.Param> form = new List<OAS.Param>(); List<OAS.Param> form = new List<OAS.Param>();
client.invoke( client.invoke(
'POST', '/user/createWithArray', 'POST', '/user/createWithArray',
(List<OASUser>) params.get('body'), (List<OASUser>) params.get('oaSUser'),
query, form, query, form,
new Map<String, Object>(), new Map<String, Object>(),
new Map<String, Object>(), new Map<String, Object>(),
new List<String>(), new List<String>(),
new List<String>(), new List<String>{ 'application/json' },
new List<String>(), new List<String> { 'api_key' },
null null
); );
} }
/** /**
* Creates list of users with given input array * 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 * @throws OAS.ApiException if fails to make API call
*/ */
public void createUsersWithListInput(Map<String, Object> params) { public void createUsersWithListInput(Map<String, Object> params) {
client.assertNotNull(params.get('body'), 'body'); client.assertNotNull(params.get('oaSUser'), 'oaSUser');
List<OAS.Param> query = new List<OAS.Param>(); List<OAS.Param> query = new List<OAS.Param>();
List<OAS.Param> form = new List<OAS.Param>(); List<OAS.Param> form = new List<OAS.Param>();
client.invoke( client.invoke(
'POST', '/user/createWithList', 'POST', '/user/createWithList',
(List<OASUser>) params.get('body'), (List<OASUser>) params.get('oaSUser'),
query, form, query, form,
new Map<String, Object>(), new Map<String, Object>(),
new Map<String, Object>(), new Map<String, Object>(),
new List<String>(), new List<String>(),
new List<String>(), new List<String>{ 'application/json' },
new List<String>(), new List<String> { 'api_key' },
null null
); );
} }
@ -114,7 +114,7 @@ public class OASUserApi {
new Map<String, Object>(), new Map<String, Object>(),
new List<String>(), new List<String>(),
new List<String>(), new List<String>(),
new List<String>(), new List<String> { 'api_key' },
null null
); );
} }
@ -189,7 +189,7 @@ public class OASUserApi {
new Map<String, Object>(), new Map<String, Object>(),
new List<String>(), new List<String>(),
new List<String>(), new List<String>(),
new List<String>(), new List<String> { 'api_key' },
null null
); );
} }
@ -197,26 +197,26 @@ public class OASUserApi {
* Updated user * Updated user
* This can only be done by the logged in user. * This can only be done by the logged in user.
* @param username name that need to be deleted (required) * @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 * @throws OAS.ApiException if fails to make API call
*/ */
public void updateUser(Map<String, Object> params) { public void updateUser(Map<String, Object> params) {
client.assertNotNull(params.get('username'), 'username'); client.assertNotNull(params.get('username'), 'username');
client.assertNotNull(params.get('body'), 'body'); client.assertNotNull(params.get('oaSUser'), 'oaSUser');
List<OAS.Param> query = new List<OAS.Param>(); List<OAS.Param> query = new List<OAS.Param>();
List<OAS.Param> form = new List<OAS.Param>(); List<OAS.Param> form = new List<OAS.Param>();
client.invoke( client.invoke(
'PUT', '/user/{username}', 'PUT', '/user/{username}',
(OASUser) params.get('body'), (OASUser) params.get('oaSUser'),
query, form, query, form,
new Map<String, Object>{ new Map<String, Object>{
'username' => (String) params.get('username') 'username' => (String) params.get('username')
}, },
new Map<String, Object>(), new Map<String, Object>(),
new List<String>(), new List<String>(),
new List<String>(), new List<String>{ 'application/json' },
new List<String>(), new List<String> { 'api_key' },
null null
); );
} }