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

Feature: Filtering of endpoints and tags #132

Merged

Conversation

kirides
Copy link
Contributor

@kirides kirides commented Aug 30, 2023

This PR demonstrates how #131 could be implemented

It add --match-path and --tag CLI options, which allow the user to filter endpoints based on existing Tags and/or if the Path matches an regular expression.

It's not as fine grained as for supporting HTTP methods. I.e. you can't filter for ^/greet and only allow GET and PUT or something like that.

A call might look like this:

refitter.exe swagger.json --tag Greeting --tag OpenApi --match-path '^/api/'

It works by modifying the OpenApiDocument and removing the Paths/Methods that don't match any of the Tags or patterns, thus further steps in code generation only see the filtered document.

@codecov
Copy link

codecov bot commented Aug 30, 2023

Codecov Report

Merging #132 (4529cd5) into main (a074908) will increase coverage by 0.15%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main     #132      +/-   ##
==========================================
+ Coverage   98.29%   98.44%   +0.15%     
==========================================
  Files          32       34       +2     
  Lines         997     1094      +97     
==========================================
+ Hits          980     1077      +97     
  Misses          6        6              
  Partials       11       11              
Flag Coverage Δ
unittests 98.44% <100.00%> (+0.15%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Changed Coverage Δ
src/Refitter.Core/RefitGenerator.cs 100.00% <100.00%> (ø)
src/Refitter.Tests/Examples/FilterByPathTests.cs 100.00% <100.00%> (ø)
src/Refitter.Tests/Examples/FilterByTagsTests.cs 100.00% <100.00%> (ø)

@sonarcloud
Copy link

sonarcloud bot commented Aug 30, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 4 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@christianhelle christianhelle added the enhancement New feature, bug fix, or request label Aug 30, 2023
return new RefitGenerator(settings, document);
}

private static void ProcessTagFilters(OpenApiDocument document,
Copy link
Owner

Choose a reason for hiding this comment

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

I really like this approach. It seems so much more simple to just trim the OpenAPI document down instead of checking every single endpoint upon generation

@christianhelle
Copy link
Owner

The changes here looks good to me. Shall we merge this in @kirides? Or do you have pending changes?

@kirides
Copy link
Contributor Author

kirides commented Aug 30, 2023

I would still have to check if the source generator works and maybe clean up the filtering mechanisms.

Also need to take a look at poco generation, maybe there's room for improvement (remove unneeded schema from document after filtering it)

@christianhelle
Copy link
Owner

I would still have to check if the source generator works and maybe clean up the filtering mechanisms.

Thanks for thinking about that @kirides

Also need to take a look at poco generation, maybe there's room for improvement (remove unneeded schema from document after filtering it)

It might be dangerous to tamper with the contracts. We need to make sure that the contract types that we skip generating are not referenced by other contract types

@kirides
Copy link
Contributor Author

kirides commented Aug 31, 2023

@christianhelle after evaluating my consideration about trimming contracts, i came to the conclusion that there is no way to get it right, due to the spec allowing for additional schema and things like "any object" as result or parameters.

if the code looks good for you, and the checks are green we can merge it :)

@kirides kirides marked this pull request as ready for review August 31, 2023 06:53
@christianhelle christianhelle merged commit e8ffe5a into christianhelle:main Aug 31, 2023
62 checks passed
@christianhelle christianhelle linked an issue Aug 31, 2023 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature, bug fix, or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Proposal: filter generated interfaces
2 participants