Skip to content

Commit 6757d72

Browse files
committed
this version compiles for TestData
method parameter list edm namespace special handling option and query option referring to full name added an input parameter to testAction
1 parent 37163b7 commit 6757d72

File tree

8 files changed

+62
-41
lines changed

8 files changed

+62
-41
lines changed

Templates/Java/models_extensions/BaseMethodBody.java.tt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@
55
<#host.TemplateName = c.TypeBody();#>
66
<#=writer.WriteHeader()#>
77
<#=host.CreatePackageDefinition()#>
8-
import com.microsoft.graph.models.generated.*;
8+
<#
9+
var sb = new StringBuilder();
10+
sb = TypeHelperJava.ImportClassesOfMethodParameters(c.AsOdcmMethod(), "import {0}.{1}.{2};", sb);
11+
#>
12+
<#=sb.ToString()#>
913
import com.google.gson.annotations.Expose;
1014
import com.google.gson.annotations.SerializedName;
1115
import com.google.gson.JsonObject;

Templates/Java/requests_extensions/BaseEntityRequest.java.tt

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ import com.microsoft.graph.core.ClientException;
1010
import com.microsoft.graph.core.IBaseClient;
1111
import com.microsoft.graph.http.BaseRequest;
1212
import com.microsoft.graph.http.HttpMethod;
13-
import com.microsoft.graph.options.Option;
14-
import com.microsoft.graph.options.QueryOption;
1513
<#
1614
String classDeclaration = "";
1715
if (c.AsOdcmClass().Derived.Any() && c.AsOdcmClass().Base != null)
@@ -89,7 +87,7 @@ classDeclaration += c.TypeName();
8987
* @return the updated request
9088
*/
9189
public <#=c.ITypeRequest()#> select(final String value) {
92-
getQueryOptions().add(new QueryOption("$select", value));
90+
getQueryOptions().add(new com.microsoft.graph.options.QueryOption("$select", value));
9391
return (<#=c.TypeRequest()#>)this;
9492
}
9593

@@ -102,7 +100,7 @@ classDeclaration += c.TypeName();
102100
* @return the updated request
103101
*/
104102
public <#=c.ITypeRequest()#> expand(final String value) {
105-
getQueryOptions().add(new QueryOption("$expand", value));
103+
getQueryOptions().add(new com.microsoft.graph.options.QueryOption("$expand", value));
106104
return (<#=c.TypeRequest()#>)this;
107105
}
108106

@@ -116,7 +114,7 @@ classDeclaration += c.TypeName();
116114
* @return the updated request
117115
*/
118116
public <#=c.ITypeRequest()#> top(final int value) {
119-
getQueryOptions().add(new QueryOption("$top", value+""));
117+
getQueryOptions().add(new com.microsoft.graph.options.QueryOption("$top", value+""));
120118
return (<#=c.TypeRequest()#>)this;
121119
}
122120
<# } #>

Templates/Java/requests_extensions/BaseMethodBodyRequest.java.tt

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@
2525
import com.microsoft.graph.concurrency.ICallback;
2626
import com.microsoft.graph.core.ClientException;
2727
import com.microsoft.graph.core.IBaseClient;
28-
import com.microsoft.graph.options.Option;
29-
import com.microsoft.graph.options.QueryOption;
3028
<#
3129
if (c.AsOdcmMethod().IsCollection) {
3230
#>
@@ -73,7 +71,7 @@ import com.microsoft.graph.http.HttpMethod;
7371
* @return the updated request
7472
*/
7573
public <#=iTypeRequest#> select(final String value) {
76-
getQueryOptions().add(new QueryOption("$select", value));
74+
getQueryOptions().add(new com.microsoft.graph.options.QueryOption("$select", value));
7775
return (<#=typeRequest#>)this;
7876
}
7977

@@ -86,7 +84,7 @@ import com.microsoft.graph.http.HttpMethod;
8684
* @return the updated request
8785
*/
8886
public <#=iTypeRequest#> top(final int value) {
89-
getQueryOptions().add(new QueryOption("$top", value+""));
87+
getQueryOptions().add(new com.microsoft.graph.options.QueryOption("$top", value+""));
9088
return (<#=typeRequest#>)this;
9189
}
9290

@@ -99,7 +97,7 @@ import com.microsoft.graph.http.HttpMethod;
9997
* @return the updated request
10098
*/
10199
public <#=iTypeRequest#> expand(final String value) {
102-
getQueryOptions().add(new QueryOption("$expand", value));
100+
getQueryOptions().add(new com.microsoft.graph.options.QueryOption("$expand", value));
103101
return (<#=typeRequest#>)this;
104102
}
105103

Templates/Java/requests_extensions/BaseMethodRequest.java.tt

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ import com.microsoft.graph.core.ClientException;
1111
import com.microsoft.graph.core.IBaseClient;
1212
import com.microsoft.graph.http.BaseRequest;
1313
import com.microsoft.graph.http.HttpMethod;
14-
import com.microsoft.graph.options.Option;
15-
import com.microsoft.graph.options.QueryOption;
1614

1715
<#=TypeHelperJava.CreateClassDef(c.TypeRequest(), "BaseRequest", c.ITypeRequest())#>
1816

@@ -60,7 +58,7 @@ if (c.AsOdcmMethod().IsAction()) {
6058
* @return the updated request
6159
*/
6260
public <#=c.ITypeRequest()#> select(final String value) {
63-
getQueryOptions().add(new QueryOption("$select", value));
61+
getQueryOptions().add(new com.microsoft.graph.options.QueryOption("$select", value));
6462
return (<#=c.TypeRequest()#>)this;
6563
}
6664

@@ -76,7 +74,7 @@ if (c.AsOdcmMethod().IsAction()) {
7674
* @return the updated request
7775
*/
7876
public <#=c.ITypeRequest()#> expand(final String value) {
79-
getQueryOptions().add(new QueryOption("$expand", value));
77+
getQueryOptions().add(new com.microsoft.graph.options.QueryOption("$expand", value));
8078
return (<#=c.TypeRequest()#>)this;
8179
}
8280

@@ -93,7 +91,7 @@ if (c.AsOdcmMethod().IsAction()) {
9391
* @return the updated request
9492
*/
9593
public <#=c.ITypeRequest()#> top(final int value) {
96-
getQueryOptions().add(new QueryOption("$top", value+""));
94+
getQueryOptions().add(new com.microsoft.graph.options.QueryOption("$top", value+""));
9795
return (<#=c.TypeRequest()#>)this;
9896
}
9997
<#
@@ -206,7 +204,7 @@ if (c.AsOdcmMethod().IsAction()) {
206204
* @return the updated request
207205
*/
208206
public <#=c.ITypeRequest()#> select(final String value) {
209-
getQueryOptions().add(new QueryOption("$select", value));
207+
getQueryOptions().add(new com.microsoft.graph.options.QueryOption("$select", value));
210208
return (<#=c.TypeRequest()#>)this;
211209
}
212210

@@ -222,7 +220,7 @@ if (c.AsOdcmMethod().IsAction()) {
222220
* @return the updated request
223221
*/
224222
public <#=c.ITypeRequest()#> expand(final String value) {
225-
getQueryOptions().add(new QueryOption("$expand", value));
223+
getQueryOptions().add(new com.microsoft.graph.options.QueryOption("$expand", value));
226224
return (<#=c.TypeRequest()#>)this;
227225
}
228226

@@ -239,7 +237,7 @@ if (c.AsOdcmMethod().IsAction()) {
239237
* @return the updated request
240238
*/
241239
public <#=c.ITypeRequest()#> top(final int value) {
242-
getQueryOptions().add(new QueryOption("$top", value+""));
240+
getQueryOptions().add(new com.microsoft.graph.options.QueryOption("$top", value+""));
243241
return (<#=c.TypeRequest()#>)this;
244242
}
245243
<#

Templates/Java/requests_extensions/IBaseMethodRequest.java.tt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ import com.microsoft.graph.core.ClientException;
1111
import com.microsoft.graph.core.IBaseClient;
1212
import com.microsoft.graph.http.BaseRequest;
1313
import com.microsoft.graph.http.HttpMethod;
14-
import com.microsoft.graph.options.Option;
15-
import com.microsoft.graph.options.QueryOption;
1614

1715
<#=TypeHelperJava.CreateInterfaceDef(c.ITypeRequest())#>
1816

src/GraphODataTemplateWriter/CodeHelpers/Java/TypeHelperJava.cs

Lines changed: 42 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -839,26 +839,33 @@ public static string CreatePackageDefForBaseMethodRequestBuilder(this CustomT4Ho
839839

840840
foreach (var method in host.CurrentType.AsOdcmMethod().WithOverloads())
841841
{
842-
foreach (var p in method.Parameters)
842+
sb = ImportClassesOfMethodParameters(method, importFormat, sb);
843+
}
844+
return sb.ToString();
845+
}
846+
847+
public static StringBuilder ImportClassesOfMethodParameters(OdcmMethod method, string importFormat, StringBuilder sb)
848+
{
849+
foreach (var p in method.Parameters)
850+
{
851+
if (!(p.Type is OdcmPrimitiveType) && p.Type.GetTypeString() != "com.google.gson.JsonElement")
843852
{
844-
if (!(p.Type is OdcmPrimitiveType) && p.Type.GetTypeString() != "com.google.gson.JsonElement")
853+
var propertyType = p.Type.GetTypeString();
854+
if (propertyType.StartsWith("EnumSet"))
845855
{
846-
var propertyType = p.Type.GetTypeString();
847-
if (propertyType.StartsWith("EnumSet"))
848-
{
849-
propertyType = propertyType.Substring("EnumSet<".Length, propertyType.Length - ("EnumSet<".Length + 1));
850-
sb.Append("import java.util.EnumSet;\n");
851-
}
852-
853-
sb.AppendFormat(importFormat,
854-
p.Type.Namespace.Name.NamespaceName(),
855-
p.GetPackagePrefix(),
856-
propertyType);
857-
sb.Append("\n");
856+
propertyType = propertyType.Substring("EnumSet<".Length, propertyType.Length - ("EnumSet<".Length + 1));
857+
sb.Append("import java.util.EnumSet;\n");
858858
}
859+
860+
sb.AppendFormat(importFormat,
861+
p.Type.Namespace.Name.NamespaceName(),
862+
p.GetPackagePrefix(),
863+
propertyType);
864+
sb.Append("\n");
859865
}
860866
}
861-
return sb.ToString();
867+
868+
return sb;
862869
}
863870

864871
public static string CreatePackageDefForIBaseMethodBodyRequest(this CustomT4Host host)
@@ -1122,7 +1129,7 @@ public static string CreatePackageDef(this CustomT4Host host)
11221129
import {2}.concurrency.*;
11231130
import {2}.core.*;
11241131
import {0}.models.extensions.*;
1125-
import {0}.models.generated.*;{3}
1132+
import {0}.models.generated.*;{3}{4}
11261133
import {2}.http.*;
11271134
import {0}.requests.extensions.*;
11281135
import {2}.options.*;
@@ -1134,11 +1141,28 @@ public static string CreatePackageDef(this CustomT4Host host)
11341141
// We need this for disambiguation of generated model class/interfaces references.
11351142
string fullyQualifiedImport = host.GetFullyQualifiedImportStatementForModel();
11361143

1144+
string @namespace;
1145+
string methodImports = string.Empty;
1146+
switch (host.CurrentType)
1147+
{
1148+
case OdcmProperty p:
1149+
@namespace = p.Type.Namespace.Name.NamespaceName();
1150+
break;
1151+
case OdcmMethod m:
1152+
var sb = new StringBuilder(Environment.NewLine);
1153+
methodImports = ImportClassesOfMethodParameters(m, "import {0}.{1}.{2};", sb).ToString();
1154+
goto default;
1155+
default:
1156+
@namespace = host.CurrentNamespace();
1157+
break;
1158+
}
1159+
11371160
return string.Format(format,
1138-
host.CurrentNamespace(),
1161+
@namespace,
11391162
host.TemplateInfo.OutputParentDirectory.Replace("_", "."),
11401163
host.CurrentModel.GetNamespace().NamespaceName(),
1141-
fullyQualifiedImport);
1164+
fullyQualifiedImport,
1165+
methodImports);
11421166
}
11431167

11441168
public static string CurrentNamespace(this CustomT4Host host)

src/GraphODataTemplateWriter/Extensions/OdcmModelExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -432,8 +432,8 @@ public static string NamespaceName(this string @namespace)
432432
{
433433
if (string.IsNullOrEmpty(ConfigurationService.Settings.NamespaceOverride))
434434
{
435-
var name = string.Format("{0}.{1}", ConfigurationService.Settings.NamespacePrefix, @namespace);
436-
return name.ToLower();
435+
var name = string.Format("{0}.{1}", ConfigurationService.Settings.NamespacePrefix, @namespace).ToLower();
436+
return name == "com.edm" ? "com.microsoft.graph" : name;
437437
}
438438
return ConfigurationService.Settings.NamespaceOverride;
439439
}

test/Typewriter.Test/Metadata/MetadataMultipleNamespaces.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,7 @@
275275
</Action>
276276
<Action Name="testAction" IsBound="true">
277277
<Parameter Name="bindingParameter" Type="microsoft.graph2.callRecords.segment" />
278+
<Parameter Name="value" Type="graph.identitySet" />
278279
<ReturnType Type="Collection(microsoft.graph2.callRecords.session)" />
279280
</Action>
280281
</Schema>

0 commit comments

Comments
 (0)