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

Validation Option to disable strict path parameter uniqueness validation #157

Merged
merged 1 commit into from
Nov 20, 2023

Conversation

dadgar
Copy link
Contributor

@dadgar dadgar commented Oct 12, 2023

Adds a validation option to disable path uniqueness validation behavior where path parameters are ignored. The existing behavior of the validator replaces path parameters with an X and then checks for uniqueness.

As an example, the two paths GET /v1/{book} and GET /v1/{shelve} where book has the pattern shelves/*/book/* and shelve has the pattern shelve/*, get both replaced to /v1/X and an error is returned reporting overlapping paths.

This does not allow the resource name pattern described by Google's AIPs. Further, I do not see it being described in the specification that the path parameters can not have slashes and thus the path can be unique based on the required path parameter.

I will add that I tested other Swagger validators / code generators and they were perfectly happy with paths that are only unique based on unique path parameters.

@dadgar dadgar force-pushed the master branch 2 times, most recently from 1efe773 to b4b6ac8 Compare October 12, 2023 22:10
@codecov
Copy link

codecov bot commented Oct 13, 2023

Codecov Report

Attention: 6 lines in your changes are missing coverage. Please review.

Comparison is base (348543c) 90.60% compared to head (99afba0) 90.60%.

Files Patch % Lines
spec.go 66.66% 3 Missing and 3 partials ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##           master     #157   +/-   ##
=======================================
  Coverage   90.60%   90.60%           
=======================================
  Files          22       22           
  Lines        2990     2991    +1     
=======================================
+ Hits         2709     2710    +1     
  Misses        227      227           
  Partials       54       54           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

dadgar added a commit to dadgar/go-swagger that referenced this pull request Oct 13, 2023
go mod replace github.com/go-openapi/validate with
github.com/dadgar/validate. The forked validate contains the changes
from here: go-openapi/validate#157
@casualjim
Copy link
Member

Wouldn't it make more sense to just turn the error into a warning? And perhaps make this a configurable behavior via an env var or validator config.

Basically, this is a breaking change and while it might not work for your case, others might be depending on the behavior. This tool has been around for a long time

@dadgar
Copy link
Contributor Author

dadgar commented Oct 27, 2023

@casualjim I would be willing to plump it through a config. So you would want the default behavior to be the historic behavior?

As I see it, the validation is enforcing something that is not in the spec and thus didn't warrant keeping the old behavior around; configurable or not.

@casualjim
Copy link
Member

Yeah, it's just that we don't know who is depending on this behavior, and since it's been around for so long, this has become a feature for some and a bug for you. I understand where you're coming from, but the issue is not so critical that it warrants a breaking change. We can easily address both use cases with a simple guard.

Add a validation option to remove strict path uniqueness validation
behavior where path parameters are ignored.

Signed-off-by: Alex Dadgar <alex.dadgar@gmail.com>
@dadgar dadgar changed the title Path validation respects path parameters Validation Option to disable strict path parameter uniqueness validation Nov 1, 2023
@dadgar
Copy link
Contributor Author

dadgar commented Nov 1, 2023

@casualjim Please take another look, added a validation option to switch the behavior and kept the existing default.

@dadgar
Copy link
Contributor Author

dadgar commented Nov 20, 2023

@casualjim would appreciate a look at the updated PR when you have the chance. Thank you.

@casualjim casualjim merged commit 194d97e into go-openapi:master Nov 20, 2023
8 of 9 checks passed
@dadgar
Copy link
Contributor Author

dadgar commented Nov 20, 2023

Thank you!

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

2 participants