Skip to content

Commit

Permalink
Merge pull request #24186 from sberyozkin/openapi_cors
Browse files Browse the repository at this point in the history
Update OpenApiRecorder to recommend using quarkus.http.cors
  • Loading branch information
gsmet committed Mar 9, 2022
2 parents e385c46 + 597440d commit 18b4520
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
4 changes: 4 additions & 0 deletions docs/src/main/asciidoc/openapi-swaggerui.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,10 @@ rather than `style.css`.

For more information on styling, read this blog entry: https://quarkus.io/blog/stylish-api/

=== Cross Origin Resource Sharing

If you plan to consume this application from a Single Page Application running on a different domain, you will need to configure CORS (Cross-Origin Resource Sharing). Please read the xref:http-reference.adoc#cors-filter[HTTP CORS documentation] for more details.

== Configuration Reference

=== OpenAPI
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@

import org.eclipse.microprofile.openapi.OASFilter;
import org.eclipse.microprofile.openapi.spi.OASFactoryResolver;
import org.jboss.logging.Logger;

import io.quarkus.runtime.LaunchMode;
import io.quarkus.runtime.RuntimeValue;
import io.quarkus.runtime.ShutdownContext;
import io.quarkus.runtime.annotations.Recorder;
Expand All @@ -18,6 +20,7 @@

@Recorder
public class OpenApiRecorder {
private static final Logger log = Logger.getLogger(OpenApiRecorder.class);
final RuntimeValue<HttpConfiguration> configuration;

public OpenApiRecorder(RuntimeValue<HttpConfiguration> configuration) {
Expand All @@ -26,6 +29,9 @@ public OpenApiRecorder(RuntimeValue<HttpConfiguration> configuration) {

public Handler<RoutingContext> handler(OpenApiRuntimeConfig runtimeConfig) {
if (runtimeConfig.enable) {
if (!configuration.getValue().corsEnabled && LaunchMode.NORMAL == LaunchMode.current()) {
log.info("Default CORS properties will be used, please use 'quarkus.http.cors' properties instead");
}
return new OpenApiHandler(configuration.getValue().corsEnabled);
} else {
return new OpenApiNotFoundHandler();
Expand Down

0 comments on commit 18b4520

Please sign in to comment.