From 82d9e935e9a5e890333b51b6fc4972fadd74ee59 Mon Sep 17 00:00:00 2001 From: Christophe Bornet Date: Thu, 17 May 2018 13:55:51 +0000 Subject: [PATCH] Add CORS configuration (#71) --- .../codegen/online/OpenAPI2SpringBoot.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/modules/openapi-generator-online/src/main/java/org/openapitools/codegen/online/OpenAPI2SpringBoot.java b/modules/openapi-generator-online/src/main/java/org/openapitools/codegen/online/OpenAPI2SpringBoot.java index 45000a9bdde..6e525d8fdba 100644 --- a/modules/openapi-generator-online/src/main/java/org/openapitools/codegen/online/OpenAPI2SpringBoot.java +++ b/modules/openapi-generator-online/src/main/java/org/openapitools/codegen/online/OpenAPI2SpringBoot.java @@ -21,7 +21,10 @@ import org.springframework.boot.CommandLineRunner; import org.springframework.boot.ExitCodeGenerator; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; +import org.springframework.web.servlet.config.annotation.CorsRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; @SpringBootApplication @ComponentScan(basePackages = { "org.openapitools.codegen.online", "org.openapitools.codegen.online.api", "org.openapitools.codegen.online.configuration"}) @@ -47,4 +50,14 @@ public class OpenAPI2SpringBoot implements CommandLineRunner { } } + + @Bean + public WebMvcConfigurer corsConfigurer() { + return new WebMvcConfigurer() { + @Override + public void addCorsMappings(CorsRegistry registry) { + registry.addMapping("/**").allowedOrigins("*").allowedHeaders("Content-Type"); + } + }; + } }