Skip to content

Commit f034a7a

Browse files
committed
Merged upstream changes
2 parents c4dda12 + 424ff5f commit f034a7a

File tree

141 files changed

+11613
-2950
lines changed

Some content is hidden

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

141 files changed

+11613
-2950
lines changed

9-22-16-staging-v1_noannots.xml

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

GraphODataTemplateWriter.sln

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,4 @@ Global
3030
GlobalSection(SolutionProperties) = preSolution
3131
HideSolutionNode = FALSE
3232
EndGlobalSection
33-
EndGlobal
33+
EndGlobal

README.md

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,16 @@ Source code writers for [VIPR][vipr-source-repo] utilizing T4 templates. The Gra
77
Currently the following target languages are supported by this writer:
88
- Android
99
- CSharp
10-
- JavaScript
1110
- Objective-C
1211
- Python
12+
- TypeScript
1313

1414
# Contents
15-
- [Prerequisites](#Prerequisites)
16-
- [Getting started](#Getting-started)
17-
- [Using Vipr with this writer](#Using-Vipr-with-this-Writer)
18-
- [Using generated code](#Using-generated-code)
19-
- [Contributing](#Contributing)
20-
- [License](#License)
15+
- [Prerequisites](#prerequisites)
16+
- [Getting started](#getting-started)
17+
- [Using Vipr with this writer](#using-vipr-with-this-writer)
18+
- [Contributing](#contributing)
19+
- [License](#license)
2120

2221
## Prerequisites
2322
- [Visual Studio SDK](https://www.microsoft.com/en-us/download/details.aspx?id=40758)
@@ -36,16 +35,16 @@ For more information on submodules read [this chapter](http://git-scm.com/book/e
3635
## Using Vipr with this Writer
3736

3837
1. Build the solution in Visual Studio.
39-
2. Go to the `src\T4TemplateWriter\bin\debug` folder to find all compiled components.
38+
2. Go to the `src\GraphODataTemplateWriter\bin\debug` folder to find all compiled components.
4039
3. In that folder, modify `.config\TemplateWriterSettings.json` to specify your template mapping see [Template Writer Settings](##Template-Writer-Settings) for more details.
41-
4. Open a command prompt as administrator in the same folder and run `Vipr.exe <path-or-url-to-metadata> --writer="Graph.ODataTemplateWriter"`
40+
4. Open a command prompt as administrator in the same folder and run `Vipr.exe <path-or-url-to-metadata> --writer="GraphODataTemplateWriter"`. An example metadata file can be found in the root of this project.
4241

4342
By default, output source code will be put in a folder named "output" next to the Vipr executable.
4443

4544
## Template Writer Settings
4645
### Available Languages
4746

48-
There are four languages to choose from at the moment. Java, ObjC, CSharp, and Python. Specify which language you want to generate in the `TargetLanguage` setting.
47+
There are five languages to choose from at the moment. Java, ObjC, CSharp, TypeScript and Python. Specify which language you want to generate in the `TargetLanguage` setting.
4948

5049
### Templates
5150
You must specify a template directory under the `TemplatesDirectory` Settings. The directory can be a full path or relative to the running directory. The directory must contain a sub directory for each platform you want to generate code for. See the Templates directory for an example.

Templates/Android/BaseModel.template.tt

Lines changed: 62 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,48 @@
55
CustomT4Host host = (CustomT4Host) Host;
66
var model = host.CurrentModel;
77
CodeWriterAndroid writer = (CodeWriterAndroid) host.CodeWriter;
8+
bool logTemplateSrc = false;
89
var c = host.CurrentType;
10+
#>
11+
<# if (logTemplateSrc) { #>
12+
// Template Source: <#= TemplateName(host.TemplateFile) #>
13+
<# } #>
14+
<#+
915

10-
if (c == null)
11-
{
12-
// throw new InvalidOperationException("Unable to get the current type!");
16+
/// Is this request type a post?
17+
public bool IsPostRequestType(OdcmMethod method) {
18+
return method.IsAction()
19+
&& null != method.Parameters
20+
&& method.Parameters.Any();
21+
}
22+
23+
/// Choose an intermediate class type based on GETs/POSTs
24+
public string RequestBuilderSuperClass(OdcmObject currentType) {
25+
var isPostAction =
26+
IsPostRequestType(
27+
currentType.AsOdcmMethod()
28+
);
29+
30+
string superClass;
31+
32+
if (isPostAction) {
33+
superClass = "BasePostMethodRequestBuilder";
34+
} else {
35+
superClass = "BaseGetMethodRequestBuilder";
36+
}
37+
38+
return superClass;
39+
}
40+
41+
/// <summary>
42+
/// Get the name of the current template being processed
43+
/// </summary>
44+
/// <param name="templateFile">The full path of the current template</param>
45+
/// <returns>The template name, relative to the Templates directory.</returns>
46+
public string TemplateName(string templateFile) {
47+
return templateFile.Substring(templateFile.LastIndexOf("Templates"));
1348
}
1449

15-
#>
16-
<# //="// Template Source: '" + host.TemplateFile + "', Name: '" + c.Name + "' , TypeName: '" + TypeName(c) + "'"#>
17-
<#+
1850
public string TypeName(OdcmObject c) {
1951
if (c is OdcmMethod) {
2052
return ((OdcmMethod)c).Class.Name.ToUpperFirstChar() + c.Name.Substring(c.Name.IndexOf(".") + 1).ToUpperFirstChar();
@@ -331,14 +363,18 @@
331363
return "Base" + TypeBody(c);
332364
}
333365

366+
/// Creates an 'm' prepended name for a field
367+
/// based on its name as defined by the service $metadata
334368
public string FieldName(OdcmParameter c) {
335369
return "m" + ParamName(c).ToUpperFirstChar();
336370
}
337371

372+
/// Returns the name of the service <parameter> with the first char lowercase
338373
public string ParamName(OdcmParameter c) {
339374
return c.Name.ToLowerFirstChar();
340375
}
341376

377+
/// The Type of this param, as a string
342378
public string ParamType(OdcmParameter c) {
343379
if (c.IsCollection){
344380
return String.Format("List<{0}>", c.Type.GetTypeString());
@@ -352,19 +388,19 @@
352388
}
353389
return "Void";
354390
}
355-
356-
public string MethodParametersSignature(OdcmObject c) {
391+
392+
public string MethodParametersSignature(OdcmMethod method) {
357393
var parameterSignatureBuilder = new StringBuilder();
358-
foreach (var p in c.AsOdcmMethod().Parameters)
394+
foreach (var p in method.Parameters)
359395
{
360396
parameterSignatureBuilder.AppendFormat(", final {0} {1}", ParamType(p), ParamName(p));
361397
}
362398
return parameterSignatureBuilder.ToString();
363399
}
364400

365-
public string MethodParametersValues(OdcmObject c) {
401+
public string MethodParametersValues(OdcmMethod method) {
366402
var parameterValuesBuilder = new StringBuilder();
367-
foreach (var p in c.AsOdcmMethod().Parameters)
403+
foreach (var p in method.Parameters)
368404
{
369405
parameterValuesBuilder.AppendFormat(", {0}", ParamName(p));
370406
}
@@ -437,9 +473,15 @@
437473
return null;
438474
}
439475

476+
public string OdcmMethodReturnType(OdcmMethod method) {
477+
return method.ReturnType is OdcmPrimitiveType
478+
? method.ReturnType.GetTypeString() : method.ReturnType.Name.ToCheckedCase();
479+
}
480+
440481
public string CollectionPageGeneric(OdcmObject c) {
441482
if (c is OdcmMethod) {
442-
return "<" + ClassTypeName(c) + ", " + ITypeCollectionRequestBuilder(c) + ">";
483+
string returnType = OdcmMethodReturnType(c as OdcmMethod);
484+
return "<" + returnType + ", " + ITypeCollectionRequestBuilder(c) + ">";
443485
}
444486
return "<" + TypeName(c) + ", " + ITypeCollectionRequestBuilder(c) + ">";
445487
}
@@ -477,6 +519,10 @@ import java.util.List;";
477519
host.TemplateInfo.OutputParentDirectory);
478520
}
479521

522+
/// Creates a class declaration
523+
/// name = the name of the class
524+
/// extends = the class it extends
525+
/// implements = the interface it extends
480526
public string CreateClassDef(string name, string extends = null, string implements = null)
481527
{
482528
return this.CreateClassOrInterface(name, true, extends, implements);
@@ -631,12 +677,13 @@ public {1} {2}{3}{4} {{";
631677
";
632678
foreach (var p in parameters)
633679
{
634-
var propertyType = p.IsCollection ? string.Format("List<{0}>", ParamType(p)) : ParamType(p);
635-
sb.AppendFormat(format,
680+
sb.AppendFormat(
681+
format,
636682
ParamName(p).SplitCamelCase(),
637683
ParamName(p),
638684
ParamType(p),
639-
p.SanitizePropertyName().ToLowerFirstChar());
685+
p.SanitizePropertyName().ToLowerFirstChar()
686+
);
640687
}
641688
return sb.ToString();
642689
}

Templates/Android/extensions/EntityCollectionPage.java.tt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,4 @@
1616
public <#=TypeCollectionPage(c)#>(final <#=BaseTypeCollectionResponse(c)#> response, final <#=ITypeCollectionRequestBuilder(c)#> builder) {
1717
super(response, builder);
1818
}
19-
2019
}

Templates/Android/extensions/EntityCollectionWithReferencesPage.java.tt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,4 @@
1616
public <#=TypeCollectionWithReferencesPage(c)#>(final <#=BaseTypeCollectionResponse(c)#> response, final <#=ITypeCollectionWithReferencesRequestBuilder(c)#> builder) {
1717
super(response, builder);
1818
}
19-
2019
}

Templates/Android/extensions/EntityReferenceRequestBuilder.java.tt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@
1818
public <#=TypeReferenceRequestBuilder(c)#>(final String requestUrl, final <#=IBaseClientType()#> client, final List<Option> options) {
1919
super(requestUrl, client, options);
2020
}
21-
}
21+
}

Templates/Android/extensions/EntityRequestBuilder.java.tt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@
1818
public <#=TypeRequestBuilder(c)#>(final String requestUrl, final <#=IBaseClientType()#> client, final List<Option> options) {
1919
super(requestUrl, client, options);
2020
}
21-
}
21+
}

Templates/Android/extensions/EntityStreamRequestBuilder.java.tt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@
1818
public <#=TypeStreamRequestBuilder(c)#>(final String requestUrl, final <#=IBaseClientType()#> client, final List<Option> options) {
1919
super(requestUrl, client, options);
2020
}
21-
}
21+
}

Templates/Android/extensions/EntityWithReferenceRequestBuilder.java.tt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@
1818
public <#=TypeWithReferencesRequestBuilder(c)#>(final String requestUrl, final <#=IBaseClientType()#> client, final List<Option> options) {
1919
super(requestUrl, client, options);
2020
}
21-
}
21+
}

0 commit comments

Comments
 (0)