reven
reven

Reputation: 340

NSwagStudio using common C# shared library

I'm wanting to use a shared DLL between my endpoint REST service and my client. Both are written in dotnet core.

I dont want the generated nswag c# to include these objects defined in the shared DLL but instead just reference them. This way I retain all the validation attributes/logic and can validate both on the server and the front end.

I tried using "Excluded Type Names", but thats not having any effect. Eg. my common dll namespace is "MyCommonLibrary" and theres an object of type "MyType" in there. I've tried "MyCommonLibrary.MyType" aswell as just "MyType" in that field, neither produced a C# generated file with that type missing (i.e. a new type was generated).

Say my REST call is

public MyType[] GetAll(){ ... }

I want the generated controllers to return MyCommonLibrary.MyType and not "MyGenreatedController.MyType".

Is there a way to do this?

I'm hoping to wildcard this, since myself and other developers will be continuing to add to this and wanting to generate the generated C# code as part of the build process.

Upvotes: 1

Views: 824

Answers (1)

Rico Suter
Rico Suter

Reputation: 11868

This can be solved in this way:

  • Add a custom schema processor which adds x-namespace to all types/schemas in the spec
  • When generating client code, process the spec and dynamically find all excluded type names based on the namespace
  • Run the client generator with these excluded type names

Upvotes: 1

Related Questions