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

Path with several "{...}" incorrectly parsed #358

Closed
dedece35 opened this issue Mar 29, 2022 · 2 comments · Fixed by #359
Closed

Path with several "{...}" incorrectly parsed #358

dedece35 opened this issue Mar 29, 2022 · 2 comments · Fixed by #359

Comments

@dedece35
Copy link
Contributor

dedece35 commented Mar 29, 2022

Explanation

When a path contains several variables with "{}" characters, the template computed for this URL is incorrect.

Example with URL template computed correctly :

  • path : /avis/by_id_utilisateur-{id_utilisateur}
  • template computed : /avis/by_id_utilisateur-{}

Example with URL template incorrect :

  • path : /avis/by_id_utilisateur-{id_utilisateur}_code_support-{code_support}
  • template computed : /avis/by_id_utilisateur-{}

If we have an API with these two paths, /avis/by_id_utilisateur-{id_utilisateur} and /avis/by_id_utilisateur-{id_utilisateur}_code_support-{code_support}
thus de verification will fail with an error Two path items have the same signature: /avis/by_id_utilisateur-{}.
This is because of wrong templates computed during the control process.

Analysis / Solution

After, an analysis of code, this template URL computation was made by a method that does a replace from a regex pattern.

...
public class PathsDiff {
  private static final String REGEX_PATH = "\\{([^/]+)}";
  ...  
  private static String normalizePath(String path) {
    return path.replaceAll(REGEX_PATH, "{}");
  }
  ...
}

This pattern is wrong, we should have "\{([^/{}]+)}" to exclude "{" and "}" from detection.
I tested this pattern locally and it's ok for me with this last regex pattern.

If you want I can correct it. I will create a PR if nobody does it before me :p

thanks.

David.

@dedece35 dedece35 changed the title Path with several "{}" incorrectly parsed Path with several "{...}" incorrectly parsed Mar 29, 2022
dedece35 pushed a commit to dedece35/openapi-diff that referenced this issue Mar 29, 2022
dedece35 pushed a commit to dedece35/openapi-diff that referenced this issue Mar 29, 2022
@dedece35
Copy link
Contributor Author

dedece35 commented Mar 29, 2022

you can see the PR : #359

joschi pushed a commit that referenced this issue Jun 7, 2022
@dedece35
Copy link
Contributor Author

dedece35 commented Jun 8, 2022

hello @joschi
thank you for your review and merge.

when do you think that there will be a new release ?

thank you.

best regards,
David

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 a pull request may close this issue.

2 participants
@dedece35 and others