1

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.

reven
  • 330
  • 4
  • 14
  • MyType in ExcludedTypeNames should work – Rico Suter Nov 30 '18 at 07:49
  • Like I said, I tried that, but it didnt work. I tried the name "MyType" and the full typename "MyNamespace.MyType". MyType is defined in a different assembly to the application assembly if that makes any difference. – reven Nov 30 '18 at 10:31
  • ExcludedTypeNames is based on the name in the Swagger spec and not the initial C# type... that's also why you can't exclude by namespace wildcard (the ns is not in the spec) – Rico Suter Nov 30 '18 at 16:54

1 Answers1

1

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
Rico Suter
  • 11,548
  • 6
  • 67
  • 93