Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class FlashClientCodegen extends DefaultCodegen implements CodegenConfig
protected String packageVersion;

protected String invokerPackage = "io.swagger";
protected String sourceFolder = "src/main/flex";
protected String sourceFolder = "flash";

public FlashClientCodegen() {
super();
Expand Down Expand Up @@ -83,7 +83,7 @@ public FlashClientCodegen() {
.defaultValue("1.0.0"));
cliOptions.add(new CliOption(CodegenConstants.INVOKER_PACKAGE, CodegenConstants.INVOKER_PACKAGE_DESC));
cliOptions.add(new CliOption(CodegenConstants.SOURCE_FOLDER, "source folder for generated " +
"code. e.g. src/main/flex"));
"code. e.g. flash"));

}

Expand Down Expand Up @@ -124,23 +124,23 @@ public void processOpts() {
//modelPackage = invokerPackage + File.separatorChar + "client" + File.separatorChar + "model";
//apiPackage = invokerPackage + File.separatorChar + "client" + File.separatorChar + "api";

final String invokerFolder = (sourceFolder + File.separator + invokerPackage + File.separator
+ "swagger" + File.separator).replace(".", File.separator).replace('.', File.separatorChar);
final String invokerFolder = (sourceFolder + File.separator + "src/" + invokerPackage + File.separator).replace(".", File.separator).replace('.', File.separatorChar);

supportingFiles.add(new SupportingFile("ApiInvoker.as", invokerFolder + "common", "ApiInvoker.as"));
supportingFiles.add(new SupportingFile("ApiUrlHelper.as", invokerFolder + "common", "ApiUrlHelper.as"));
supportingFiles.add(new SupportingFile("ApiUserCredentials.as", invokerFolder + "common", "ApiUserCredentials.as"));
supportingFiles.add(new SupportingFile("ListWrapper.as", invokerFolder + "common", "ListWrapper.as"));
supportingFiles.add(new SupportingFile("SwaggerApi.as", invokerFolder + "common", "SwaggerApi.as"));
supportingFiles.add(new SupportingFile("XMLWriter.as", invokerFolder + "common", "XMLWriter.as"));
supportingFiles.add(new SupportingFile("ApiError.as", invokerFolder + "exception", "ApiErrors.as"));
supportingFiles.add(new SupportingFile("ApiError.as", invokerFolder + "exception", "ApiError.as"));
supportingFiles.add(new SupportingFile("ApiErrorCodes.as", invokerFolder + "exception", "ApiErrorCodes.as"));
supportingFiles.add(new SupportingFile("ApiClientEvent.as", invokerFolder + "event", "ApiClientEvent.as"));
supportingFiles.add(new SupportingFile("Response.as", invokerFolder + "event", "Response.as"));
supportingFiles.add(new SupportingFile("build.properties", sourceFolder, "build.properties"));
supportingFiles.add(new SupportingFile("build.xml", sourceFolder, "build.xml"));
supportingFiles.add(new SupportingFile("AirExecutorApp-app.xml", sourceFolder + File.separatorChar
+ "bin", "AirExecutorApp-app.xml"));
supportingFiles.add(new SupportingFile("README.txt", sourceFolder, "README.txt"));
//supportingFiles.add(new SupportingFile("AirExecutorApp-app.xml", sourceFolder + File.separatorChar
// + "bin", "AirExecutorApp-app.xml"));
supportingFiles.add(new SupportingFile("ASAXB-0.1.1.swc", sourceFolder + File.separatorChar
+ "lib", "ASAXB-0.1.1.swc"));
supportingFiles.add(new SupportingFile("as3corelib.swc", sourceFolder + File.separatorChar
Expand Down Expand Up @@ -181,13 +181,13 @@ public String escapeReservedWord(String name) {

@Override
public String apiFileFolder() {
return (outputFolder + File.separatorChar + sourceFolder + File.separatorChar
return (outputFolder + File.separatorChar + sourceFolder + File.separatorChar + "src/"
+ apiPackage().replace('.', File.separatorChar)).replace('/', File.separatorChar);
}

@Override
public String modelFileFolder() {
return (outputFolder + File.separatorChar + sourceFolder + File.separatorChar
return (outputFolder + File.separatorChar + sourceFolder + File.separatorChar + "src/"
+ modelPackage().replace('.', File.separatorChar)).replace('/', File.separatorChar);
}

Expand Down Expand Up @@ -253,7 +253,7 @@ public String toDefaultValue(Property p) {
} else if (p instanceof ArrayProperty) {
return "new Array()";
} else {
return "null";
return "NaN";
}
}

Expand Down
27 changes: 24 additions & 3 deletions modules/swagger-codegen/src/main/resources/flash/ApiInvoker.as
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@ package io.swagger.common {
import io.swagger.event.ApiClientEvent;
import io.swagger.event.Response;

import flash.events.EventDispatcher;
import flash.utils.*;
import mx.rpc.AsyncToken;
import mx.rpc.events.ResultEvent;
import mx.rpc.events.FaultEvent;
import mx.utils.ObjectUtil;
import mx.rpc.http.HTTPService;
import mx.messaging.messages.HTTPRequestMessage;
import mx.messaging.ChannelSet;
import mx.messaging.channels.DirectHTTPChannel;
import asaxb.xml.bind.ASAXBContext;
import asaxb.xml.bind.Unmarshaller;

public class ApiInvoker extends EventDispatcher {

private static const DELETE_DATA_DUMMY:String = "dummyDataRequiredForDeleteOverride";
Expand Down Expand Up @@ -99,7 +112,7 @@ public class ApiInvoker extends EventDispatcher {
var qualifiedClassName:String = objDescriptor.@name;
qualifiedClassName = qualifiedClassName.replace("::", ".");
var className:String = qualifiedClassName.substring(qualifiedClassName.lastIndexOf(".") + 1);
className = className().toLowerCase() + className.substring(1);
className = className.toLowerCase() + className.substring(1);
writer.xml.setName(className);

for each(property in objDescriptor.elements("variable")) {
Expand Down Expand Up @@ -178,7 +191,7 @@ public class ApiInvoker extends EventDispatcher {
httpService.useProxy = true;

var channelSet:ChannelSet = new ChannelSet();
var httpChannel:HTTPChannel = new HTTPChannel();
var httpChannel:DirectHTTPChannel = new DirectHTTPChannel("");
httpChannel.uri = ApiUrlHelper.getProxyUrl(_proxyHostName, _proxyPath);
channelSet.addChannel(httpChannel);
httpService.channelSet = channelSet;
Expand All @@ -188,6 +201,11 @@ public class ApiInvoker extends EventDispatcher {
}

private function onApiRequestResult(event:ResultEvent):void {

// I put this in comments. Here, it's trying to parse XML and it fails if it's not XML.
// Therefore, it's better to have the raw result that we can parse as we want.
// TODO: Create different parser (JSON, XML, etc.)
/*
var completionListener:Function = event.token.completionListener;
var result:Object = event.result;
var resultType:Class = event.token.returnType;
Expand All @@ -214,6 +232,9 @@ public class ApiInvoker extends EventDispatcher {
}

var response:Response = new Response(true, resultObject);
*/

var response:Response = new Response(true, event.result);
response.requestId = event.token.requestId;
var successEventType:String = event.token.completionEventType != null ? event.token.completionEventType : ApiClientEvent.SUCCESS_EVENT;

Expand Down Expand Up @@ -252,4 +273,4 @@ public class ApiInvoker extends EventDispatcher {


}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ internal class ApiUrlHelper {
}

internal static function getProxyUrl(hostName: String, proxyPath: String): String{
if (hostName(hostName.length - 1) == "/") //remove trailing slash
if (hostName..charAt(hostName.length) == "/") //remove trailing slash
{
hostName = hostName.substring(0, hostName.length - 1);
}
Expand Down
65 changes: 65 additions & 0 deletions modules/swagger-codegen/src/main/resources/flash/README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
README for the Flash application.

These instructions are given using the version 4.7 of Flash Builder.

How to use the Flash client library:

The code which is given to you is to be considered as a Library. Therefore, in Flash Builder, you have to:
1. Create an ActionScript Library Project. (Warning: If you are dealing with Files as parameter, you need to include the Adobe AIR libraries)
2. Copy the src folder from the flash library to the project.
3. Copy the lib folder.
4. Copy the build.properties and build.xml. (You can update the paths in build.properties)
5. Right+Click on the project folder and go to Properties. Then go to the tab 'ActionScript Library Build Path' and add these two SWC: 'as3corelib.swc' and 'ASAXB-0.1.1.swc'. (They are located in the folder lib)
6. Create the Flash Application

How to use the Flash client library in an application:

Using the Flash client library (especially getting the response message from the server) is a bit tricky.

The response message is given through an EventDispatcher. Therefore, you have to create an EventDispatcher and listen to the endpoints that you're calling. Below, you will find a pseudo-code explaining how to do this.

After creating an application in java, you will have a mxml file. In this mxml file, you need to declare a Script (given below) after the Declarations.

<fx:Script>
<![CDATA[

// Import the different libraries you need
// ...

// Import the io.swagger libraries
import io.swagger.common.ApiUserCredentials;
import io.swagger.event.ApiClientEvent;
import io.swagger.client.api.[[API]]; // Put your Api here.

// Variables
private var cred:ApiUserCredentials;
private var dispatcher:EventDispatcher;
private var myAPI:[[API]]; // Change [[API]] to be the real name

// Function that print in the console the message of the response
public function onEvent(event:ApiClientEvent):void {
// trace only prints when in debug mod. Be carefule about that.
trace(event.response.payload);
}

// Main function
public main():void {
// Define a dispatcher
dispatcher = new EventDispatcher();
// Define the EventListener. Fill the [[function]] by the name of the function you have in
// the API file.
dispatcher.addEventListener([[function]], onEvent);

// To create the API, you need the ApiUserCredentials and the dispatcher.
cred = new ApiUserCredentials([[host]], [[basePath]] , [[apiToken]]);
// You can add more parameters. Go see the function in ApiUserCredential.as in io/swagger/common

// Create the API
myAPI = new [[API]](cred, dispatcher); // change [[API]] to be the real name

// Now, you can use the API
myAPI.[[function]]([[PARAMETERS]]);
// Change [[function]] and add your parameters. Then, you will see the response in the console.
}
]]>
</fx:Script>
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class {{classname}} extends SwaggerApi {
/*
* Returns {{#returnType}}{{{returnType}}} {{/returnType}}{{^returnType}}void {{/returnType}}
*/
public function {{nickname}} ({{#allParams}}{{paramName}}: {{{dataType}}}{{#defaultValue}} = {{{defaultValue}}}{{/defaultValue}}{{#hasMore}}, {{/hasMore}}{{/allParams}}): String {
public function {{nickname}} ({{#allParams}}{{paramName}}: {{{dataType}}}{{#hasMore}}, {{/hasMore}}{{/allParams}}): String {
// create path and map variables
var path: String = "{{path}}".replace(/{format}/g,"xml"){{#pathParams}}.replace("{" + "{{paramName}}" + "}", getApiInvoker().escapeString({{{paramName}}})){{/pathParams}};

Expand Down
65 changes: 65 additions & 0 deletions samples/client/petstore/flash/flash/README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
README for the Flash application.

These instructions are given using the version 4.7 of Flash Builder.

How to use the Flash client library:

The code which is given to you is to be considered as a Library. Therefore, in Flash Builder, you have to:
1. Create an ActionScript Library Project. (Warning: If you are dealing with Files as parameter, you need to include the Adobe AIR libraries)
2. Copy the src folder from the flash library to the project.
3. Copy the lib folder.
4. Copy the build.properties and build.xml. (You can update the paths in build.properties)
5. Right+Click on the project folder and go to Properties. Then go to the tab 'ActionScript Library Build Path' and add these two SWC: 'as3corelib.swc' and 'ASAXB-0.1.1.swc'. (They are located in the folder lib)
6. Create the Flash Application

How to use the Flash client library in an application:

Using the Flash client library (especially getting the response message from the server) is a bit tricky.

The response message is given through an EventDispatcher. Therefore, you have to create an EventDispatcher and listen to the endpoints that you're calling. Below, you will find a pseudo-code explaining how to do this.

After creating an application in java, you will have a mxml file. In this mxml file, you need to declare a Script (given below) after the Declarations.

<fx:Script>
<![CDATA[

// Import the different libraries you need
// ...

// Import the io.swagger libraries
import io.swagger.common.ApiUserCredentials;
import io.swagger.event.ApiClientEvent;
import io.swagger.client.api.[[API]]; // Put your Api here.

// Variables
private var cred:ApiUserCredentials;
private var dispatcher:EventDispatcher;
private var myAPI:[[API]]; // Change [[API]] to be the real name

// Function that print in the console the message of the response
public function onEvent(event:ApiClientEvent):void {
// trace only prints when in debug mod. Be carefule about that.
trace(event.response.payload);
}

// Main function
public main():void {
// Define a dispatcher
dispatcher = new EventDispatcher();
// Define the EventListener. Fill the [[function]] by the name of the function you have in
// the API file.
dispatcher.addEventListener([[function]], onEvent);

// To create the API, you need the ApiUserCredentials and the dispatcher.
cred = new ApiUserCredentials([[host]], [[basePath]] , [[apiToken]]);
// You can add more parameters. Go see the function in ApiUserCredential.as in io/swagger/common

// Create the API
myAPI = new [[API]](cred, dispatcher); // change [[API]] to be the real name

// Now, you can use the API
myAPI.[[function]]([[PARAMETERS]]);
// Change [[function]] and add your parameters. Then, you will see the response in the console.
}
]]>
</fx:Script>
29 changes: 29 additions & 0 deletions samples/client/petstore/flash/flash/build.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Window and document title for the documentation
title=Sample app AS3 SDK API Documentation

#Path to the source folder where the .as files are located
sourcepath = ./src/main/flex

# Class-folders you want to search for classes to be included in the docs, seperated by spaces (for example ../com/ ../net/ )
# to include every .as and .mxml file within your project, just state ../
domainextensions = ./src/main/flex

# The Location of deployment library on your Computer (PC/Mac) for compiled SWC file
liboutputfolder = bin
liboutputfile = as3-sample-sdk.swc
libpath = lib

# The Location of the output folder for your generated documents
docsoutputfolder = asdoc

# The location of the test sources
testsourcepath = ./src/test/flex

# Home directory for flex sdk, change this to build for Mac or PC using # as comment
FLEX4_SDK_HOME = /usr/local/flex_sdk_4.1.0/
#FLEX4_SDK_HOME = /Applications/Adobe Flash Builder 4/sdks/4.1.0/

# The location of your asdoc.exe, change this to build for Mac or PC using # as comment
#asdoc.exe = C:/Program Files/Adobe/Flash Builder 4/sdks/3.5.0/bin/asdoc.exe
#asdoc.exe = /Applications/Adobe Flash Builder 4/sdks/3.5.0/bin/asdoc

Loading