When a DTO object is used both a a request and a response the generated code treats it as just a response and not a request.
For example:
[Route("/thing/{Id}", verbs: "GET")]
public class ThingRequest : IReturn<Thing>
{
public int Id { get; set; }
}
[Route("/thing/{Id}", verbs: "PUT")]
public class Thing : IReturn<Thing>
{
public int Id { get; set; }
public string Value { get; set; }
}
When the client code is generated to route on Thing is missing.
This is the C# code generated (but it seems to affect all languages):
public partial class Thing
{
public virtual int Id { get; set; }
public virtual string Value { get; set; }
}
[Route("/thing/{Id}", "GET")]
public partial class ThingRequest
: IReturn<Thing>
{
public virtual int Id { get; set; }
}
I grabbed that one, and it does indeed fix this case, so that’s good. Thanks for that.
However there seems to be a similar issue left when AutoQuery is being used, specifically for Typescript. (C# code is correct, I haven’t checked the others.)
These requests give me the same issue where the Thing is generated as just a response:
[Route("/thing/{Id}", verbs: "GET")]
public class ThingRequest : QueryDb<Thing>
{
public int Id { get; set; }
}
[Route("/thing/{Id}", verbs: "PUT")]
public class Thing : ISaveDb<Thing>, IReturnVoid
{
public int Id { get; set; }
public string Value { get; set; }
}
When we get there AllTypes contains the Thing twice, and the first one happens to be the response so that gets generated, causing the request gets skipped. This was what the some debugging showed me at that point:
This is the generated TypeScript code those C# DTOs generate:
// @Route("/thing/{Id}", "GET")
export class ThingRequest extends QueryDb_1<Thing> implements IReturn<QueryResponse<Thing>>
{
public id: number;
public constructor(init?: Partial<ThingRequest>) { super(init); (Object as any).assign(this, init); }
public createResponse() { return new QueryResponse<Thing>(); }
public getTypeName() { return 'ThingRequest'; }
}
export class Thing implements ISaveDb<Thing>
{
public id: number;
public value: string;
public constructor(init?: Partial<Thing>) { (Object as any).assign(this, init); }
}
Ok seeing that it’s not generated like a Request DTO.
The point is that Thing actually is a Request as well here. So I’d expect the typescript class for Thing to contain getTypeName() and createResponse() methods too, allowing the client to PUT it…