-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from Hangar-Tech/feat-add-swagger
Feat add swagger
- Loading branch information
Showing
14 changed files
with
233 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,28 +7,40 @@ | |
import com.institutosemprealerta.semprealerta.infrastructure.entity.user.User; | ||
import com.institutosemprealerta.semprealerta.infrastructure.entity.user.UserRoles; | ||
import com.institutosemprealerta.semprealerta.utils.DateManipulation; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import jakarta.validation.constraints.*; | ||
|
||
import java.time.LocalDate; | ||
import java.time.format.DateTimeFormatter; | ||
|
||
public record UserDTO( | ||
@NotBlank | ||
@Schema(description = "Nome do usuário", example = "Matheus Victor") | ||
String name, | ||
@Schema(description = "Email do usuário", example = "[email protected]") | ||
String email, | ||
@NotBlank | ||
@Schema(description = "Senha do usuário", example = "123456") | ||
String password, | ||
@NotBlank | ||
@Schema(description = "Telefone do usuário", example = "123456") | ||
String phone, | ||
@Schema(description = "Gênero do usuário", example = "Masculino") | ||
String gender, | ||
@PastOrPresent | ||
@Schema(description = "Data de nascimento do usuário", example = "1999-12-12") | ||
LocalDate birthDate, | ||
@NotNull | ||
@Schema(description = "Papel do usuário", example = "ADMIN") | ||
UserRoles roles, | ||
@Schema(description = "Rua do usuário", example = "Rua 1") | ||
String street, | ||
@Schema(description = "Número da casa do usuário", example = "123") | ||
String number, | ||
@Schema(description = "Cidade do usuário", example = "Igarassu e Lima") | ||
String city, | ||
@Schema(description = "CEP do usuário", example = "123456") | ||
String zipCode | ||
|
||
) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,12 +2,22 @@ | |
|
||
import com.institutosemprealerta.semprealerta.domain.ports.in.SlugGenerator; | ||
import com.institutosemprealerta.semprealerta.domain.ports.in.impl.SlugifySlugGenerator; | ||
import io.swagger.v3.oas.models.Components; | ||
import io.swagger.v3.oas.models.OpenAPI; | ||
import io.swagger.v3.oas.models.info.Contact; | ||
import io.swagger.v3.oas.models.info.Info; | ||
import io.swagger.v3.oas.models.info.License; | ||
import io.swagger.v3.oas.models.security.SecurityRequirement; | ||
import io.swagger.v3.oas.models.security.SecurityScheme; | ||
import io.swagger.v3.oas.models.servers.Server; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.data.domain.PageRequest; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.data.domain.Sort; | ||
|
||
import java.util.List; | ||
|
||
@Configuration | ||
public class ApplicationConfig { | ||
|
||
|
@@ -20,4 +30,29 @@ public SlugGenerator slugGenerator() { | |
public Pageable defaultPageable() { | ||
return PageRequest.of(0, 10, Sort.by("createdAt").descending()); | ||
} | ||
|
||
public SecurityScheme createAPIKeyScheme() { | ||
return new SecurityScheme() | ||
.type(SecurityScheme.Type.HTTP) | ||
.bearerFormat("JWT") | ||
.scheme("bearer"); | ||
} | ||
|
||
@Bean | ||
public OpenAPI openAPI() { | ||
return new OpenAPI() | ||
.addSecurityItem(new SecurityRequirement() | ||
.addList("Bearer Authentication")) | ||
.components(new Components().addSecuritySchemes( | ||
"Bearer Authentication", | ||
createAPIKeyScheme() | ||
)) | ||
.info(new Info().title("Instituto Sempre Alerta API") | ||
.description("API do Instituto Sempre Alerta.") | ||
.version("1.0").contact(new Contact().name("Matheus Victor") | ||
.email("[email protected]") | ||
.url("https://www.instituto-sempre-alerta.com.br/")) | ||
.license(new License().name("License of API") | ||
.url("https://opensource.org/license/mit/"))); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
...n/java/com/institutosemprealerta/semprealerta/swagger/annotations/BadRequestResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.institutosemprealerta.semprealerta.swagger.annotations; | ||
|
||
import com.institutosemprealerta.semprealerta.domain.ports.out.exceptions.ExceptionPattern; | ||
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 java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
@Target({ElementType.METHOD, ElementType.TYPE}) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@ApiResponse(responseCode = "400", description = "Erro de requisição inválida, no lado do cliente", | ||
content = @Content(mediaType = "application/json", schema = @Schema(implementation = ExceptionPattern.class))) | ||
public @interface BadRequestResponse { | ||
} |
18 changes: 18 additions & 0 deletions
18
...ain/java/com/institutosemprealerta/semprealerta/swagger/annotations/ConflictResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.institutosemprealerta.semprealerta.swagger.annotations; | ||
|
||
import com.institutosemprealerta.semprealerta.domain.ports.out.exceptions.ExceptionPattern; | ||
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 java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
@Target({ElementType.METHOD, ElementType.TYPE}) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@ApiResponse(responseCode = "409", description = "Possui alguns conflitos na requisição", | ||
content = @Content(mediaType = "application/json", schema = @Schema(implementation = ExceptionPattern.class))) | ||
public @interface ConflictResponse { | ||
} |
Oops, something went wrong.