Skip to content

Commit a0482a4

Browse files
authored
Add support for Apex API client (#5669)
* Salesforce Apex support * typo in function name * comments for clarification * DoubleProperty and FloatProperty are both DecimalProperty * test models with default and provided example property values * adding some more default example values
1 parent ef2028e commit a0482a4

28 files changed

+3563
-0
lines changed

modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/ApexClientCodegen.java

Lines changed: 454 additions & 0 deletions
Large diffs are not rendered by default.

modules/swagger-codegen/src/main/resources/META-INF/services/io.swagger.codegen.CodegenConfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
io.swagger.codegen.languages.AndroidClientCodegen
2+
io.swagger.codegen.languages.ApexClientCodegen
23
io.swagger.codegen.languages.AspNet5ServerCodegen
34
io.swagger.codegen.languages.AspNetCoreServerCodegen
45
io.swagger.codegen.languages.AsyncScalaClientCodegen
Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
# {{appName}} API Client
2+
{{#appDescription}}
3+
4+
{{{appDescription}}}
5+
{{/appDescription}}
6+
7+
## Requirements
8+
9+
- [Java 8 JDK](http://www.oracle.com/technetwork/java/javase/downloads/index.html)
10+
- [Apache Ant](http://ant.apache.org/) version 1.6 or later
11+
- [Force.com Migration Tool](https://developer.salesforce.com/docs/atlas.en-us.daas.meta/daas/forcemigrationtool_install.htm)
12+
- 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`)
13+
- `ANT_HOME` and `JAVA_HOME` environment variables must be set accordingly
14+
- On Windows, `JAVA_HOME` will probably look something like this:
15+
16+
```
17+
JAVA_HOME = C:\Program Files\Java\jdk1.8.0_121
18+
```
19+
20+
- The `bin` directory from Ant must be on your `PATH`
21+
22+
If everything is set correctly:
23+
24+
- Running `java -version` in a command prompt should output something like:
25+
26+
```bash
27+
java version "1.8.0_121"
28+
Java(TM) SE Runtime Environment (build 1.8.0_121-b13)
29+
Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)
30+
```
31+
32+
- Running `ant -version` should output something like:
33+
34+
```bash
35+
Apache Ant(TM) version 1.10.1 compiled on February 2 2017
36+
```
37+
38+
For more information, see <https://developer.salesforce.com/docs/atlas.en-us.daas.meta/daas/forcemigrationtool_prereq.htm>
39+
40+
## Installation
41+
{{#gitRepoId}}{{#gitUserId}}
42+
43+
1. Clone the repo from GitHub
44+
45+
```bash
46+
$ git clone [email protected]:{{gitUserId}}/{{gitRepoId}}.git
47+
```
48+
49+
Or, [download](https://github.com/{{gitUserId}}/{{gitRepoId}}/archive/master.zip) the repo as a ZIP and extract it to `{{gitRepoId}}`
50+
{{/gitUserId}}{{/gitRepoId}}
51+
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.
52+
53+
`SF_SESSIONID` may also be set instead of `SF_USERNAME` and `SF_PASSWORD` (more info in `build.properties`)
54+
55+
2. Open up a command prompt in the root project directory {{#gitRepoId}}`{{gitRepoId}}` {{/gitRepoId}}(the same directory as this README and `build.xml`)
56+
3. Deploy to your Salesforce org
57+
58+
```bash
59+
$ ant deploy
60+
```
61+
62+
This command will:
63+
64+
- deploy all classes in the `deploy/classes` directory to your Salesforce org
65+
- create a new [unmanaged package](https://help.salesforce.com/articleView?id=sharing_apps.htm) called **{{appName}} API Client**
66+
- execute all of the unit tests included in this package (at least 75% code coverage required)
67+
- create a new [remote site](https://help.salesforce.com/articleView?id=configuring_remoteproxy.htm) called **{{sanitizedName}}** configured for the endpoint: <{{basePath}}>
68+
- rolls back any changes upon any error
69+
70+
A successful deployment will look like this:
71+
72+
```bash
73+
[sf:deploy] Request Status: Succeeded
74+
[sf:deploy] *********** DEPLOYMENT SUCCEEDED ***********
75+
[sf:deploy] Finished request 0Af7A00000Ebd5oSAB successfully.
76+
77+
BUILD SUCCESSFUL
78+
Total time: 34 seconds
79+
```
80+
81+
### Test deployment only
82+
83+
To perform a test deployment without committing changes:
84+
85+
```bash
86+
$ ant deployCheckOnly
87+
```
88+
89+
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.
90+
91+
### Uninstallation
92+
93+
```bash
94+
$ ant undeploy
95+
```
96+
97+
Removes all classes and the Remote Site created by this package.
98+
99+
## Getting Started
100+
101+
Please follow the [installation](#installation) instruction and execute the following Apex code:
102+
103+
```java{{#apiInfo}}{{#apis}}{{#-first}}{{#operations}}{{#operation}}{{#-first}}
104+
{{classname}} api = new {{classname}}();
105+
{{#hasAuthMethods}}
106+
{{classPrefix}}Client client = api.getClient();
107+
{{#authMethods}}{{#isBasic}}
108+
// Configure HTTP basic authorization: {{{name}}}
109+
HttpBasicAuth {{{name}}} = (HttpBasicAuth) client.getAuthentication('{{{name}}}');
110+
{{{name}}}.setUsername('YOUR USERNAME');
111+
{{{name}}}.setPassword('YOUR PASSWORD');
112+
113+
// You can also set your username and password in one line
114+
{{{name}}}.setCredentials('YOUR USERNAME', 'YOUR PASSWORD');{{/isBasic}}{{#isApiKey}}
115+
// Configure API key authorization: {{{name}}}
116+
ApiKeyAuth {{{name}}} = (ApiKeyAuth) client.getAuthentication('{{{name}}}');
117+
{{{name}}}.setApiKey('YOUR API KEY');{{/isApiKey}}{{#isOAuth}}
118+
// Configure OAuth2 access token for authorization: {{{name}}}
119+
Swagger.OAuth {{{name}}} = (Swagger.OAuth) client.getAuthentication('{{{name}}}');
120+
{{{name}}}.setAccessToken('YOUR ACCESS TOKEN');{{/isOAuth}}
121+
{{/authMethods}}
122+
{{/hasAuthMethods}}
123+
{{#hasParams}}
124+
125+
Map<String, Object> params = new Map<String, Object>{
126+
{{#allParams}}
127+
'{{{paramName}}}' => {{{example}}}{{#hasMore}},{{/hasMore}}
128+
{{/allParams}}
129+
};
130+
{{/hasParams}}
131+
132+
try {
133+
// cross your fingers
134+
{{#returnType}}{{{returnType}}} result = {{/returnType}}api.{{{operationId}}}({{#hasParams}}params{{/hasParams}});
135+
{{#returnType}}
136+
System.debug(result);
137+
{{/returnType}}
138+
} catch (Swagger.ApiException e) {
139+
// ...handle your exceptions
140+
}{{/-first}}{{/operation}}{{/operations}}{{/-first}}{{/apis}}{{/apiInfo}}
141+
```
142+
143+
## Documentation for API Endpoints
144+
145+
All URIs are relative to *{{basePath}}*
146+
147+
Class | Method | HTTP request | Description
148+
------------ | ------------- | ------------- | -------------
149+
{{#apiInfo}}{{#apis}}{{#operations}}{{#operation}}*{{classname}}* | [**{{operationId}}**]({{apiDocPath}}{{classname}}.md#{{operationId}}) | **{{httpMethod}}** {{path}} | {{#summary}}{{summary}}{{/summary}}
150+
{{/operation}}{{/operations}}{{/apis}}{{/apiInfo}}
151+
152+
## Documentation for Models
153+
154+
{{#models}}{{#model}} - [{{classname}}]({{modelDocPath}}{{classname}}.md)
155+
{{/model}}{{/models}}
156+
157+
## Documentation for Authorization
158+
159+
{{^authMethods}}All endpoints do not require authorization.
160+
{{/authMethods}}Authentication schemes defined for the API:
161+
{{#authMethods}}### {{name}}
162+
163+
{{#isApiKey}}- **Type**: API key
164+
- **API key parameter name**: {{keyParamName}}
165+
- **Location**: {{#isKeyInQuery}}URL query string{{/isKeyInQuery}}{{#isKeyInHeader}}HTTP header{{/isKeyInHeader}}
166+
{{/isApiKey}}
167+
{{#isBasic}}- **Type**: HTTP basic authentication
168+
{{/isBasic}}
169+
{{#isOAuth}}- **Type**: OAuth
170+
- **Flow**: {{flow}}
171+
- **Authorizatoin URL**: {{authorizationUrl}}
172+
- **Scopes**: {{^scopes}}N/A{{/scopes}}
173+
{{#scopes}} - {{scope}}: {{description}}
174+
{{/scopes}}
175+
{{/isOAuth}}
176+
177+
{{/authMethods}}
178+
179+
## Author
180+
181+
{{#apiInfo}}{{#apis}}{{^hasMore}}{{infoEmail}}
182+
{{/hasMore}}{{/apis}}{{/apiInfo}}

0 commit comments

Comments
 (0)