Generating swift client errors

Hi i’m trying to generate a swift client with x swift
i’m getting multiple errors on missing interfaces.
I’m on xcode 12 beta 6.

For example i get this generated

public class UpdateAuditBase<Table : JsonSerializable, TResponse :     JsonSerializable> : IUpdateDb<Table>
{
    required public init(){}
}

It’s complaining on IUpdateDb which dosen’t exist.

Also i get an error that IAudit is redundant because is already present on AuditBase

public class ChangeSet : AuditBase, IAudit

I get multiple of the above errors.

Edit: Also i noticed that i get errors when it generate the dto for AuthenticateResponse it cant find IHasSessionId, IHasBearerToken.
The same services generate fine on typescript

There is a way for example to exclude IUpdateDb and ICreateDb to be generated or to include it i have tried using the settings on top of the file without any luck.

You can ignore them in your AppHost with:

var typesConfig = GetPlugin<NativeTypesFeature>().MetadataTypesConfig;
typesConfig.ExportTypes.Remove(typeof(ICreateDb<>));
typesConfig.ExportTypes.Remove(typeof(IUpdateDb<>));
typesConfig.ExportTypes.Remove(typeof(IPatchDb<>));
typesConfig.ExportTypes.Remove(typeof(IUpdateDb<>));
typesConfig.ExportTypes.Remove(typeof(ISaveDb<>));

But as Swift doesn’t supports C# generic marker interfaces in generic protocols I’ve removed them by default for Swift. This change is available from v5.9.3 that’s now available on MyGet.

1 Like

Good i was able to remove all the errors on 5.9.3.
I had to also configure this way

    typesConfig.ExcludeImplementedInterfaces = true;
    typesConfig.ExportTypes.Remove(typeof(IAudit)); 
    typesConfig.ExportTypes.Remove(typeof(IHasSessionId)); 
    typesConfig.ExportTypes.Remove(typeof(IHasBearerToken)); 

Otherwise especially for IAudit it would generate a dto with IAudit added while is also on the base class, and swift will complain that is declared twice.

for my case should be ok not having this interface at all.

Thanks

IAudit isn’t an interface in ServiceStack, removing it shouldn’t have done anything unless you’ve added it yourself?

Was the issue with IHasSessionId & IHasBearerToken interfaces just that it didn’t exist? (I’m adding it to new ServiceStack.Swift client).

Yes IAudit is defined by me .
This is on the service side where i have my ormlite entities inherit from AuditBase which implements IAudit

public interface IAudit
{
    DateTime CreatedDate { get; set; }

    string CreatedBy { get; set; }

    DateTime ModifiedDate { get; set; }

    string ModifiedBy { get; set; }

    DateTime? SoftDeletedDate { get; set; }

    string SoftDeletedBy { get; set; }

    string SoftDeletedInfo { get; set; }
}

 public abstract class AuditBase : IAudit
 {
  .....
 }
 
 public class Look: AuditBase, IHasIntId, IIncludeInChangeSet
{
    [AutoIncrement]
    public int Id { get; set; }
    ....
}

public class Look: AuditBase, IHasIntId, IIncludeInChangeSet
{
    [AutoIncrement]
    public int Id { get; set; }
    ....
}

But on swift the IAudit interface is applied on AuditBase and also on Look.

  public class AuditBase : IAudit
    {
        ...
    }
     public class Look : AuditBase, IAudit, IIncludeInChangeSet
    {
        ...
    }

This on swift cause an compilation error because it dosent like to have the IAudit defined on Look and also on AuditBase.

For IHasSessionId & IHasBearerToken yes it’s because they are not defined.

ok cool, I’ve changed it so it only generates the Type’s direct interfaces which should avoid this duplicate interface issue. This change is available on the latest v5.9.3 that’s now on MyGet.

After updating the next version of the Swift library it should resolve the outstanding issues.

1 Like

Upgraded on both sides and those issues are resolved.

One thing i don’t understand when trying to do a postAsync i get this error

        let rq = QueryLooks<Look>()
        client.postAsync(rq)
            .then { r in
                         
                        return r
                    }

Instance method 'then(on:flags:_:)' requires that 'QueryLooks<Look>.Return' (aka 'QueryResponse<Look>') conform to 'Thenable'

Is something i’m missing? this is my first time with promisekit :slight_smile:

1 Like

The error says then can only return a Thenable, i.e. a Promise. You already have the completed Response DTO in the then callback so you should handle the response there and not return anything.

Yeah sorry i got confused by some old example which didn’t need to return anything, but as of now to compile it need to return another promise.
Instead i managed to use .done as it dosen’t need to return anything.