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

Restier Swagger not applying route prefix #749

Open
DennyFiguerres opened this issue Nov 29, 2023 · 1 comment · May be fixed by #755
Open

Restier Swagger not applying route prefix #749

DennyFiguerres opened this issue Nov 29, 2023 · 1 comment · May be fixed by #755
Milestone

Comments

@DennyFiguerres
Copy link

i configured by Restier with a route prefix of 'odata' and this works when i use it directly but the swagger ui does not seem to have that and errors.
example from swagger ui of wrong example:
curl -X 'GET' \ 'https://localhost:7221/Addresses?%24top=100' \ -H 'accept: application/json'

it should be:
curl -X 'GET' \ 'https://localhost:7221/odata/Addresses?%24top=100' \ -H 'accept: application/json'

also actual output shows :

{ "@odata.context": "https://localhost:7221/odata/$metadata#Addresses", "value": [ { "Id": 1, ... } ] }

Assemblies affected

restier swagger 1.1.0

Reproduce steps

use the sample for noerthwind and just add routprefix and try it.
from my code:
app.UseEndpoints(endpoints => { endpoints.Select().Expand().Filter().OrderBy().MaxTop(100).Count().SetTimeZoneInfo(TimeZoneInfo.Utc); endpoints.MapRestier(builder => { builder.MapApiRoute<RiaODataController>("v1", "odata", true); }); });

Expected result

swagger ui would show the route as
curl -X 'GET' \ 'https://localhost:7221/odata/Addresses?%24top=100' \ -H 'accept: application/json'
and the ui "try it" button would return data

Actual result

http error 404 - not found

@robertmclaws robertmclaws added this to the 1.1.1 milestone Dec 5, 2023
0xced added a commit to 0xced/RESTier that referenced this issue Jan 25, 2024
## Before this commit

When mapping a Restier route with a non empty route prefix, the generated swagger file does not include the route prefix in the `servers[0].url` property.

```csharp
app.MapRestier(restier => restier.MapApiRoute<EntityFrameworkApi<MyDbContext>>(routeName: "RestierDefault", routePrefix: "api"));
```

❌ The generated url is `http://localhost:5000`, making all requests from SwaggerUI fail with 404 errors.

## After this commit

The route prefix is included in the generated swagger file in the `servers[0].url` property.

✅ The generated url is `http://localhost:5000/api/`, making SwaggerUI usable.

Fixes OData#749
@0xced 0xced linked a pull request Jan 25, 2024 that will close this issue
@0xced
Copy link
Contributor

0xced commented Jan 25, 2024

I just submitted #755 which will fix this issue.

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.

3 participants