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

fix: fixes the filtering logic #110

Merged
merged 6 commits into from
Jul 25, 2024
Merged

fix: fixes the filtering logic #110

merged 6 commits into from
Jul 25, 2024

Conversation

andreaangiolillo
Copy link
Collaborator

@andreaangiolillo andreaangiolillo commented Jul 24, 2024

Proposed changes

The PR proposes the following changes:

  • Fixes a bug in the HiddenEnvs filter where we were not deleting the ContentType
  • Updates the split command to remove the hidden env before getting the valid version

func (f *HiddenEnvsFilter) removeContentIfHiddenForEnv(contentType *openapi3.MediaType) {
if isContentTypeHiddenForEnv := isContentTypeHiddenForEnv(contentType, f.metadata.targetEnv); isContentTypeHiddenForEnv {
log.Printf("Removing contentType: %q because is hidden for target env: %q", contentType.Schema.Ref, f.metadata.targetEnv)
contentType.Schema = nil // Remove ContentType if it is hidden for the target environment
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

contentType.Schema = nil // Remove ContentType if it is hidden for the target environment This piece of code was removing the schema instead of the ContentType

Copy link
Collaborator

Choose a reason for hiding this comment

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

but why are we breaking the patterns you stablished in this filter with the f.removeContentIfHiddenForEnv?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The main reason was that we need to pass the k and response.Value.Content as we need them to delete the content.

@andreaangiolillo andreaangiolillo marked this pull request as ready for review July 24, 2024 17:29
@andreaangiolillo andreaangiolillo requested a review from a team as a code owner July 24, 2024 17:29
func ApplyFilters(doc *openapi3.T, metadata *Metadata) error {
if err := initFilters(doc, metadata); err != nil {
return err
func ApplyFiltersWithInit(doc *openapi3.T, metadata *Metadata, init func(oas *openapi3.T, metadata *Metadata) []Filter) (*openapi3.T, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

[nit] I think naming this WithInit leaks filter.go logic that is not necessary. Would make more sense to call this ApplyFilter and pass the filter type, maybe? and do the init logic here instead of outside

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

do you think the problem is the name and/or the fact that we are passing a function returning an array of filters?

I can call the function newFilters if we think init is the problem

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Updated. Let me know what you think

tools/cli/internal/openapi/filter/hidden_envs.go Outdated Show resolved Hide resolved
func (f *HiddenEnvsFilter) removeContentIfHiddenForEnv(contentType *openapi3.MediaType) {
if isContentTypeHiddenForEnv := isContentTypeHiddenForEnv(contentType, f.metadata.targetEnv); isContentTypeHiddenForEnv {
log.Printf("Removing contentType: %q because is hidden for target env: %q", contentType.Schema.Ref, f.metadata.targetEnv)
contentType.Schema = nil // Remove ContentType if it is hidden for the target environment
Copy link
Collaborator

Choose a reason for hiding this comment

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

but why are we breaking the patterns you stablished in this filter with the f.removeContentIfHiddenForEnv?

tools/cli/internal/openapi/versions.go Outdated Show resolved Hide resolved
@andreaangiolillo andreaangiolillo requested review from blva and a team July 25, 2024 09:27
Copy link
Collaborator

@blva blva left a comment

Choose a reason for hiding this comment

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

lgtm thanks for the changes!

@andreaangiolillo andreaangiolillo merged commit bb790a3 into main Jul 25, 2024
6 checks passed
@andreaangiolillo andreaangiolillo deleted the test_future_version branch July 25, 2024 15:29
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.

2 participants