Situation:
- Server side in a Web API controller I got a model class, lets call it
MyNamespace.MyData
, that in addition to properties also has business logic functions like abool CanEditThis()
method. - With Visual Studio 2017 I use "Add"->"REST API Client" to generate client side code to call the Web API methods and return data, but this generates a new model class like
ClientNamespace.MyData
for the client (without functions), instead of detecting there already is a useable model classMyNamespace.MyData
(with funcitons). - The model classes used server side are defined in their own project and available in a DLL for both client and server side code (used this setup for WCF but wanted to implement new features via Web API).
How can I use the same model class on both ends?
Any magic property to add to the swagger/OpenAPI definition so AutoREST generated code knows to reuse a class model instead of making a new?
Or do I have to choose between
a) duplicating the code of the partical class MyData
both in server-side and client-side projects or
b) having utility functions to convert the returned IList<ClientNamespace.MyData>
to IList<MyNamespace.MyData>
?