Swagger: AS3 sdk - Using another template for output wrappers

This commit is contained in:
Deepak Michael 2011-08-18 10:33:29 +05:30
parent 63e2368040
commit 27697afa9f
2 changed files with 36 additions and 2 deletions

View File

@ -0,0 +1,29 @@
package $packageName$ {
$imports:{ import |
import $import$;
}$
/**
* $model.description$
* NOTE: This class is auto generated by the drive code generator program so please do not edit the class manually.
* @author deepak
*
*/
public class $className$ extends $extends$ {
$fields:{ field |
/**
* $field.description$
* $if(field.required)$@Required$endif$
* $if(field.allowableValues)$[AllowableValues(value="$field.allowedValuesString$"]$endif$
*/
$if(!field.fieldDefinition.collectionItemType)$
[XmlElement(name="$field.fieldDefinition.name$")]$endif$
$if(field.fieldDefinition.collectionItemType)$
[XmlElements(name="$field.fieldDefinition.collectionItemName$", type="$field.fieldDefinition.collectionItemType$")]$endif$
public var $field.fieldDefinition.name$: $field.fieldDefinition.returnType$ $field.fieldDefinition.initialization$;$\r$}$
}
}

View File

@ -46,6 +46,7 @@ public class LibraryCodeGenerator {
private static String MODEL_OBJECT_TEMPLATE = "ModelObject"; private static String MODEL_OBJECT_TEMPLATE = "ModelObject";
private static String API_OBJECT_TEMPLATE = "ResourceObject"; private static String API_OBJECT_TEMPLATE = "ResourceObject";
private static final String ENUM_OBJECT_TEMPLATE = "EnumObject"; private static final String ENUM_OBJECT_TEMPLATE = "EnumObject";
private static final String WRAPPER_OBJECT_TEMPLATE = "WrapperObject";
private static final String PACKAGE_NAME = "packageName"; private static final String PACKAGE_NAME = "packageName";
private ApiConfiguration config = null; private ApiConfiguration config = null;
@ -273,7 +274,11 @@ public class LibraryCodeGenerator {
private void generateOutputWrappers(List<Resource> resources, StringTemplateGroup templateGroup) { private void generateOutputWrappers(List<Resource> resources, StringTemplateGroup templateGroup) {
List<String> generatedClasses = new ArrayList<String>(); List<String> generatedClasses = new ArrayList<String>();
StringTemplate template; StringTemplate template = templateGroup.getInstanceOf(WRAPPER_OBJECT_TEMPLATE);
if(template == null){
System.out.println("WrapperObject template not found to generate output wrappers");
return;
}
for(Resource resource: resources) { for(Resource resource: resources) {
if(resource.getEndPoints() != null) { if(resource.getEndPoints() != null) {
@ -298,7 +303,7 @@ public class LibraryCodeGenerator {
} }
} }
} }
template = templateGroup.getInstanceOf(MODEL_OBJECT_TEMPLATE); template = templateGroup.getInstanceOf(WRAPPER_OBJECT_TEMPLATE);
template.setAttribute("fields", model.getFields()); template.setAttribute("fields", model.getFields());
template.setAttribute("imports", imports); template.setAttribute("imports", imports);