Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Apex] migrating to OpenAPI Generator project #692

Merged
merged 2 commits into from
Jul 31, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ Class | Method | HTTP request | Description
{{/isBasic}}
{{#isOAuth}}- **Type**: OAuth
- **Flow**: {{flow}}
- **Authorizatoin URL**: {{authorizationUrl}}
- **Authorization URL**: {{authorizationUrl}}
- **Scopes**: {{^scopes}}N/A{{/scopes}}
{{#scopes}} - {{scope}}: {{description}}
{{/scopes}}
Expand Down
6 changes: 2 additions & 4 deletions modules/openapi-generator/src/main/resources/apex/Swagger.cls
Original file line number Diff line number Diff line change
Expand Up @@ -271,9 +271,7 @@ public class Swagger {
@TestVisible
protected virtual void applyAuthentication(List<String> names, Map<String, Object> headers,
List<Param> query) {
for (Authentication auth : getAuthMethods(names)) {
auth.apply(headers, query);
}
// TODO Check auth methods
}

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

@TestVisible
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ private class SwaggerTest {
new Swagger.Param('foo', 'bar'),
new Swagger.Param('bat', '123')
};
String expected = 'https://www.mccombs.utexas.edu/departments/finance?foo=bar&bat=123';
String expected = 'callout:Winkelmeyer/departments/finance?foo=bar&bat=123';
String actual = client.toEndpoint(path, params, queryParams);
System.assertEquals(expected, actual);
}
Expand Down Expand Up @@ -360,7 +360,8 @@ private class SwaggerTest {

private class MockApiClient extends Swagger.ApiClient {
public MockApiClient() {
basePath = 'https://www.mccombs.utexas.edu';
basePath = 'https://blog.winkelmeyer.com';
calloutName = 'Winkelmeyer';
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,13 @@ public class {{classname}} {
{{/headerParams}}
}{{/hasHeaderParams}}{{^hasHeaderParams}}(){{/hasHeaderParams}},
{{#hasProduces}}
new List<String>{ {{#produces}}'{{{mediaType}}}'{{#hasMore}}, {{/hasMore}}{{/produces}} },
new List<String>{ {{#produces}}'{{mediaType}}'{{#hasMore}}, {{/hasMore}}{{/produces}} },
{{/hasProduces}}
{{^hasProduces}}
new List<String>(),
{{/hasProduces}}
{{#hasConsumes}}
new List<String>{ {{#consumes}}'{{{mediaType}}}'{{#hasMore}}, {{/hasMore}}{{/consumes}} },
new List<String>{ {{#consumes}}'{{mediaType}}'{{#hasMore}}, {{/hasMore}}{{/consumes}} },
{{/hasConsumes}}
{{^hasConsumes}}
new List<String>(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,19 @@ private class {{classname}}Test {
{{{returnType}}} response;
{{{returnType}}} expectedResponse;
{{/returnType}}
String js = '';

{{#authMethods}}
client = new {{classPrefix}}Client();
api = new {{classname}}(client);{{#isApiKey}}
((Swagger.ApiKeyAuth){{/isApiKey}} client.getAuthentication('{{name}}');
{{#isApiKey}}
client.setApiKey('foo-bar-api-key');
((Swagger.ApiKeyAuth)client.getAuthentication('{{name}}')).setApiKey('foo-bar-api-key');
{{/isApiKey}}
{{#examples}}


js = JSON.serialize({{{deserializedExample}}});
res.setHeader('Content-Type', '{{contentType}}');
res.setBody('{{{example}}}');
res.setBody(js);
expectedResponse = {{{deserializedExample}}};
response = ({{{returnType}}}) api.{{operationId}}({{#hasParams}}params{{/hasParams}});
System.assertEquals(expectedResponse, response);
Expand All @@ -59,8 +60,9 @@ private class {{classname}}Test {
api = new {{classname}}(new {{classPrefix}}Client());
{{#examples}}

js = JSON.serialize({{{deserializedExample}}});
res.setHeader('Content-Type', '{{contentType}}');
res.setBody('{{{example}}}');
res.setBody(js);
expectedResponse = {{{deserializedExample}}};
response = ({{{returnType}}}) api.{{operationId}}({{#hasParams}}params{{/hasParams}});
System.assertEquals(expectedResponse, response);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/sh
# ref: https://help.github.com/articles/adding-an-existing-project-to-github-using-the-command-line/
#
# Usage example: /bin/sh ./git_push.sh wing328 openapi-pestore-perl "minor update"
# Usage example: /bin/sh ./git_push.sh wing328 swagger-petstore-perl "minor update"

git_user_id=$1
git_repo_id=$2
Expand Down Expand Up @@ -36,7 +36,7 @@ git_remote=`git remote`
if [ "$git_remote" = "" ]; then # git remote not defined

if [ "$GIT_TOKEN" = "" ]; then
echo "[INFO] \$GIT_TOKEN (environment variable) is not set. Using the git credential in your environment."
echo "[INFO] \$GIT_TOKEN (environment variable) is not set. Using the git crediential in your environment."
git remote add origin https://github.com/${git_user_id}/${git_repo_id}.git
else
git remote add origin https://${git_user_id}:${GIT_TOKEN}@github.com/${git_user_id}/${git_repo_id}.git
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* {{#version}}OpenAPI spec version: {{{version}}}{{/version}}
* {{#infoEmail}}Contact: {{{infoEmail}}}{{/infoEmail}}
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* NOTE: This class is auto generated by the swagger code generator program.
* https://github.com/swagger-api/swagger-codegen.git
* Do not edit the class manually.
*/
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,6 @@ private class {{classname}}Test {
System.assert({{classVarName}}4.equals({{classVarName}}3));
}

@isTest
private static void notEqualsUnlikeInstance() {
{{classname}} {{classVarName}}1 = {{classname}}.getExample();
{{classname}} {{classVarName}}2 = new {{classname}}();

System.assertEquals(false, {{classVarName}}1.equals({{classVarName}}2));
System.assertEquals(false, {{classVarName}}2.equals({{classVarName}}1));
}

@isTest
private static void notEqualsDifferentType() {
{{classname}} {{classVarName}}1 = {{classname}}.getExample();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<fullName>{{appName}} API Client</fullName>
<description>Client library for calling the {{appName}} API.{{#appDescription}}
{{{appDescription}}}{{/appDescription}}
Generated with OpenAPI Generator (https://openapi-generator.tech)</description>
Generated with Swagger Codegen (github.com/swagger-api/swagger-codegen)</description>
<types>
{{#apiInfo}}
{{#apis}}
Expand Down
19 changes: 11 additions & 8 deletions modules/openapi-generator/src/main/resources/apex/pojo.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ public class {{classname}}{{#parent}} extends {{{parent}}}{{/parent}}{{#interfac
{{#isEnum}}
{{^isContainer}}
{{>modelInnerEnum}}
{{/isContainer}}
{{#isContainer}}
{{#mostInnerItems}}
{{>modelInnerEnum}}
{{/mostInnerItems}}
{{/isContainer}}
{{/isEnum}}
{{#items.isEnum}}
{{#items}}
{{^isContainer}}
{{>modelInnerEnum}}
{{/isContainer}}
{{/items}}
{{/items.isEnum}}
/**
{{#description}}
* {{{description}}}
Expand Down Expand Up @@ -58,16 +60,17 @@ public class {{classname}}{{#parent}} extends {{{parent}}}{{/parent}}{{#interfac
public static {{classname}} getExample() {
{{classname}} {{classVarName}} = new {{classname}}();
{{#vars}}
{{classVarName}}.{{name}} = {{{example}}};
{{#example}}{{classVarName}}.{{name}} = {{{example}}};{{/example}}
{{/vars}}
return {{classVarName}};
}

public Boolean equals(Object obj) {
if (obj instanceof {{classname}}) {
if (obj instanceof {{classname}}) { {{#hasVars}}
{{classname}} {{classVarName}} = ({{classname}}) obj;
return {{#vars}}this.{{name}} == {{classVarName}}.{{name}}{{#hasMore}}
&& {{/hasMore}}{{/vars}};
&& {{/hasMore}}{{/vars}};{{/hasVars}}{{^hasVars}}
return true;{{/hasVars}}
}
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
{{#vars}}**{{name}}** | {{#isEnum}}[**{{datatypeWithEnum}}**](#{{datatypeWithEnum}}){{/isEnum}}{{^isEnum}}{{#isPrimitiveType}}**{{dataType}}**{{/isPrimitiveType}}{{^isPrimitiveType}}[**{{dataType}}**]({{complexType}}.md){{/isPrimitiveType}}{{/isEnum}} | {{description}} | {{^required}} [optional]{{/required}}{{#readOnly}} [readonly]{{/readOnly}}
{{#vars}}**{{name}}** | {{#isEnum}}[**{{datatypeWithEnum}}**](#{{datatypeWithEnum}}){{/isEnum}}{{^isEnum}}{{#isPrimitiveType}}**{{datatype}}**{{/isPrimitiveType}}{{^isPrimitiveType}}[**{{datatype}}**]({{complexType}}.md){{/isPrimitiveType}}{{/isEnum}} | {{description}} | {{^required}} [optional]{{/required}}{{#readOnly}} [readonly]{{/readOnly}}
{{/vars}}
{{#vars}}{{#isEnum}}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"orgName": "muenzpraeger - René Winkelmeyer",
"edition": "Developer",
"orgPreferences": {
"enabled": ["S1DesktopEnabled"],
"disabled": ["S1EncryptedStoragePref2"]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"packageDirectories": [
{
"path": "force-app",
"default": true
}
],
"namespace": "",
"sfdcLoginUrl": "https://login.salesforce.com",
"sourceApiVersion": "{{apiVersion}}"
}
10 changes: 0 additions & 10 deletions modules/openapi-generator/src/main/resources/apex/sfdx.mustache

This file was deleted.

6 changes: 3 additions & 3 deletions samples/client/petstore/apex/.openapi-generator-ignore
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# OpenAPI Generator Ignore
# Generated by openapi-generator https://github.com/openapitools/openapi-generator
# 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 OpenAPI Generator to ignore just this file by uncommenting the following line:
# 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 (*):
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/apex/.openapi-generator/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.0.0-SNAPSHOT
3.2.0-SNAPSHOT
1 change: 1 addition & 0 deletions samples/client/petstore/apex/.swagger-codegen/VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2.4.0-SNAPSHOT
Loading