add openapi docs
This commit is contained in:
parent
042fd2637e
commit
d9f93f42c3
6 changed files with 79 additions and 69 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
plugins {
|
plugins {
|
||||||
id 'java'
|
id 'java'
|
||||||
id 'org.springframework.boot' version '3.5.8'
|
id 'org.springframework.boot' version '3.3.5'
|
||||||
id 'io.spring.dependency-management' version '1.1.7'
|
id 'io.spring.dependency-management' version '1.1.7'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -15,34 +15,37 @@ java {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
repositories {
|
|
||||||
mavenCentral()
|
|
||||||
}
|
|
||||||
|
|
||||||
ext {
|
// ext {
|
||||||
set('springCloudVersion', "2025.0.0")
|
// springCloudVersion = "2023.0.3"
|
||||||
}
|
// }
|
||||||
|
|
||||||
dependencies {
|
// dependencies {
|
||||||
// 🔥 ESSENCIAL — traz SpringApplication
|
|
||||||
implementation 'org.springframework.boot:spring-boot-starter'
|
|
||||||
|
|
||||||
implementation 'org.springframework.boot:spring-boot-starter-web'
|
// implementation 'br.com.rayan:hd-commons-lib:1.0.0'
|
||||||
implementation 'org.springframework.boot:spring-boot-starter-data-mongodb'
|
|
||||||
|
|
||||||
compileOnly 'org.projectlombok:lombok'
|
// implementation 'org.springframework.boot:spring-boot-starter'
|
||||||
developmentOnly 'org.springframework.boot:spring-boot-devtools'
|
// implementation 'org.springframework.boot:spring-boot-starter-web'
|
||||||
annotationProcessor 'org.projectlombok:lombok'
|
// implementation 'org.springframework.boot:spring-boot-starter-data-mongodb'
|
||||||
|
// implementation 'org.springframework.boot:spring-boot-starter-validation'
|
||||||
|
|
||||||
testImplementation 'org.springframework.boot:spring-boot-starter-test'
|
// // Swagger / OpenAPI (compatível com Spring Boot 3.3.x)
|
||||||
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
|
// implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.3.0'
|
||||||
}
|
|
||||||
|
|
||||||
dependencyManagement {
|
// compileOnly 'org.projectlombok:lombok'
|
||||||
imports {
|
// annotationProcessor 'org.projectlombok:lombok'
|
||||||
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
|
|
||||||
}
|
// implementation 'org.mapstruct:mapstruct:1.5.3.Final'
|
||||||
}
|
// annotationProcessor 'org.mapstruct:mapstruct-processor:1.5.3.Final'
|
||||||
|
|
||||||
|
// testImplementation 'org.springframework.boot:spring-boot-starter-test'
|
||||||
|
// }
|
||||||
|
|
||||||
|
// dependencyManagement {
|
||||||
|
// imports {
|
||||||
|
// mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
tasks.named('test') {
|
tasks.named('test') {
|
||||||
useJUnitPlatform()
|
useJUnitPlatform()
|
||||||
|
|
|
||||||
|
|
@ -6,48 +6,33 @@ repositories {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ext {
|
||||||
|
springCloudVersion = "2023.0.3"
|
||||||
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
|
||||||
implementation 'br.com.rayan:hd-commons-lib:1.0.0'
|
implementation 'br.com.rayan:hd-commons-lib:1.0.0'
|
||||||
|
|
||||||
// Starter para desenvolvimento de aplicativos web com Spring Boot
|
implementation 'org.springframework.boot:spring-boot-starter'
|
||||||
implementation 'org.springframework.boot:spring-boot-starter-web'
|
implementation 'org.springframework.boot:spring-boot-starter-web'
|
||||||
|
|
||||||
// Starter para configuração do Spring Cloud Config
|
|
||||||
implementation 'org.springframework.cloud:spring-cloud-starter-config'
|
|
||||||
|
|
||||||
// Starter para configuração do Spring Cloud
|
|
||||||
implementation 'org.springframework.cloud:spring-cloud-starter-bootstrap'
|
|
||||||
|
|
||||||
// Starter para integração com o Eureka Discovery Client
|
|
||||||
// implementation 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-client'
|
|
||||||
|
|
||||||
// Starter para acesso a dados com o MongoDB
|
|
||||||
implementation 'org.springframework.boot:spring-boot-starter-data-mongodb'
|
implementation 'org.springframework.boot:spring-boot-starter-data-mongodb'
|
||||||
|
|
||||||
// Starter para validação de dados
|
|
||||||
implementation 'org.springframework.boot:spring-boot-starter-validation'
|
implementation 'org.springframework.boot:spring-boot-starter-validation'
|
||||||
|
|
||||||
// Starter para geração de documentação OpenAPI com Springdoc
|
// Swagger / OpenAPI (compatível com Spring Boot 3.3.x)
|
||||||
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.0.4'
|
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.3.0'
|
||||||
|
|
||||||
// Lombok
|
|
||||||
compileOnly 'org.projectlombok:lombok'
|
compileOnly 'org.projectlombok:lombok'
|
||||||
annotationProcessor 'org.projectlombok:lombok'
|
annotationProcessor 'org.projectlombok:lombok'
|
||||||
|
|
||||||
// Binding para o MapStruct com Lombok
|
|
||||||
implementation 'org.projectlombok:lombok-mapstruct-binding:0.2.0'
|
|
||||||
|
|
||||||
// MapStruct
|
|
||||||
implementation 'org.mapstruct:mapstruct:1.5.3.Final'
|
implementation 'org.mapstruct:mapstruct:1.5.3.Final'
|
||||||
annotationProcessor 'org.mapstruct:mapstruct-processor:1.5.3.Final'
|
annotationProcessor 'org.mapstruct:mapstruct-processor:1.5.3.Final'
|
||||||
|
|
||||||
// Dependência de teste
|
|
||||||
testImplementation 'org.springframework.boot:spring-boot-starter-test'
|
testImplementation 'org.springframework.boot:spring-boot-starter-test'
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencyManagement {
|
dependencyManagement {
|
||||||
imports {
|
imports {
|
||||||
mavenBom "org.springframework.cloud:spring-cloud-dependencies:2022.0.2"
|
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,11 @@
|
||||||
|
package br.com.rayankonecny.userserviceapi.config;
|
||||||
|
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.OpenAPIDefinition;
|
||||||
|
import io.swagger.v3.oas.annotations.info.Info;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
@OpenAPIDefinition(info = @Info(title = "User Service API", version = "1.0.0", description = "Component responsible for user management created on Spring Boot"))
|
||||||
|
public class OpenAPIConfig {
|
||||||
|
}
|
||||||
|
|
@ -4,13 +4,29 @@ import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.PathVariable;
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
import io.swagger.v3.oas.annotations.Parameter;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Content;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||||
|
import io.swagger.v3.oas.annotations.responses.ApiResponses;
|
||||||
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
import main.java.models.exceptions.StandardError;
|
||||||
import main.java.models.responses.UserResponse;
|
import main.java.models.responses.UserResponse;
|
||||||
|
|
||||||
|
@Tag(name = "User Controller", description = "Controller responsible for user operations")
|
||||||
@RequestMapping("/api/users")
|
@RequestMapping("/api/users")
|
||||||
public interface UserController {
|
public interface UserController {
|
||||||
|
|
||||||
|
@Operation(summary = "Find User by ID", description = "Retrieve user information by user ID")
|
||||||
|
@ApiResponses(value = {
|
||||||
|
@ApiResponse(responseCode = "200", description = "User found successfully"),
|
||||||
|
@ApiResponse(responseCode = "404", description = "User not found", content = @Content(mediaType = "application/json", schema = @Schema(implementation = StandardError.class))),
|
||||||
|
@ApiResponse(responseCode = "500", description = "Internal server error", content = @Content(mediaType = "application/json", schema = @Schema(implementation = StandardError.class))),
|
||||||
|
})
|
||||||
@GetMapping("/{id}")
|
@GetMapping("/{id}")
|
||||||
ResponseEntity<UserResponse> findById(@PathVariable(name = "id") final String id);
|
ResponseEntity<UserResponse> findById(
|
||||||
|
@Parameter(description = "User id", required = true, example = "6927c8c75efcfda14c3ea570")
|
||||||
|
@PathVariable(name = "id") final String id);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,20 +0,0 @@
|
||||||
spring.application.name=user-service-api
|
|
||||||
|
|
||||||
# Configuração do MongoDB
|
|
||||||
spring.data.mongodb.host=175.15.15.6
|
|
||||||
spring.data.mongodb.port=27017
|
|
||||||
spring.data.mongodb.database=olympdb
|
|
||||||
spring.data.mongodb.username=admin
|
|
||||||
spring.data.mongodb.password=admin
|
|
||||||
spring.data.mongodb.authentication-database=admin
|
|
||||||
|
|
||||||
|
|
||||||
# Eureka Server Configuration
|
|
||||||
eureka.client.register-with-eureka=true
|
|
||||||
eureka.client.fetch-registry=true
|
|
||||||
eureka.client.serviceUrl.defaultZone=http://175.15.15.91:8761/eureka/
|
|
||||||
eureka.instance.prefer-ip-address=true
|
|
||||||
eureka.instance.ip-address=175.15.15.91
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
15
user-service-api/src/main/resources/application.yml
Normal file
15
user-service-api/src/main/resources/application.yml
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
spring:
|
||||||
|
application:
|
||||||
|
name: user-service-api
|
||||||
|
data:
|
||||||
|
mongodb:
|
||||||
|
uri: mongodb://175.15.15.6:27017/olympdb
|
||||||
|
auto-index-creation: true
|
||||||
|
|
||||||
|
springdoc:
|
||||||
|
api-docs:
|
||||||
|
enabled: true
|
||||||
|
path: /v3/api-docs
|
||||||
|
swagger-ui:
|
||||||
|
enabled: true
|
||||||
|
path: /swagger-ui.html
|
||||||
Loading…
Add table
Reference in a new issue