Skip to content

Commit 7ebb478

Browse files
committed
feat: Adicionar segurança no Swagger API (OpenAPI 3). Usando o próprio spring security (#10).
1 parent c456d97 commit 7ebb478

File tree

6 files changed

+84
-174
lines changed

6 files changed

+84
-174
lines changed

README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,37 @@ Para encerrar o projeto, execute (dentro da pasta `target`):
154154
Nada será necessário, o projeto é executado como `Fat jar`. Mas para produção e homologação, é possível usar as imagens geradas pelo comando: `mvn clean package -Pdocker`. Muito importante para o uso do CI.
155155

156156

157+
# Banco de dados
158+
159+
O projeto usa o mongo para banco de dados. Recomendo que utilize o projeto [danielso2007/dockerMongoDB](https://github.com/danielso2007/dockerMongoDB) para executar o mongo em docker. Há dois arquivos `book.js` e `rating.js` que podem ser usados para importar dados no banco.
160+
161+
Segue a configuração padrão do banco, mas cada profile do `POM` tem seu database.
162+
- host: localhost
163+
- port: 27017
164+
- database: virtuallibraryapi
165+
- username: root
166+
- password: 112358
167+
168+
Execute o arquivo `./mongoimport.sh` e informe:
169+
170+
- Importando arquivo para o MongoDB...
171+
- Infome o nome do banco de dados:
172+
- `virtuallibraryapi`
173+
- Infome collection:
174+
- `book`
175+
- Infome o nome do arquivo JSON:
176+
- `book.json`
177+
178+
Depois para o `rating`:
179+
180+
- Importando arquivo para o MongoDB...
181+
- Infome o nome do banco de dados:
182+
- `virtuallibraryapi`
183+
- Infome collection:
184+
- `rating`
185+
- Infome o nome do arquivo JSON:
186+
- `rating.json`
187+
157188
## Built With
158189

159190
* [Java](https://www.oracle.com/br/java/)

package-lock.json

Lines changed: 27 additions & 169 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,12 +158,12 @@
158158
<dependency>
159159
<groupId>org.jboss.xnio</groupId>
160160
<artifactId>xnio-nio</artifactId>
161-
<version>3.7.7.Final</version>
161+
<version>3.8.0.Final</version>
162162
</dependency>
163163
<dependency>
164164
<groupId>org.jboss.threads</groupId>
165165
<artifactId>jboss-threads</artifactId>
166-
<version>3.0.0.Final</version>
166+
<version>3.1.0.Final</version>
167167
</dependency>
168168
</dependencies>
169169

src/main/java/br/com/virtuallibrary/config/OpenApiConfig.java

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package br.com.virtuallibrary.config;
22

3+
import java.util.ArrayList;
4+
import java.util.List;
5+
36
import org.springframework.context.annotation.Bean;
47
import org.springframework.context.annotation.Configuration;
58

@@ -8,6 +11,7 @@
811
import io.swagger.v3.oas.models.info.Contact;
912
import io.swagger.v3.oas.models.info.Info;
1013
import io.swagger.v3.oas.models.info.License;
14+
import io.swagger.v3.oas.models.servers.Server;
1115

1216
@Configuration
1317
public class OpenApiConfig {
@@ -23,16 +27,31 @@ public OpenAPI customOpenAPI() {
2327
license.setName("Apache 2.0");
2428
license.setUrl("http://www.apache.org/licenses/LICENSE-2.0.html");
2529

30+
List<Server> servers = new ArrayList<>();
31+
32+
Server dev = new Server();
33+
dev.setUrl("http://localhost:8080");
34+
dev.setDescription("DEV Server");
35+
36+
Server prod = new Server();
37+
prod.setUrl("http://localhost:8080");
38+
prod.setDescription("PROD Server");
39+
40+
servers.add(dev);
41+
servers.add(prod);
42+
43+
Components components = new Components();
44+
2645
return new OpenAPI()
27-
.components(new Components())
46+
.components(components)
2847
.info(new Info()
2948
.title("Virtual Library REST API")
3049
.description("API para cadastro e consulta de livros.")
3150
.version("0.4.0")
3251
.termsOfService("https://smartbear.com/terms-of-use/")
3352
.contact(contact)
3453
.license(license)
35-
);
54+
).servers(servers);
3655
}
3756

3857
}

src/test/java/br/com/virtuallibrary/othertests/BookModelTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public void testEqualsObjectBookModel() {
5050
assertTrue(entity.equals(entity));
5151
}
5252

53+
@SuppressWarnings("unlikely-arg-type")
5354
@Test
5455
public void testEqualsObjectNoBookModel() {
5556
assertTrue(!entity.equals(Integer.getInteger("12")));

src/test/java/br/com/virtuallibrary/othertests/BookTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,10 @@ public void testEqualsObjectBook() {
5050
assertTrue(entity.equals(entity));
5151
}
5252

53+
@SuppressWarnings("unlikely-arg-type")
5354
@Test
5455
public void testEqualsObjectNoBook() {
55-
assertTrue(!entity.equals(Integer.getInteger("12")));
56+
assertTrue(!entity.equals(Integer.parseInt("12")));
5657
}
5758

5859
@Test

0 commit comments

Comments
 (0)