Asp.Net Core: Swagger-UI requests not working (are not relative)
Hy
We're using Asp.Net Core to create a REST-Service with Swagger. We're hosting the service at a URL like this:
https://www.mywebsite.com/myservice
With the following code:
applicationBuilder
.UseSwagger()
.UseSwaggerUI(c =>
c.SwaggerEndpoint("../swagger/1.0.0/swagger.json"",title);
c.DisplayRequestDuration();
c.OAuthClientId(clientId);
c.OAuthRealm(redirectUri);
c.OAuthAppName("App");
);
...the Swagger-UI is correctly loading at:
https://www.mywebsite.com/myservice/swagger/
But when I try to do a Request over the UI with the Execute-Button, I got a 404, because the UI tries to do the request without the /myservice/ in the URL:
https://www.mywebsite.com/v1/cars
instead of
https://www.mywebsite.com/myservice/v1/cars
How do I have to correctly configure the service, so that the Swagger UI Calls are also working?
Hint:
This should be done in a generic way (like the ../ of the UI), because we will deploy the service on different environments, so the www.mywebsite.com is not the same on each environment.
Thanks for your help!
Regards,
Peter
asp.net-core swagger swagger-ui relative-url
add a comment |
Hy
We're using Asp.Net Core to create a REST-Service with Swagger. We're hosting the service at a URL like this:
https://www.mywebsite.com/myservice
With the following code:
applicationBuilder
.UseSwagger()
.UseSwaggerUI(c =>
c.SwaggerEndpoint("../swagger/1.0.0/swagger.json"",title);
c.DisplayRequestDuration();
c.OAuthClientId(clientId);
c.OAuthRealm(redirectUri);
c.OAuthAppName("App");
);
...the Swagger-UI is correctly loading at:
https://www.mywebsite.com/myservice/swagger/
But when I try to do a Request over the UI with the Execute-Button, I got a 404, because the UI tries to do the request without the /myservice/ in the URL:
https://www.mywebsite.com/v1/cars
instead of
https://www.mywebsite.com/myservice/v1/cars
How do I have to correctly configure the service, so that the Swagger UI Calls are also working?
Hint:
This should be done in a generic way (like the ../ of the UI), because we will deploy the service on different environments, so the www.mywebsite.com is not the same on each environment.
Thanks for your help!
Regards,
Peter
asp.net-core swagger swagger-ui relative-url
Did you manage to solve this issue?
– gerarddp
Jul 25 '18 at 15:15
add a comment |
Hy
We're using Asp.Net Core to create a REST-Service with Swagger. We're hosting the service at a URL like this:
https://www.mywebsite.com/myservice
With the following code:
applicationBuilder
.UseSwagger()
.UseSwaggerUI(c =>
c.SwaggerEndpoint("../swagger/1.0.0/swagger.json"",title);
c.DisplayRequestDuration();
c.OAuthClientId(clientId);
c.OAuthRealm(redirectUri);
c.OAuthAppName("App");
);
...the Swagger-UI is correctly loading at:
https://www.mywebsite.com/myservice/swagger/
But when I try to do a Request over the UI with the Execute-Button, I got a 404, because the UI tries to do the request without the /myservice/ in the URL:
https://www.mywebsite.com/v1/cars
instead of
https://www.mywebsite.com/myservice/v1/cars
How do I have to correctly configure the service, so that the Swagger UI Calls are also working?
Hint:
This should be done in a generic way (like the ../ of the UI), because we will deploy the service on different environments, so the www.mywebsite.com is not the same on each environment.
Thanks for your help!
Regards,
Peter
asp.net-core swagger swagger-ui relative-url
Hy
We're using Asp.Net Core to create a REST-Service with Swagger. We're hosting the service at a URL like this:
https://www.mywebsite.com/myservice
With the following code:
applicationBuilder
.UseSwagger()
.UseSwaggerUI(c =>
c.SwaggerEndpoint("../swagger/1.0.0/swagger.json"",title);
c.DisplayRequestDuration();
c.OAuthClientId(clientId);
c.OAuthRealm(redirectUri);
c.OAuthAppName("App");
);
...the Swagger-UI is correctly loading at:
https://www.mywebsite.com/myservice/swagger/
But when I try to do a Request over the UI with the Execute-Button, I got a 404, because the UI tries to do the request without the /myservice/ in the URL:
https://www.mywebsite.com/v1/cars
instead of
https://www.mywebsite.com/myservice/v1/cars
How do I have to correctly configure the service, so that the Swagger UI Calls are also working?
Hint:
This should be done in a generic way (like the ../ of the UI), because we will deploy the service on different environments, so the www.mywebsite.com is not the same on each environment.
Thanks for your help!
Regards,
Peter
asp.net-core swagger swagger-ui relative-url
asp.net-core swagger swagger-ui relative-url
asked Jun 20 '18 at 9:35
Peter WyssPeter Wyss
919
919
Did you manage to solve this issue?
– gerarddp
Jul 25 '18 at 15:15
add a comment |
Did you manage to solve this issue?
– gerarddp
Jul 25 '18 at 15:15
Did you manage to solve this issue?
– gerarddp
Jul 25 '18 at 15:15
Did you manage to solve this issue?
– gerarddp
Jul 25 '18 at 15:15
add a comment |
1 Answer
1
active
oldest
votes
Both Swagger
and Swagger UI
need to be configured with relative paths. For example, if I wanted the UI to be accessible at the root of the app (whatever that might be) and the JSON endpoint at swagger/documentName/swagger.json
, my configuration would look like this:
// register the services
services.AddSwaggerGen(c =>
c.SwaggerDoc("latest", new Info Title = "Web API", Version = "latest" );
...
app.UseMvc();
// Enable middleware to serve generated Swagger as a JSON endpoint.
app.UseSwagger(c =>
c.RouteTemplate = "swagger/documentName/swagger.json";
// Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.),
// specifying the Swagger JSON endpoint.
app.UseSwaggerUI(c =>
c.SwaggerEndpoint("swagger/latest/swagger.json", "DynaFile Web API");
c.RoutePrefix = string.Empty; //To serve the Swagger UI at the app's root
And obviously my controllers don't need to know my app name either. For example:
[Route("~/[controller]")]
[ApiController]
public class ValuesController : ControllerBase
....
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f50944920%2fasp-net-core-swagger-ui-requests-not-working-are-not-relative%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Both Swagger
and Swagger UI
need to be configured with relative paths. For example, if I wanted the UI to be accessible at the root of the app (whatever that might be) and the JSON endpoint at swagger/documentName/swagger.json
, my configuration would look like this:
// register the services
services.AddSwaggerGen(c =>
c.SwaggerDoc("latest", new Info Title = "Web API", Version = "latest" );
...
app.UseMvc();
// Enable middleware to serve generated Swagger as a JSON endpoint.
app.UseSwagger(c =>
c.RouteTemplate = "swagger/documentName/swagger.json";
// Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.),
// specifying the Swagger JSON endpoint.
app.UseSwaggerUI(c =>
c.SwaggerEndpoint("swagger/latest/swagger.json", "DynaFile Web API");
c.RoutePrefix = string.Empty; //To serve the Swagger UI at the app's root
And obviously my controllers don't need to know my app name either. For example:
[Route("~/[controller]")]
[ApiController]
public class ValuesController : ControllerBase
....
add a comment |
Both Swagger
and Swagger UI
need to be configured with relative paths. For example, if I wanted the UI to be accessible at the root of the app (whatever that might be) and the JSON endpoint at swagger/documentName/swagger.json
, my configuration would look like this:
// register the services
services.AddSwaggerGen(c =>
c.SwaggerDoc("latest", new Info Title = "Web API", Version = "latest" );
...
app.UseMvc();
// Enable middleware to serve generated Swagger as a JSON endpoint.
app.UseSwagger(c =>
c.RouteTemplate = "swagger/documentName/swagger.json";
// Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.),
// specifying the Swagger JSON endpoint.
app.UseSwaggerUI(c =>
c.SwaggerEndpoint("swagger/latest/swagger.json", "DynaFile Web API");
c.RoutePrefix = string.Empty; //To serve the Swagger UI at the app's root
And obviously my controllers don't need to know my app name either. For example:
[Route("~/[controller]")]
[ApiController]
public class ValuesController : ControllerBase
....
add a comment |
Both Swagger
and Swagger UI
need to be configured with relative paths. For example, if I wanted the UI to be accessible at the root of the app (whatever that might be) and the JSON endpoint at swagger/documentName/swagger.json
, my configuration would look like this:
// register the services
services.AddSwaggerGen(c =>
c.SwaggerDoc("latest", new Info Title = "Web API", Version = "latest" );
...
app.UseMvc();
// Enable middleware to serve generated Swagger as a JSON endpoint.
app.UseSwagger(c =>
c.RouteTemplate = "swagger/documentName/swagger.json";
// Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.),
// specifying the Swagger JSON endpoint.
app.UseSwaggerUI(c =>
c.SwaggerEndpoint("swagger/latest/swagger.json", "DynaFile Web API");
c.RoutePrefix = string.Empty; //To serve the Swagger UI at the app's root
And obviously my controllers don't need to know my app name either. For example:
[Route("~/[controller]")]
[ApiController]
public class ValuesController : ControllerBase
....
Both Swagger
and Swagger UI
need to be configured with relative paths. For example, if I wanted the UI to be accessible at the root of the app (whatever that might be) and the JSON endpoint at swagger/documentName/swagger.json
, my configuration would look like this:
// register the services
services.AddSwaggerGen(c =>
c.SwaggerDoc("latest", new Info Title = "Web API", Version = "latest" );
...
app.UseMvc();
// Enable middleware to serve generated Swagger as a JSON endpoint.
app.UseSwagger(c =>
c.RouteTemplate = "swagger/documentName/swagger.json";
// Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.),
// specifying the Swagger JSON endpoint.
app.UseSwaggerUI(c =>
c.SwaggerEndpoint("swagger/latest/swagger.json", "DynaFile Web API");
c.RoutePrefix = string.Empty; //To serve the Swagger UI at the app's root
And obviously my controllers don't need to know my app name either. For example:
[Route("~/[controller]")]
[ApiController]
public class ValuesController : ControllerBase
....
edited Nov 14 '18 at 18:00
answered Nov 14 '18 at 16:47
MoonStomMoonStom
2,1071718
2,1071718
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f50944920%2fasp-net-core-swagger-ui-requests-not-working-are-not-relative%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Did you manage to solve this issue?
– gerarddp
Jul 25 '18 at 15:15