Skip to content

Commit d8ec6b2

Browse files
authored
[Apex] migrating to OpenAPI Generator project (#692)
* [apex] migrating to OpenAPITools * migrate apex to openapi-generator
1 parent 8246549 commit d8ec6b2

49 files changed

Lines changed: 1005 additions & 589 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractApexCodegen.java

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

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ApexClientCodegen.java

Lines changed: 81 additions & 407 deletions
Large diffs are not rendered by default.

modules/openapi-generator/src/main/resources/apex/README_sfdx.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ Class | Method | HTTP request | Description
100100
{{/isBasic}}
101101
{{#isOAuth}}- **Type**: OAuth
102102
- **Flow**: {{flow}}
103-
- **Authorizatoin URL**: {{authorizationUrl}}
103+
- **Authorization URL**: {{authorizationUrl}}
104104
- **Scopes**: {{^scopes}}N/A{{/scopes}}
105105
{{#scopes}} - {{scope}}: {{description}}
106106
{{/scopes}}

modules/openapi-generator/src/main/resources/apex/Swagger.cls

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -271,9 +271,7 @@ public class Swagger {
271271
@TestVisible
272272
protected virtual void applyAuthentication(List<String> names, Map<String, Object> headers,
273273
List<Param> query) {
274-
for (Authentication auth : getAuthMethods(names)) {
275-
auth.apply(headers, query);
276-
}
274+
// TODO Check auth methods
277275
}
278276

279277
@TestVisible
@@ -298,7 +296,7 @@ public class Swagger {
298296
protected virtual String toEndpoint(String path, Map<String, Object> params,
299297
List<Param> queryParams) {
300298
String query = '?' + paramsToString(queryParams);
301-
return '"callout:' + calloutName + toPath(path, params) + query.removeEnd('?') + '""';
299+
return 'callout:' + calloutName + toPath(path, params) + query.removeEnd('?');
302300
}
303301

304302
@TestVisible

modules/openapi-generator/src/main/resources/apex/SwaggerTest.cls

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ private class SwaggerTest {
292292
new Swagger.Param('foo', 'bar'),
293293
new Swagger.Param('bat', '123')
294294
};
295-
String expected = 'https://www.mccombs.utexas.edu/departments/finance?foo=bar&bat=123';
295+
String expected = 'callout:Winkelmeyer/departments/finance?foo=bar&bat=123';
296296
String actual = client.toEndpoint(path, params, queryParams);
297297
System.assertEquals(expected, actual);
298298
}
@@ -360,7 +360,8 @@ private class SwaggerTest {
360360

361361
private class MockApiClient extends Swagger.ApiClient {
362362
public MockApiClient() {
363-
basePath = 'https://www.mccombs.utexas.edu';
363+
basePath = 'https://blog.winkelmeyer.com';
364+
calloutName = 'Winkelmeyer';
364365
}
365366
}
366367
}

modules/openapi-generator/src/main/resources/apex/api.mustache

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,13 @@ public class {{classname}} {
8888
{{/headerParams}}
8989
}{{/hasHeaderParams}}{{^hasHeaderParams}}(){{/hasHeaderParams}},
9090
{{#hasProduces}}
91-
new List<String>{ {{#produces}}'{{{mediaType}}}'{{#hasMore}}, {{/hasMore}}{{/produces}} },
91+
new List<String>{ {{#produces}}'{{mediaType}}'{{#hasMore}}, {{/hasMore}}{{/produces}} },
9292
{{/hasProduces}}
9393
{{^hasProduces}}
9494
new List<String>(),
9595
{{/hasProduces}}
9696
{{#hasConsumes}}
97-
new List<String>{ {{#consumes}}'{{{mediaType}}}'{{#hasMore}}, {{/hasMore}}{{/consumes}} },
97+
new List<String>{ {{#consumes}}'{{mediaType}}'{{#hasMore}}, {{/hasMore}}{{/consumes}} },
9898
{{/hasConsumes}}
9999
{{^hasConsumes}}
100100
new List<String>(),

modules/openapi-generator/src/main/resources/apex/api_test.mustache

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,19 @@ private class {{classname}}Test {
3434
{{{returnType}}} response;
3535
{{{returnType}}} expectedResponse;
3636
{{/returnType}}
37+
String js = '';
3738

3839
{{#authMethods}}
3940
client = new {{classPrefix}}Client();
4041
api = new {{classname}}(client);{{#isApiKey}}
41-
((Swagger.ApiKeyAuth){{/isApiKey}} client.getAuthentication('{{name}}');
42-
{{#isApiKey}}
43-
client.setApiKey('foo-bar-api-key');
42+
((Swagger.ApiKeyAuth)client.getAuthentication('{{name}}')).setApiKey('foo-bar-api-key');
4443
{{/isApiKey}}
4544
{{#examples}}
4645

46+
47+
js = JSON.serialize({{{deserializedExample}}});
4748
res.setHeader('Content-Type', '{{contentType}}');
48-
res.setBody('{{{example}}}');
49+
res.setBody(js);
4950
expectedResponse = {{{deserializedExample}}};
5051
response = ({{{returnType}}}) api.{{operationId}}({{#hasParams}}params{{/hasParams}});
5152
System.assertEquals(expectedResponse, response);
@@ -59,8 +60,9 @@ private class {{classname}}Test {
5960
api = new {{classname}}(new {{classPrefix}}Client());
6061
{{#examples}}
6162

63+
js = JSON.serialize({{{deserializedExample}}});
6264
res.setHeader('Content-Type', '{{contentType}}');
63-
res.setBody('{{{example}}}');
65+
res.setBody(js);
6466
expectedResponse = {{{deserializedExample}}};
6567
response = ({{{returnType}}}) api.{{operationId}}({{#hasParams}}params{{/hasParams}});
6668
System.assertEquals(expectedResponse, response);

modules/openapi-generator/src/main/resources/apex/git_push.sh.mustache

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/sh
22
# ref: https://help.github.com/articles/adding-an-existing-project-to-github-using-the-command-line/
33
#
4-
# Usage example: /bin/sh ./git_push.sh wing328 openapi-pestore-perl "minor update"
4+
# Usage example: /bin/sh ./git_push.sh wing328 swagger-petstore-perl "minor update"
55

66
git_user_id=$1
77
git_repo_id=$2
@@ -36,7 +36,7 @@ git_remote=`git remote`
3636
if [ "$git_remote" = "" ]; then # git remote not defined
3737

3838
if [ "$GIT_TOKEN" = "" ]; then
39-
echo "[INFO] \$GIT_TOKEN (environment variable) is not set. Using the git credential in your environment."
39+
echo "[INFO] \$GIT_TOKEN (environment variable) is not set. Using the git crediential in your environment."
4040
git remote add origin https://github.com/${git_user_id}/${git_repo_id}.git
4141
else
4242
git remote add origin https://${git_user_id}:${GIT_TOKEN}@github.com/${git_user_id}/${git_repo_id}.git

modules/openapi-generator/src/main/resources/apex/licenseInfo.mustache

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* {{#version}}OpenAPI spec version: {{{version}}}{{/version}}
66
* {{#infoEmail}}Contact: {{{infoEmail}}}{{/infoEmail}}
77
*
8-
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
9-
* https://openapi-generator.tech
8+
* NOTE: This class is auto generated by the swagger code generator program.
9+
* https://github.com/swagger-api/swagger-codegen.git
1010
* Do not edit the class manually.
1111
*/

modules/openapi-generator/src/main/resources/apex/model_test.mustache

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,6 @@ private class {{classname}}Test {
4545
System.assert({{classVarName}}4.equals({{classVarName}}3));
4646
}
4747

48-
@isTest
49-
private static void notEqualsUnlikeInstance() {
50-
{{classname}} {{classVarName}}1 = {{classname}}.getExample();
51-
{{classname}} {{classVarName}}2 = new {{classname}}();
52-
53-
System.assertEquals(false, {{classVarName}}1.equals({{classVarName}}2));
54-
System.assertEquals(false, {{classVarName}}2.equals({{classVarName}}1));
55-
}
56-
5748
@isTest
5849
private static void notEqualsDifferentType() {
5950
{{classname}} {{classVarName}}1 = {{classname}}.getExample();

0 commit comments

Comments
 (0)