Compare commits
3 Commits
swagger-oa
...
master
Author | SHA1 | Date | |
---|---|---|---|
2884979a4e | |||
ee4f6f0a02 | |||
fb40f340ea |
37
pom.xml
37
pom.xml
@ -2,11 +2,10 @@
|
|||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-parent -->
|
|
||||||
<parent>
|
<parent>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-parent</artifactId>
|
<artifactId>spring-boot-starter-parent</artifactId>
|
||||||
<version>3.3.5</version>
|
<version>2.7.1</version>
|
||||||
<relativePath/> <!-- lookup parent from repository -->
|
<relativePath/> <!-- lookup parent from repository -->
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
@ -18,7 +17,11 @@
|
|||||||
<description>Demo project for Swagger</description>
|
<description>Demo project for Swagger</description>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<java.version>21</java.version>
|
<java.version>17</java.version>
|
||||||
|
<maven.compiler.source>${java.version}</maven.compiler.source>
|
||||||
|
<maven.compiler.target>${java.version}</maven.compiler.target>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
@ -26,16 +29,21 @@
|
|||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-web</artifactId>
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework.boot</groupId>
|
|
||||||
<artifactId>spring-boot-starter-oauth2-client</artifactId>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- https://mvnrepository.com/artifact/org.springdoc/springdoc-openapi-starter-webmvc-ui -->
|
<dependency>
|
||||||
|
<groupId>io.swagger.core.v3</groupId>
|
||||||
|
<artifactId>swagger-annotations</artifactId>
|
||||||
|
<version>2.2.1</version>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springdoc</groupId>
|
<groupId>org.springdoc</groupId>
|
||||||
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
|
<artifactId>springdoc-openapi-ui</artifactId>
|
||||||
<version>2.6.0</version>
|
<version>1.6.9</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-validation</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
@ -48,13 +56,4 @@
|
|||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
<developers>
|
|
||||||
<developer>
|
|
||||||
<id>uPagge</id>
|
|
||||||
<name>Struchkov Mark</name>
|
|
||||||
<email>mark@struchkov.dev</email>
|
|
||||||
<url>https://mark.struchkov.dev</url>
|
|
||||||
</developer>
|
|
||||||
</developers>
|
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
@ -1,44 +0,0 @@
|
|||||||
package org.sadtech.example.swagger.config;
|
|
||||||
|
|
||||||
import io.swagger.v3.oas.annotations.OpenAPIDefinition;
|
|
||||||
import io.swagger.v3.oas.annotations.enums.SecuritySchemeIn;
|
|
||||||
import io.swagger.v3.oas.annotations.enums.SecuritySchemeType;
|
|
||||||
import io.swagger.v3.oas.annotations.info.Contact;
|
|
||||||
import io.swagger.v3.oas.annotations.info.Info;
|
|
||||||
import io.swagger.v3.oas.annotations.security.SecurityScheme;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author upagge 30.12.2020
|
|
||||||
*/
|
|
||||||
@OpenAPIDefinition(
|
|
||||||
info = @Info(
|
|
||||||
title = "Loyalty System Api",
|
|
||||||
description = "Loyalty System", version = "1.0.0",
|
|
||||||
contact = @Contact(
|
|
||||||
name = "Struchkov Mark",
|
|
||||||
email = "mark@struchkov.dev",
|
|
||||||
url = "https://mark.struchkov.dev"
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
//@SecurityScheme(
|
|
||||||
// name = "Oauth2",
|
|
||||||
// type = SecuritySchemeType.OAUTH2,
|
|
||||||
// flows = @OAuthFlows(
|
|
||||||
// authorizationCode = @OAuthFlow(
|
|
||||||
// tokenUrl = "https://oauth.mocklab.io/oauth/token",
|
|
||||||
// refreshUrl = "https://oauth.mocklab.io/oauth/token",
|
|
||||||
// authorizationUrl = "https://oauth.mocklab.io/oauth/authorize",
|
|
||||||
// scopes = {@OAuthScope(name = "profile"), @OAuthScope(name = "email")}
|
|
||||||
// )
|
|
||||||
// )
|
|
||||||
//)
|
|
||||||
@SecurityScheme(
|
|
||||||
name = "jsessionid",
|
|
||||||
in = SecuritySchemeIn.COOKIE,
|
|
||||||
type = SecuritySchemeType.APIKEY,
|
|
||||||
paramName = "JSESSIONID"
|
|
||||||
)
|
|
||||||
public class OpenApiConfig {
|
|
||||||
|
|
||||||
}
|
|
@ -1,28 +0,0 @@
|
|||||||
package org.sadtech.example.swagger.config;
|
|
||||||
|
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
|
||||||
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
|
||||||
import org.springframework.security.web.SecurityFilterChain;
|
|
||||||
|
|
||||||
@Configuration
|
|
||||||
@EnableWebSecurity
|
|
||||||
public class SecurityConfig {
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
|
|
||||||
return http
|
|
||||||
.cors().disable()
|
|
||||||
.oauth2Login()
|
|
||||||
.and()
|
|
||||||
.authorizeHttpRequests(
|
|
||||||
registry -> registry
|
|
||||||
.requestMatchers("/v3/api-docs/**", "/swagger-ui/**", "/swagger-ui.html")
|
|
||||||
.permitAll()
|
|
||||||
.anyRequest().authenticated()
|
|
||||||
)
|
|
||||||
.build();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -0,0 +1,31 @@
|
|||||||
|
package org.sadtech.example.swagger.config;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.models.OpenAPI;
|
||||||
|
import io.swagger.v3.oas.models.info.Contact;
|
||||||
|
import io.swagger.v3.oas.models.info.Info;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author upagge 30.12.2020
|
||||||
|
*/
|
||||||
|
@Configuration
|
||||||
|
public class SwaggerConfig {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public OpenAPI customOpenAPI() {
|
||||||
|
return new OpenAPI()
|
||||||
|
.info(
|
||||||
|
new Info()
|
||||||
|
.title("Loyalty System Api")
|
||||||
|
.version("1.0.0")
|
||||||
|
.contact(
|
||||||
|
new Contact()
|
||||||
|
.email("me@upagge.ru")
|
||||||
|
.url("https://uPagge.ru")
|
||||||
|
.name("Struchkov Mark")
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -2,23 +2,19 @@ package org.sadtech.example.swagger.controller;
|
|||||||
|
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
import io.swagger.v3.oas.annotations.Parameter;
|
import io.swagger.v3.oas.annotations.Parameter;
|
||||||
import io.swagger.v3.oas.annotations.enums.ParameterIn;
|
|
||||||
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
|
||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
import jakarta.validation.constraints.Min;
|
|
||||||
import jakarta.validation.constraints.NotBlank;
|
|
||||||
import org.sadtech.example.swagger.dto.TypeOperation;
|
import org.sadtech.example.swagger.dto.TypeOperation;
|
||||||
import org.sadtech.example.swagger.dto.UserDto;
|
import org.sadtech.example.swagger.dto.UserDto;
|
||||||
import org.springframework.http.HttpHeaders;
|
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
import org.springframework.web.bind.annotation.PathVariable;
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestHeader;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import javax.validation.constraints.Min;
|
||||||
|
import javax.validation.constraints.NotBlank;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -37,12 +33,11 @@ public class PointController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("{key}")
|
@PostMapping("{key}")
|
||||||
@ApiResponse(responseCode = "400", description = "Неверный запрос — количество баллов должно быть неотрицательным")
|
|
||||||
@Operation(summary = "Управление баллами", description = "Позволяет удалить или добавить баллы пользователю")
|
@Operation(summary = "Управление баллами", description = "Позволяет удалить или добавить баллы пользователю")
|
||||||
public HttpStatus changePoints(
|
public HttpStatus changePoints(
|
||||||
@PathVariable @NotBlank @Parameter(description = "Идентификатор пользователя") String key,
|
@PathVariable @NotBlank @Parameter(description = "Идентификатор пользователя") String key,
|
||||||
@RequestParam("point") @Min(0) @Parameter(description = "Количество баллов", required = true, example = "100") Long point,
|
@RequestParam("point") @Min(0) @Parameter(description = "Количество баллов", required = true) Long point,
|
||||||
@RequestParam("type") @Parameter(description = "Тип операции", required = true, example = "PLUS") TypeOperation type
|
@RequestParam("type") @Parameter(description = "Тип операции", required = true) TypeOperation type
|
||||||
) {
|
) {
|
||||||
final UserDto userDto = repository.get(key);
|
final UserDto userDto = repository.get(key);
|
||||||
userDto.setPoints(
|
userDto.setPoints(
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
package org.sadtech.example.swagger.controller;
|
package org.sadtech.example.swagger.controller;
|
||||||
|
|
||||||
import io.swagger.v3.oas.annotations.ExternalDocumentation;
|
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
|
|
||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
import org.sadtech.example.swagger.dto.UserDto;
|
import org.sadtech.example.swagger.dto.UserDto;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
@ -24,14 +22,7 @@ import static org.springframework.util.MimeTypeUtils.APPLICATION_JSON_VALUE;
|
|||||||
*/
|
*/
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/api/user")
|
@RequestMapping("/api/user")
|
||||||
@Tag(
|
@Tag(name = "Пользователи", description = "Взаимодействие с пользователями")
|
||||||
name = "User Controller",
|
|
||||||
description = "Контроллер для управления пользователями",
|
|
||||||
externalDocs = @ExternalDocumentation(
|
|
||||||
description = "Ссылка на общую документацию",
|
|
||||||
url = "https://example.com/docs/user-controller"
|
|
||||||
)
|
|
||||||
)
|
|
||||||
public class UserController {
|
public class UserController {
|
||||||
|
|
||||||
private final Map<String, UserDto> repository;
|
private final Map<String, UserDto> repository;
|
||||||
@ -57,13 +48,9 @@ public class UserController {
|
|||||||
return HttpStatus.OK;
|
return HttpStatus.OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
// http://localhost:8080/api/user/1
|
|
||||||
@SecurityRequirement(name = "jsessionid")
|
|
||||||
@GetMapping(value = "{key}", produces = APPLICATION_JSON_VALUE)
|
@GetMapping(value = "{key}", produces = APPLICATION_JSON_VALUE)
|
||||||
@Operation(summary = "Получить пользователя")
|
@Operation(summary = "Получить пользователя")
|
||||||
public ResponseEntity<UserDto> getSimpleDto(
|
public ResponseEntity<UserDto> getSimpleDto(@PathVariable("key") String key) {
|
||||||
@PathVariable("key") String key
|
|
||||||
) {
|
|
||||||
return ResponseEntity.ok(repository.get(key));
|
return ResponseEntity.ok(repository.get(key));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@ package org.sadtech.example.swagger.dto;
|
|||||||
|
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotBlank;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
1
src/main/resources/application.properties
Normal file
1
src/main/resources/application.properties
Normal file
@ -0,0 +1 @@
|
|||||||
|
|
@ -1,25 +0,0 @@
|
|||||||
#springdoc:
|
|
||||||
# swagger-ui:
|
|
||||||
# oauth:
|
|
||||||
# client-id: mocklab_oidc
|
|
||||||
# client-secret: whatever
|
|
||||||
spring:
|
|
||||||
security:
|
|
||||||
oauth2:
|
|
||||||
client:
|
|
||||||
registration:
|
|
||||||
mocklab:
|
|
||||||
provider: mocklab
|
|
||||||
client-authentication-method: client_secret_basic
|
|
||||||
authorization-grant-type: authorization_code
|
|
||||||
scope: profile, email
|
|
||||||
redirect-uri: http://localhost:8080/login/oauth2/code/
|
|
||||||
clientId: mocklab_oidc
|
|
||||||
clientSecret: whatever
|
|
||||||
provider:
|
|
||||||
mocklab:
|
|
||||||
authorization-uri: https://oauth.wiremockapi.cloud/oauth/authorize
|
|
||||||
token-uri: https://oauth.wiremockapi.cloud/oauth/token
|
|
||||||
user-info-uri: https://oauth.wiremockapi.cloud/userinfo
|
|
||||||
user-name-attribute: sub
|
|
||||||
jwk-set-uri: https://oauth.wiremockapi.cloud/.well-known/jwks.json
|
|
Loading…
Reference in New Issue
Block a user