Permalink
Browse files

[Apex] add petstore samples, shell scripts, batch files (#5672)

* add apex petstore samples, shell scripts, batch files

* add wording "beta" to Apex help
  • Loading branch information...
1 parent 1aeef5f commit 7edf74442664243a639255ec6635b27260d786f7 @wing328 wing328 committed on GitHub May 19, 2017
Showing with 5,057 additions and 1 deletion.
  1. +31 −0 bin/apex-petstore.sh
  2. +10 −0 bin/windows/apex-petstore.bat
  3. +1 −1 modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/ApexClientCodegen.java
  4. +27 −0 samples/client/petstore/apex/.gitignore
  5. +23 −0 samples/client/petstore/apex/.swagger-codegen-ignore
  6. +1 −0 samples/client/petstore/apex/.swagger-codegen/VERSION
  7. +181 −0 samples/client/petstore/apex/README.md
  8. +37 −0 samples/client/petstore/apex/build.properties
  9. +96 −0 samples/client/petstore/apex/build.xml
  10. +69 −0 samples/client/petstore/apex/deploy/classes/SwagApiResponse.cls
  11. +5 −0 samples/client/petstore/apex/deploy/classes/SwagApiResponse.cls-meta.xml
  12. +87 −0 samples/client/petstore/apex/deploy/classes/SwagApiResponseTest.cls
  13. +5 −0 samples/client/petstore/apex/deploy/classes/SwagApiResponseTest.cls-meta.xml
  14. +52 −0 samples/client/petstore/apex/deploy/classes/SwagCategory.cls
  15. +5 −0 samples/client/petstore/apex/deploy/classes/SwagCategory.cls-meta.xml
  16. +80 −0 samples/client/petstore/apex/deploy/classes/SwagCategoryTest.cls
  17. +5 −0 samples/client/petstore/apex/deploy/classes/SwagCategoryTest.cls-meta.xml
  18. +7 −0 samples/client/petstore/apex/deploy/classes/SwagClient.cls
  19. +5 −0 samples/client/petstore/apex/deploy/classes/SwagClient.cls-meta.xml
  20. +101 −0 samples/client/petstore/apex/deploy/classes/SwagOrder.cls
  21. +5 −0 samples/client/petstore/apex/deploy/classes/SwagOrder.cls-meta.xml
  22. +91 −0 samples/client/petstore/apex/deploy/classes/SwagOrderTest.cls
  23. +5 −0 samples/client/petstore/apex/deploy/classes/SwagOrderTest.cls-meta.xml
  24. +102 −0 samples/client/petstore/apex/deploy/classes/SwagPet.cls
  25. +5 −0 samples/client/petstore/apex/deploy/classes/SwagPet.cls-meta.xml
  26. +241 −0 samples/client/petstore/apex/deploy/classes/SwagPetApi.cls
  27. +5 −0 samples/client/petstore/apex/deploy/classes/SwagPetApi.cls-meta.xml
  28. +247 −0 samples/client/petstore/apex/deploy/classes/SwagPetApiTest.cls
  29. +5 −0 samples/client/petstore/apex/deploy/classes/SwagPetApiTest.cls-meta.xml
  30. +91 −0 samples/client/petstore/apex/deploy/classes/SwagPetTest.cls
  31. +5 −0 samples/client/petstore/apex/deploy/classes/SwagPetTest.cls-meta.xml
  32. +122 −0 samples/client/petstore/apex/deploy/classes/SwagStoreApi.cls
  33. +5 −0 samples/client/petstore/apex/deploy/classes/SwagStoreApi.cls-meta.xml
  34. +115 −0 samples/client/petstore/apex/deploy/classes/SwagStoreApiTest.cls
  35. +5 −0 samples/client/petstore/apex/deploy/classes/SwagStoreApiTest.cls-meta.xml
  36. +52 −0 samples/client/petstore/apex/deploy/classes/SwagTag.cls
  37. +5 −0 samples/client/petstore/apex/deploy/classes/SwagTag.cls-meta.xml
  38. +80 −0 samples/client/petstore/apex/deploy/classes/SwagTagTest.cls
  39. +5 −0 samples/client/petstore/apex/deploy/classes/SwagTagTest.cls-meta.xml
  40. +106 −0 samples/client/petstore/apex/deploy/classes/SwagUser.cls
  41. +5 −0 samples/client/petstore/apex/deploy/classes/SwagUser.cls-meta.xml
  42. +223 −0 samples/client/petstore/apex/deploy/classes/SwagUserApi.cls
  43. +5 −0 samples/client/petstore/apex/deploy/classes/SwagUserApi.cls-meta.xml
  44. +204 −0 samples/client/petstore/apex/deploy/classes/SwagUserApiTest.cls
  45. +5 −0 samples/client/petstore/apex/deploy/classes/SwagUserApiTest.cls-meta.xml
  46. +80 −0 samples/client/petstore/apex/deploy/classes/SwagUserTest.cls
  47. +5 −0 samples/client/petstore/apex/deploy/classes/SwagUserTest.cls-meta.xml
  48. +395 −0 samples/client/petstore/apex/deploy/classes/Swagger.cls
  49. +5 −0 samples/client/petstore/apex/deploy/classes/Swagger.cls-meta.xml
  50. +18 −0 samples/client/petstore/apex/deploy/classes/SwaggerResponseMock.cls
  51. +5 −0 samples/client/petstore/apex/deploy/classes/SwaggerResponseMock.cls-meta.xml
  52. +782 −0 samples/client/petstore/apex/deploy/classes/SwaggerTest.cls
  53. +5 −0 samples/client/petstore/apex/deploy/classes/SwaggerTest.cls-meta.xml
  54. +37 −0 samples/client/petstore/apex/deploy/package.xml
  55. +7 −0 samples/client/petstore/apex/deploy/remoteSiteSettings/Swagger_Petstore.remoteSite
  56. +12 −0 samples/client/petstore/apex/docs/SwagApiResponse.md
  57. +11 −0 samples/client/petstore/apex/docs/SwagCategory.md
  58. +24 −0 samples/client/petstore/apex/docs/SwagOrder.md
  59. +24 −0 samples/client/petstore/apex/docs/SwagPet.md
  60. +414 −0 samples/client/petstore/apex/docs/SwagPetApi.md
  61. +185 −0 samples/client/petstore/apex/docs/SwagStoreApi.md
  62. +11 −0 samples/client/petstore/apex/docs/SwagTag.md
  63. +17 −0 samples/client/petstore/apex/docs/SwagUser.md
  64. +359 −0 samples/client/petstore/apex/docs/SwagUserApi.md
  65. +52 −0 samples/client/petstore/apex/git_push.sh
  66. +37 −0 samples/client/petstore/apex/undeploy/destructiveChanges.xml
  67. +5 −0 samples/client/petstore/apex/undeploy/package.xml
View
@@ -0,0 +1,31 @@
+#!/bin/sh
+
+SCRIPT="$0"
+
+while [ -h "$SCRIPT" ] ; do
+ ls=`ls -ld "$SCRIPT"`
+ link=`expr "$ls" : '.*-> \(.*\)$'`
+ if expr "$link" : '/.*' > /dev/null; then
+ SCRIPT="$link"
+ else
+ SCRIPT=`dirname "$SCRIPT"`/"$link"
+ fi
+done
+
+if [ ! -d "${APP_DIR}" ]; then
+ APP_DIR=`dirname "$SCRIPT"`/..
+ APP_DIR=`cd "${APP_DIR}"; pwd`
+fi
+
+executable="./modules/swagger-codegen-cli/target/swagger-codegen-cli.jar"
+
+if [ ! -f "$executable" ]
+then
+ mvn clean package
+fi
+
+# if you've executed sbt assembly previously it will use that instead.
+export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
+ags="$@ generate -t modules/swagger-codegen/src/main/resources/apex -i modules/swagger-codegen/src/test/resources/2_0/petstore.yaml -l apex -o samples/client/petstore/apex"
+
+java $JAVA_OPTS -jar $executable $ags
@@ -0,0 +1,10 @@
+set executable=.\modules\swagger-codegen-cli\target\swagger-codegen-cli.jar
+
+If Not Exist %executable% (
+ mvn clean package
+)
+
+REM set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M
+set ags=generate -i modules\swagger-codegen\src\test\resources\2_0\petstore.yaml -l apex -o samples\client\petstore\apex
+
+java %JAVA_OPTS% -jar %executable% %ags%
@@ -449,6 +449,6 @@ public String getName() {
@Override
public String getHelp() {
- return "Generates an Apex client library.";
+ return "Generates an Apex API client library (beta).";
}
}
@@ -0,0 +1,27 @@
+*DS_Store*
+
+/Referenced Packages
+/salesforce.schema
+
+.metadata
+bin/
+tmp/
+*.tmp
+*.bak
+*.swp
+*~.nib
+local.properties
+.settings/
+.loadpath
+.recommenders
+
+# Eclipse
+.project
+.externalToolBuilders/
+*.launch
+
+*.iml
+.idea
+
+*.sublime*
+config
@@ -0,0 +1,23 @@
+# Swagger Codegen Ignore
+# Generated by swagger-codegen https://github.com/swagger-api/swagger-codegen
+
+# Use this file to prevent files from being overwritten by the generator.
+# The patterns follow closely to .gitignore or .dockerignore.
+
+# As an example, the C# client generator defines ApiClient.cs.
+# You can make changes and tell Swagger Codgen to ignore just this file by uncommenting the following line:
+#ApiClient.cs
+
+# You can match any string of characters against a directory, file or extension with a single asterisk (*):
+#foo/*/qux
+# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux
+
+# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
+#foo/**/qux
+# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux
+
+# You can also negate patterns with an exclamation (!).
+# For example, you can ignore all files in a docs folder with the file extension .md:
+#docs/*.md
+# Then explicitly reverse the ignore rule for a single file:
+#!docs/README.md
@@ -0,0 +1 @@
+2.2.3-SNAPSHOT
@@ -0,0 +1,181 @@
+# Swagger Petstore API Client
+
+This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters.
+
+## Requirements
+
+- [Java 8 JDK](http://www.oracle.com/technetwork/java/javase/downloads/index.html)
+- [Apache Ant](http://ant.apache.org/) version 1.6 or later
+- [Force.com Migration Tool](https://developer.salesforce.com/docs/atlas.en-us.daas.meta/daas/forcemigrationtool_install.htm)
+ - The `ant-salesforce.jar` file included with the Force.com Migration Tool must be placed in the root directory of this project (in the same directory as this README and `build.xml`)
+- `ANT_HOME` and `JAVA_HOME` environment variables must be set accordingly
+ - On Windows, `JAVA_HOME` will probably look something like this:
+
+ ```
+ JAVA_HOME = C:\Program Files\Java\jdk1.8.0_121
+ ```
+
+- The `bin` directory from Ant must be on your `PATH`
+
+If everything is set correctly:
+
+- Running `java -version` in a command prompt should output something like:
+
+ ```bash
+ java version "1.8.0_121"
+ Java(TM) SE Runtime Environment (build 1.8.0_121-b13)
+ Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)
+ ```
+
+- Running `ant -version` should output something like:
+
+ ```bash
+ Apache Ant(TM) version 1.10.1 compiled on February 2 2017
+ ```
+
+For more information, see <https://developer.salesforce.com/docs/atlas.en-us.daas.meta/daas/forcemigrationtool_prereq.htm>
+
+## Installation
+
+
+1. Clone the repo from GitHub
+
+ ```bash
+ $ git clone git@github.com:GIT_USER_ID/GIT_REPO_ID.git
+ ```
+
+ Or, [download](https://github.com/GIT_USER_ID/GIT_REPO_ID/archive/master.zip) the repo as a ZIP and extract it to `GIT_REPO_ID`
+
+1. Set the `SF_USERNAME` and `SF_PASSWORD` environment variables to your Salesforce username and password. Alternatively, they may be set in `build.properties`. Environment variables will override the values in `build.properties` if set.
+
+ `SF_SESSIONID` may also be set instead of `SF_USERNAME` and `SF_PASSWORD` (more info in `build.properties`)
+
+2. Open up a command prompt in the root project directory `GIT_REPO_ID` (the same directory as this README and `build.xml`)
+3. Deploy to your Salesforce org
+
+ ```bash
+ $ ant deploy
+ ```
+
+ This command will:
+
+ - deploy all classes in the `deploy/classes` directory to your Salesforce org
+ - create a new [unmanaged package](https://help.salesforce.com/articleView?id=sharing_apps.htm) called **Swagger Petstore API Client**
+ - execute all of the unit tests included in this package (at least 75% code coverage required)
+ - create a new [remote site](https://help.salesforce.com/articleView?id=configuring_remoteproxy.htm) called **Swagger_Petstore** configured for the endpoint: <http://petstore.swagger.io/v2>
+ - rolls back any changes upon any error
+
+ A successful deployment will look like this:
+
+ ```bash
+ [sf:deploy] Request Status: Succeeded
+ [sf:deploy] *********** DEPLOYMENT SUCCEEDED ***********
+ [sf:deploy] Finished request 0Af7A00000Ebd5oSAB successfully.
+
+ BUILD SUCCESSFUL
+ Total time: 34 seconds
+ ```
+
+### Test deployment only
+
+To perform a test deployment without committing changes:
+
+```bash
+$ ant deployCheckOnly
+```
+
+All of the included tests will run as if it were a real deployment. Tests and other validations will report back while leaving your org untouched, allowing you to verify that a deployment will succeed without affecting anything in the org.
+
+### Uninstallation
+
+```bash
+$ ant undeploy
+```
+
+Removes all classes and the Remote Site created by this package.
+
+## Getting Started
+
+Please follow the [installation](#installation) instruction and execute the following Apex code:
+
+```java
+SwagPetApi api = new SwagPetApi();
+SwagClient client = api.getClient();
+
+// Configure OAuth2 access token for authorization: petstore_auth
+Swagger.OAuth petstore_auth = (Swagger.OAuth) client.getAuthentication('petstore_auth');
+petstore_auth.setAccessToken('YOUR ACCESS TOKEN');
+
+Map<String, Object> params = new Map<String, Object>{
+ 'body' => SwagPet.getExample()
+};
+
+try {
+ // cross your fingers
+ api.addPet(params);
+} catch (Swagger.ApiException e) {
+ // ...handle your exceptions
+}
+```
+
+## Documentation for API Endpoints
+
+All URIs are relative to *http://petstore.swagger.io/v2*
+
+Class | Method | HTTP request | Description
+------------ | ------------- | ------------- | -------------
+*SwagPetApi* | [**addPet**](docs/SwagPetApi.md#addPet) | **POST** /pet | Add a new pet to the store
+*SwagPetApi* | [**deletePet**](docs/SwagPetApi.md#deletePet) | **DELETE** /pet/{petId} | Deletes a pet
+*SwagPetApi* | [**findPetsByStatus**](docs/SwagPetApi.md#findPetsByStatus) | **GET** /pet/findByStatus | Finds Pets by status
+*SwagPetApi* | [**findPetsByTags**](docs/SwagPetApi.md#findPetsByTags) | **GET** /pet/findByTags | Finds Pets by tags
+*SwagPetApi* | [**getPetById**](docs/SwagPetApi.md#getPetById) | **GET** /pet/{petId} | Find pet by ID
+*SwagPetApi* | [**updatePet**](docs/SwagPetApi.md#updatePet) | **PUT** /pet | Update an existing pet
+*SwagPetApi* | [**updatePetWithForm**](docs/SwagPetApi.md#updatePetWithForm) | **POST** /pet/{petId} | Updates a pet in the store with form data
+*SwagPetApi* | [**uploadFile**](docs/SwagPetApi.md#uploadFile) | **POST** /pet/{petId}/uploadImage | uploads an image
+*SwagStoreApi* | [**deleteOrder**](docs/SwagStoreApi.md#deleteOrder) | **DELETE** /store/order/{orderId} | Delete purchase order by ID
+*SwagStoreApi* | [**getInventory**](docs/SwagStoreApi.md#getInventory) | **GET** /store/inventory | Returns pet inventories by status
+*SwagStoreApi* | [**getOrderById**](docs/SwagStoreApi.md#getOrderById) | **GET** /store/order/{orderId} | Find purchase order by ID
+*SwagStoreApi* | [**placeOrder**](docs/SwagStoreApi.md#placeOrder) | **POST** /store/order | Place an order for a pet
+*SwagUserApi* | [**createUser**](docs/SwagUserApi.md#createUser) | **POST** /user | Create user
+*SwagUserApi* | [**createUsersWithArrayInput**](docs/SwagUserApi.md#createUsersWithArrayInput) | **POST** /user/createWithArray | Creates list of users with given input array
+*SwagUserApi* | [**createUsersWithListInput**](docs/SwagUserApi.md#createUsersWithListInput) | **POST** /user/createWithList | Creates list of users with given input array
+*SwagUserApi* | [**deleteUser**](docs/SwagUserApi.md#deleteUser) | **DELETE** /user/{username} | Delete user
+*SwagUserApi* | [**getUserByName**](docs/SwagUserApi.md#getUserByName) | **GET** /user/{username} | Get user by user name
+*SwagUserApi* | [**loginUser**](docs/SwagUserApi.md#loginUser) | **GET** /user/login | Logs user into the system
+*SwagUserApi* | [**logoutUser**](docs/SwagUserApi.md#logoutUser) | **GET** /user/logout | Logs out current logged in user session
+*SwagUserApi* | [**updateUser**](docs/SwagUserApi.md#updateUser) | **PUT** /user/{username} | Updated user
+
+
+## Documentation for Models
+
+ - [SwagApiResponse](docs/SwagApiResponse.md)
+ - [SwagCategory](docs/SwagCategory.md)
+ - [SwagOrder](docs/SwagOrder.md)
+ - [SwagPet](docs/SwagPet.md)
+ - [SwagTag](docs/SwagTag.md)
+ - [SwagUser](docs/SwagUser.md)
+
+
+## Documentation for Authorization
+
+Authentication schemes defined for the API:
+### api_key
+
+- **Type**: API key
+- **API key parameter name**: api_key
+- **Location**: HTTP header
+
+### petstore_auth
+
+- **Type**: OAuth
+- **Flow**: implicit
+- **Authorizatoin URL**: http://petstore.swagger.io/api/oauth/dialog
+- **Scopes**:
+ - write:pets: modify pets in your account
+ - read:pets: read your pets
+
+
+## Author
+
+apiteam@swagger.io
+
@@ -0,0 +1,37 @@
+# build.properties
+#
+
+# The first three properties (SF_USERNAME, SF_PASSWORD, SF_SESSIONID) may either be specified below
+# or set from environment variables of the same names. The remaining non-uppercase properties, which
+# have the "sf." prefix (e.g.: sf.serverurl) may only be specified in this file and not from
+# environment variables.
+
+# Required if sessionId isn’t specified. The Salesforce username for login. The username associated
+# with this connection must have the “Modify All Data” permission. Typically, this is only enabled
+# for System Administrator users.
+#
+# SF_USERNAME = username@example.com
+
+# Required if sessionId isn’t specified. The password you use to log in to the org associated with
+# this project. If you are using a security token, paste the 25-digit token value to the end of your
+# password.
+#
+# SF_PASSWORD = password123
+
+# Required if username and password aren’t specified. The ID of an active Salesforce session or the
+# OAuth access token. A session is created after a user logs in to Salesforce successfully with a
+# username and password. Use a session ID for logging in to an existing session instead of creating
+# a new session. Alternatively, use an access token for OAuth authentication. For more information,
+# see Authenticating Apps with OAuth in the Salesforce Help.
+#
+# SF_SESSIONID = 0000...
+
+# Optional. The Salesforce server URL (if blank, defaults to login.salesforce.com). To connect to a
+# sandbox instance, change this to test.salesforce.com.
+#
+sf.serverurl = test.salesforce.com
+
+# Optional. Defaults to 200. The number of times to poll the server for the results of the deploy
+# request. Note that deployment can succeed even if you stop waiting.
+#
+sf.maxPoll = 200
Oops, something went wrong.

0 comments on commit 7edf744

Please sign in to comment.