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

[csharp][aspnetcore] Allow the use of endpoints (single class per operation) #9429

Closed

Conversation

Blackclaws
Copy link
Contributor

This adds support for endpoints, i.e. a single class per operation to the generator. Unfortunately the way the generator currently works they are still all part of the same file. We can discuss whether we want to put them under an even further nested namespace.
As a side effect enabled actual usage of annotations. Might want to expand the annotations of the normal controllers later on as well.

PR checklist

  • Read the contribution guidelines.
  • Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
  • Run the following to build the project and update samples:
    ./mvnw clean package 
    ./bin/generate-samples.sh
    ./bin/utils/export_docs_generators.sh
    
    Commit all changed files.
    This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
    These must match the expectations made by your contribution.
    You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example ./bin/generate-samples.sh bin/configs/java*.
    For Windows users, please run the script in Git BASH.
  • File the PR against the correct branch: master, 5.1.x, 6.0.x
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.
    @mandrean (2017/08) @frankyjuang (2019/09) @shibayan (2020/02)

@wing328
Copy link
Member

wing328 commented May 15, 2021

cc @lucamazzanti as well (new C# technical committee member)

Copy link
Contributor

@lucamazzanti lucamazzanti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The namespace doesn't respect the folders, are you sure to keep the .Endpoints part?
Classes doesn't respect the Controller suffix convention, do you prefer to remove it because it can became a long name?

@Blackclaws
Copy link
Contributor Author

The namespace doesn't respect the folders, are you sure to keep the .Endpoints part?
Classes doesn't respect the Controller suffix convention, do you prefer to remove it because it can became a long name?

Good point, maybe we should actually change the folder instead? I think I want to keep the Endpoints part because I want to clearly separate it from the existing functionality regarding controllers.

In general I would also like to have one file per operation however the way the generator works right now this simply isn't possible and would require a new option for the template system that allows creating one file per operation instead of per tag.

The Controller suffix convention is just that a convention and we are doing route generation via annotations anyway. I was thinking about actually adding an "Endpoint" Suffix but that might be redundant for people that already call it Endpoint in their apispec. Now that I\m thinking about it that might be something we can parse out however ....

When you go by how other people are implementing a similar feature you can end up with even more different classes/names.

https://github.com/ardalis/CleanArchitecture/tree/main/src/Clean.Architecture.Web/Endpoints/ProjectEndpoints

Basically the structure would be: Endpoints.TAGEndpoints followed by classes that are named by the operationid

@Blackclaws
Copy link
Contributor Author

@lucamazzanti @wing328 Let me revive this, we're currently already using this internally in one form or another. What do you think on merging this?

@wing328
Copy link
Member

wing328 commented Nov 22, 2023

i've filed #17161 to add a new rule in openapi-normalizer to set tags to the operationId so as to support single "class" per operation (or per operationId) to be more precise.

Please take a look when you've time.

@wing328
Copy link
Member

wing328 commented Jan 12, 2024

#17161 merged. please pull the latest master to give it a try. closing this one.

@wing328 wing328 closed this Jan 12, 2024
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 this pull request may close these issues.

None yet

3 participants