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

Changed path_item_finder to detect more complex path template patterns #1

Merged
merged 5 commits into from
Aug 24, 2020

Conversation

makdad
Copy link
Owner

@makdad makdad commented Jul 20, 2020

No description provided.

@ota42y
Copy link

ota42y commented Jul 24, 2020

(from interagent/committee#261)

Hi!
I think there is no problem with the method interface, style, etc... 👍

But there is many bugs
And I think we need to make a big change to fix this problem...
(It seems like a more difficult problem than we expected)

f = OpenAPIParser::PathItemFinder.new([])
f.parse_path_parameters('{p1}.json', 'foo-.jso')
# Should be return nil but {"p1"=>"foo-"}

f.parse_path_parameters('{p1}schedule', 'adminsschedule')
# Should be return 'admins' but {"p1"=>"admin"}

f.parse_path_parameters('{p1}schedule', 'usersschedule')
# Should be return 'usres' but {"p1"=>"u"}

f.parse_path_parameters('{p1}-{p2}.json', 'foo.json')
# Should be return nil but got errors

@makdad
Copy link
Owner Author

makdad commented Aug 3, 2020

@ota42y thanks a lot, I have added a commit with failing specs to cover your feedback. Will work on the implementation for now. I'll close this PR until we have it covered.

@makdad makdad closed this Aug 3, 2020
@ota42y
Copy link

ota42y commented Aug 7, 2020

I think we can convert path parameter to regexp 🤔
( {p1}-{p2}.json -> (.+)-(.+)\.json )

@makdad makdad reopened this Aug 10, 2020
@makdad
Copy link
Owner Author

makdad commented Aug 10, 2020

@ota42y your hunch was correct, this code is so much simpler by relying on the underlying Ruby regex engine. Thank you for the idea! I'm ready for review again; if you think this is reasonable, I can open a PR to the main repository.

@makdad
Copy link
Owner Author

makdad commented Aug 10, 2020

@ota42y The only thing I am not certain about is if we need to Regex.escape the non-parameter portions of the path. I did some various tests via unit testing, but it all seemed to work as-expected. I think the more "invalid" combinations that might generate the situation would not be valid URLs, so it is probably OK?

Copy link

@ota42y ota42y left a comment

Choose a reason for hiding this comment

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

I think there is very good code.

But your concerns need to be checked.
Please check these test case.


regex = schema_path.dup
parameters.each do |parameter|
regex = regex.gsub(parameter, "(?<#{param_name(parameter)}>.+)")
Copy link

Choose a reason for hiding this comment

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

👍 👍 👍

@makdad
Copy link
Owner Author

makdad commented Aug 12, 2020

@ota42y Thanks for pointing this out; I've updated the code to escape the non-parameter components. Also, don't worry about your English - it's great! In the worst case, we can also speak Japanese 👍

@ota42y
Copy link

ota42y commented Aug 23, 2020

Sorry for my late reply, I think this PR is perfect !!! 🎉 🎉 🎉
Thank you for your kind words 👍

@makdad makdad merged commit 8c3b78b into master Aug 24, 2020
@makdad makdad deleted the better-parameter-extraction branch August 24, 2020 01:27
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