Skip to content

Commit d96544f

Browse files
committed
Don't generate Error ResponseStatus Types in Swift which are now included in JsonServiceClient.swift
1 parent dcba587 commit d96544f

4 files changed

Lines changed: 31 additions & 12 deletions

File tree

src/ServiceStack/NativeTypes/Java/JavaGenerator.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@ namespace ServiceStack.NativeTypes.Java
1111
public class JavaGenerator
1212
{
1313
readonly MetadataTypesConfig Config;
14+
readonly List<MetadataType> AllTypes;
1415
List<string> conflictTypeNames = new List<string>();
1516

1617
public JavaGenerator(MetadataTypesConfig config)
1718
{
1819
Config = config;
20+
AllTypes = new List<MetadataType>();
1921
}
2022

2123
public static string DefaultGlobalNamespace = "dto";
@@ -143,20 +145,18 @@ public string GetCode(MetadataTypes metadata, IRequest request, INativeTypesMeta
143145
.Select(x => x.Response).ToHashSet();
144146
var types = metadata.Types.ToHashSet();
145147

146-
var allTypes = new List<MetadataType>();
147-
allTypes.AddRange(types);
148-
allTypes.AddRange(responseTypes);
149-
allTypes.AddRange(requestTypes);
150-
allTypes.RemoveAll(x => x.IgnoreType(Config));
148+
AllTypes.AddRange(requestTypes);
149+
AllTypes.AddRange(responseTypes);
150+
AllTypes.AddRange(types);
151151

152152
//TypeScript doesn't support reusing same type name with different generic airity
153-
var conflictPartialNames = allTypes.Map(x => x.Name).Distinct()
153+
var conflictPartialNames = AllTypes.Map(x => x.Name).Distinct()
154154
.GroupBy(g => g.SplitOnFirst('`')[0])
155155
.Where(g => g.Count() > 1)
156156
.Select(g => g.Key)
157157
.ToList();
158158

159-
this.conflictTypeNames = allTypes
159+
this.conflictTypeNames = AllTypes
160160
.Where(x => conflictPartialNames.Any(name => x.Name.StartsWith(name)))
161161
.Map(x => x.Name);
162162

@@ -167,7 +167,7 @@ public string GetCode(MetadataTypes metadata, IRequest request, INativeTypesMeta
167167
sb.AppendLine("{");
168168

169169
//ServiceStack core interfaces
170-
foreach (var type in allTypes)
170+
foreach (var type in AllTypes)
171171
{
172172
var fullTypeName = type.GetFullName();
173173
if (requestTypes.Contains(type))

src/ServiceStack/NativeTypes/Swift/SwiftGenerator.cs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public SwiftGenerator(MetadataTypesConfig config)
5252
public string GetCode(MetadataTypes metadata, IRequest request)
5353
{
5454
var typeNamespaces = new HashSet<string>();
55-
metadata.RemoveIgnoredTypes(Config);
55+
RemoveIgnoredTypes(metadata);
5656
metadata.Types.Each(x => typeNamespaces.Add(x.Namespace));
5757
metadata.Operations.Each(x => typeNamespaces.Add(x.Request.Namespace));
5858

@@ -97,9 +97,9 @@ public string GetCode(MetadataTypes metadata, IRequest request)
9797
.Select(x => x.Response).ToHashSet();
9898
var types = metadata.Types.ToHashSet();
9999

100-
AllTypes.AddRange(types);
101-
AllTypes.AddRange(responseTypes);
102100
AllTypes.AddRange(requestTypes);
101+
AllTypes.AddRange(responseTypes);
102+
AllTypes.AddRange(types);
103103

104104
//Swift doesn't support reusing same type name with different generic airity
105105
var conflictPartialNames = AllTypes.Map(x => x.Name).Distinct()
@@ -185,6 +185,20 @@ public string GetCode(MetadataTypes metadata, IRequest request)
185185
return sb.ToString();
186186
}
187187

188+
//Use built-in types already in net.servicestack.client package
189+
public static HashSet<string> IgnoreTypeNames = new HashSet<string>
190+
{
191+
typeof(ResponseStatus).Name,
192+
typeof(ResponseError).Name,
193+
typeof(ErrorResponse).Name,
194+
};
195+
196+
private void RemoveIgnoredTypes(MetadataTypes metadata)
197+
{
198+
metadata.RemoveIgnoredTypes(Config);
199+
metadata.Types.RemoveAll(x => IgnoreTypeNames.Contains(x.Name));
200+
}
201+
188202
private string AppendType(ref StringBuilderWrapper sb, ref StringBuilderWrapper sbExt, MetadataType type, string lastNS,
189203
CreateTypeOptions options)
190204
{

tests/Check.ServiceInterface/NativeTypesTestService.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,11 @@ public object Any(HelloAllTypes request)
8282
};
8383
}
8484

85+
public object Any(AllTypes request)
86+
{
87+
return request;
88+
}
89+
8590
public object Any(HelloString request)
8691
{
8792
return request.Name;

tests/Check.ServiceModel/CodeGenTestTypes.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ public class HelloWithTypeResponse
292292

293293
namespace Check.ServiceModel.Types
294294
{
295-
public class AllTypes
295+
public class AllTypes : IReturn<AllTypes>
296296
{
297297
public int Id { get; set; }
298298
public int? NullableId { get; set; }

0 commit comments

Comments
 (0)