Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to Access operation Tags from CodeGeneration CSharp templates? #3607

Closed
SerialRYaya opened this issue Aug 19, 2021 · 1 comment · Fixed by #4807
Closed

How to Access operation Tags from CodeGeneration CSharp templates? #3607

SerialRYaya opened this issue Aug 19, 2021 · 1 comment · Fixed by #4807

Comments

@SerialRYaya
Copy link

Hello!

I have a server which exposes its api definition with swagger.
Some of the webmethods are tagged and the tags are in the definitions.
I would like to generate a client for this server with specific logic related to the operation tags.

The OpenApi definition looks like this:
{ "openapi": "3.0.1", "info": { "title": "MyServer", "version": "v1" }, "paths": { "/MyTaggedOperation": { "get": { "tags": [ "MyTag" ],[...]
I would like to access the tags from the templates so I can apply a specific logic in the generated client class.

From the NSwag source code, master branch, I found a way to do it by adding an accessor on the operation tags in the NSwag.CodeGeneration.CSharp.Models.CSharpOperationModel:
/// <summary>Gets the tags associated with this operation.</summary> public List<string> Tags { get { return _operation.Tags; } }
Then, from the Client.Class.Liquid template, I can add the following:

{% for operation in Operations -%} {% if operation.Tags contains "MyTag" -%} // the operation is tagged "MyTag", do something related {% else %} // do something else {% endif %} {% endfor %}

My issue is that I had to modify NSwag source code to make this work but I would like to avoid maintaining a fork if there's a better way.

Is this use case already taken into account? Is there and what is the way to access operation tags from the csharp client generator templates (or any other generator templates since NSwag is not exclusive to CSharp) please?

If not, what's the way to request this feature please?

@chivandikwa
Copy link

Any updates/changes regardomg this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants