Skip to content

Commit

Permalink
migrate apex samples to use oas3 spec (#6488)
Browse files Browse the repository at this point in the history
  • Loading branch information
wing328 authored May 30, 2020
1 parent 5ef626b commit 74584eb
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 43 deletions.
2 changes: 1 addition & 1 deletion bin/apex-petstore.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 3 additions & 2 deletions samples/client/petstore/apex/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,13 @@ OASClient client = api.getClient();


Map<String, Object> params = new Map<String, Object>{
'body' => ''
'oaSPet' => ''
};

try {
// cross your fingers
api.addPet(params);
OASPet result = api.addPet(params);
System.debug(result);
} catch (OAS.ApiException e) {
// ...handle your exceptions
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Object> params) {
client.assertNotNull(params.get('body'), 'body');
public OASPet addPet(Map<String, Object> params) {
client.assertNotNull(params.get('oaSPet'), 'oaSPet');
List<OAS.Param> query = new List<OAS.Param>();
List<OAS.Param> form = new List<OAS.Param>();

client.invoke(
return (OASPet) client.invoke(
'POST', '/pet',
(OASPet) params.get('body'),
(OASPet) params.get('oaSPet'),
query, form,
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> { 'petstore_auth' },
null
OASPet.class
);
}
/**
Expand Down Expand Up @@ -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<String, Object> params) {
client.assertNotNull(params.get('body'), 'body');
public OASPet updatePet(Map<String, Object> params) {
client.assertNotNull(params.get('oaSPet'), 'oaSPet');
List<OAS.Param> query = new List<OAS.Param>();
List<OAS.Param> form = new List<OAS.Param>();

client.invoke(
return (OASPet) client.invoke(
'PUT', '/pet',
(OASPet) params.get('body'),
(OASPet) params.get('oaSPet'),
query, form,
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> { 'petstore_auth' },
null
OASPet.class
);
}
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<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> form = new List<OAS.Param>();

return (OASOrder) client.invoke(
'POST', '/store/order',
(OASOrder) params.get('body'),
(OASOrder) params.get('oaSOrder'),
query, form,
new Map<String, Object>(),
new Map<String, Object>(),
new List<String>{ 'application/xml', 'application/json' },
new List<String>(),
new List<String>{ 'application/json' },
new List<String>(),
OASOrder.class
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<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> form = new List<OAS.Param>();

client.invoke(
'POST', '/user',
(OASUser) params.get('body'),
(OASUser) params.get('oaSUser'),
query, form,
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> { '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<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> form = new List<OAS.Param>();

client.invoke(
'POST', '/user/createWithArray',
(List<OASUser>) params.get('body'),
(List<OASUser>) params.get('oaSUser'),
query, form,
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> { '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<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> form = new List<OAS.Param>();

client.invoke(
'POST', '/user/createWithList',
(List<OASUser>) params.get('body'),
(List<OASUser>) params.get('oaSUser'),
query, form,
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> { 'api_key' },
null
);
}
Expand All @@ -114,7 +114,7 @@ public class OASUserApi {
new Map<String, Object>(),
new List<String>(),
new List<String>(),
new List<String>(),
new List<String> { 'api_key' },
null
);
}
Expand Down Expand Up @@ -189,34 +189,34 @@ public class OASUserApi {
new Map<String, Object>(),
new List<String>(),
new List<String>(),
new List<String>(),
new List<String> { 'api_key' },
null
);
}
/**
* 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<String, Object> params) {
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> form = new List<OAS.Param>();

client.invoke(
'PUT', '/user/{username}',
(OASUser) params.get('body'),
(OASUser) params.get('oaSUser'),
query, form,
new Map<String, Object>{
'username' => (String) params.get('username')
},
new Map<String, Object>(),
new List<String>(),
new List<String>(),
new List<String>(),
new List<String>{ 'application/json' },
new List<String> { 'api_key' },
null
);
}
Expand Down

0 comments on commit 74584eb

Please sign in to comment.