OpenApiParser - Construction of path possibly incorrect #676

Closed
opened 2025-12-29 08:32:23 +01:00 by adam · 1 comment
Owner

Originally created by @rossknudsen on GitHub (Mar 16, 2025).

Originally assigned to: @StefH on GitHub.

Hi,

So I'm experimenting with the OpenApiParser to quickly generate a mock for our API. I'm not very familiar with this software, so it may be an issue with my understanding. The issue is that the patterns that are generated for the paths seem to be incorrect. We have a path like:

paths:
  '/customers/{customerId}':
    post:

And the generated path match is this: ^//customers/example-value$. The problem is the presence of two forward slashes at the beginning of the route. I think the issue occurs in this line here:

db158bcc7e/src/WireMock.Net.OpenApiParser/Mappers/OpenApiPathsMapper.cs (L106)

The call to MapBasePath(servers) produces "/" and the call to MapPathWithParameters(path, parameters) produces "/customers/example-value". I think I understand that we are trying to prefix our routes with any path segment(s) that are on the server base path. However, the logic doesn't seem to account for the absence of any path segments (as my servers do not have any paths or trailing slash).

Maybe the combining of these strings needs to be more sophisticated to account for this scenario?

Originally created by @rossknudsen on GitHub (Mar 16, 2025). Originally assigned to: @StefH on GitHub. Hi, So I'm experimenting with the OpenApiParser to quickly generate a mock for our API. I'm not very familiar with this software, so it may be an issue with my understanding. The issue is that the patterns that are generated for the paths seem to be incorrect. We have a path like: ``` paths: '/customers/{customerId}': post: ``` And the generated path match is this: `^//customers/example-value$`. The problem is the presence of two forward slashes at the beginning of the route. I think the issue occurs in this line here: https://github.com/WireMock-Net/WireMock.Net/blob/db158bcc7eb8195c5ae13665c67286865827275b/src/WireMock.Net.OpenApiParser/Mappers/OpenApiPathsMapper.cs#L106 The call to `MapBasePath(servers)` produces `"/"` and the call to `MapPathWithParameters(path, parameters)` produces `"/customers/example-value"`. I think I understand that we are trying to prefix our routes with any path segment(s) that are on the server base path. However, the logic doesn't seem to account for the absence of any path segments (as my servers do not have any paths or trailing slash). Maybe the combining of these strings needs to be more sophisticated to account for this scenario?
adam added the bug label 2025-12-29 08:32:23 +01:00
adam closed this issue 2025-12-29 08:32:23 +01:00
Author
Owner

@StefH commented on GitHub (Mar 17, 2025):

You are correct.

I've updated to the code.

https://github.com/WireMock-Net/WireMock.Net/pull/1265

@StefH commented on GitHub (Mar 17, 2025): You are correct. I've updated to the code. https://github.com/WireMock-Net/WireMock.Net/pull/1265
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/WireMock.Net#676