dagarcos 2 năm trước cách đây
mục cha
commit
d669929fb7

+ 10 - 3
DBCDS_S13_1_Config/src/main/resources/config/api-gateway.properties

@@ -13,6 +13,7 @@ mailer.auth.name=auth-service
 mailer.auth.path=/auth
 mailer.mail.name=mail-service
 mailer.mail.path=/api/v1
+mailer.docs.path=/docs
 
 eureka.instance.hostname=localhost
 eureka.client.service-url.default-zone=http://127.0.0.1:8761/eureka
@@ -21,13 +22,19 @@ spring.cloud.gateway.discovery.locator.enabled=true
 eureka.instance.instance-id=${spring.application.name}:${random.uuid}
 spring.cloud.loadbalancer.ribbon.enabled=false
 
+server.forward-headers-strategy=framework
+
 spring.cloud.gateway.routes[0].id=${mailer.mail.name}
 spring.cloud.gateway.routes[0].uri=lb://${mailer.mail.name}
 spring.cloud.gateway.routes[0].predicates[0]=Path=${mailer.mail.path}/**
 spring.cloud.gateway.routes[0].filters[0]=AuthFilter
 
-spring.cloud.gateway.routes[1].id=${mailer.auth.name}
-spring.cloud.gateway.routes[1].uri=lb://${mailer.auth.name}
-spring.cloud.gateway.routes[1].predicates[0]=Path=${mailer.auth.path}/**
+spring.cloud.gateway.routes[1].id=${mailer.mail.name}2
+spring.cloud.gateway.routes[1].uri=lb://${mailer.mail.name}
+spring.cloud.gateway.routes[1].predicates[0]=Path=${mailer.docs.path}/**
+
+spring.cloud.gateway.routes[2].id=${mailer.auth.name}
+spring.cloud.gateway.routes[2].uri=lb://${mailer.auth.name}
+spring.cloud.gateway.routes[2].predicates[0]=Path=${mailer.auth.path}/**
 
 

+ 6 - 1
DBCDS_S13_1_Config/src/main/resources/config/mail-service.properties

@@ -11,4 +11,9 @@ mailer.auth.url=http://auth-service/auth
 
 eureka.instance.hostname=localhost
 eureka.client.service-url.default-zone=http://127.0.0.1:8761/eureka
-eureka.instance.instance-id=${spring.application.name}:${random.uuid}
+eureka.instance.instance-id=${spring.application.name}:${random.uuid}
+
+#openapi
+springdoc.api-docs.path=/docs/api-spec
+springdoc.swagger-ui.path=/docs/swagger-ui.html
+springdoc.swagger-ui.operationsSorter=method

+ 2 - 2
DBCDS_S13_1_Gateway/src/main/java/es/uv/garcosda/gateway/config/WebConfig.java

@@ -24,8 +24,8 @@ public class WebConfig extends CorsConfiguration {
         CorsConfiguration config = new CorsConfiguration();
         //config.setAllowCredentials(true);
         config.setAllowedOrigins(List.of("*"));
-        config.setAllowedMethods(List.of("GET", "POST", "PUT", "DELETE", "OPTIONS", "HEAD"));
-        config.setAllowedHeaders(List.of("origin", "content-type", "accept", "authorization", "cookie"));
+        config.setAllowedMethods(List.of("*"));
+        config.setAllowedHeaders(List.of("*"));
 
         UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
         source.registerCorsConfiguration("/**", config);

+ 5 - 0
DBCDS_S13_1_Mail/pom.xml

@@ -46,6 +46,11 @@
 		    <groupId>org.springframework.cloud</groupId>
 		    <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
 		</dependency>
+		<dependency>
+	        <groupId>org.springdoc</groupId>
+	        <artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
+	        <version>2.1.0</version>
+	   </dependency>
 	</dependencies>
 	
 	<dependencyManagement>

+ 31 - 0
DBCDS_S13_1_Mail/src/main/java/es/uv/garcosda/mail/DbcdsS131MailApplication.java

@@ -6,7 +6,38 @@ import org.springframework.cloud.client.loadbalancer.LoadBalanced;
 import org.springframework.context.annotation.Bean;
 import org.springframework.web.client.RestTemplate;
 
+import io.swagger.v3.oas.annotations.OpenAPIDefinition;
+import io.swagger.v3.oas.annotations.info.Contact;
+import io.swagger.v3.oas.annotations.info.Info;
+import io.swagger.v3.oas.annotations.info.License;
+import io.swagger.v3.oas.annotations.security.SecurityScheme;
+import io.swagger.v3.oas.annotations.enums.SecuritySchemeType;
+import io.swagger.v3.oas.annotations.servers.Server;
+
 @SpringBootApplication
+@OpenAPIDefinition(
+  info = @Info(
+    title = "Mailer API",
+    version = "v1",
+    contact = @Contact(
+      name = "Daniel Garcia Costa", email = "daniel.garcia@uv.es", url = "garcosda.uv.es"
+    ),
+    license = @License(
+      name = "Apache 2.0", url = "https://www.apache.org/licenses/LICENSE-2.0"
+    ),
+    description = "This is a simple mailer application developed with spring cloud"
+  ),
+  servers = @Server(
+    url = "127.0.0.1:8080/api/v1",
+    description = "Production"
+  )
+)
+@SecurityScheme(
+	name = "Bearer Authentication",
+	type = SecuritySchemeType.HTTP,
+	bearerFormat = "JWT",
+	scheme = "bearer"
+)
 public class DbcdsS131MailApplication {
 
 	@LoadBalanced

+ 10 - 0
DBCDS_S13_1_Mail/src/main/java/es/uv/garcosda/mail/controllers/MailerController.java

@@ -22,6 +22,8 @@ import org.springframework.web.client.RestTemplate;
 
 import es.uv.garcosda.shared.domain.Mail;
 import es.uv.garcosda.shared.domain.MailDTO;
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.security.SecurityRequirement;
 
 @RestController
 @RequestMapping("/api/v1")
@@ -38,11 +40,15 @@ public class MailerController {
 	private String data_api;
 	
 	@GetMapping("status")
+	@SecurityRequirement(name = "Bearer Authentication")
+	@Operation(summary="Is running?", description="Tests if the service is running")
 	public ResponseEntity<String> test(){
 		return new ResponseEntity<String>("Running", HttpStatus.OK);
 	}
 	
 	@GetMapping("{mail}")
+	@SecurityRequirement(name = "Bearer Authentication")
+	@Operation(summary="Get inbox", description="Get inbox for a certain user by its email")
 	public ResponseEntity<?> getMails(@PathVariable String mail, @RequestHeader("x-auth-user-id") String user){
 		ResponseEntity<MailDTO[]> response;
 		List<MailDTO> mails = new ArrayList<MailDTO>();
@@ -66,6 +72,8 @@ public class MailerController {
 	}
 	
 	@DeleteMapping("{id}")
+	@SecurityRequirement(name = "Bearer Authentication")
+	@Operation(summary="Delete email", description="Delete one email by id")
 	public ResponseEntity<?> deleteMail(@PathVariable String id){
 		try {
 			template.delete(input_api+"/"+id);
@@ -77,6 +85,8 @@ public class MailerController {
 	}
 	
 	@PostMapping
+	@SecurityRequirement(name = "Bearer Authentication")
+	@Operation(summary="Send email", description="Send email to a user")
 	public ResponseEntity<?> sendMail(@RequestBody Mail mail){		
 		ResponseEntity<Mail> response;
 		try {