1
|
|
|
package dev.hltech.dredd.interfaces.rest.validation; |
2
|
|
|
|
3
|
|
|
import dev.hltech.dredd.domain.JudgeD; |
4
|
|
|
import dev.hltech.dredd.domain.contracts.ServiceContracts; |
5
|
|
|
import dev.hltech.dredd.domain.contracts.ServiceContractsRepository; |
6
|
|
|
import dev.hltech.dredd.domain.validation.EnvironmentValidatorResult; |
7
|
|
|
import dev.hltech.dredd.domain.validation.InterfaceContractValidator; |
8
|
|
|
import dev.hltech.dredd.interfaces.rest.ResourceNotFoundException; |
9
|
|
|
import io.swagger.annotations.ApiOperation; |
10
|
|
|
import io.swagger.annotations.ApiResponse; |
11
|
|
|
import io.swagger.annotations.ApiResponses; |
12
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
13
|
|
|
import org.springframework.http.MediaType; |
14
|
|
|
import org.springframework.web.bind.annotation.GetMapping; |
15
|
|
|
import org.springframework.web.bind.annotation.PathVariable; |
16
|
|
|
import org.springframework.web.bind.annotation.RequestParam; |
17
|
|
|
import org.springframework.web.bind.annotation.RestController; |
18
|
|
|
|
19
|
|
|
import java.util.List; |
20
|
|
|
import java.util.stream.Collectors; |
21
|
|
|
|
22
|
|
|
import static dev.hltech.dredd.interfaces.rest.validation.Converters.toDtos; |
23
|
|
|
|
24
|
|
|
@RestController |
25
|
|
|
public class ValidationController { |
26
|
|
|
|
27
|
|
|
private final JudgeD judgeD; |
28
|
|
|
private final ServiceContractsRepository serviceContractsRepository; |
29
|
|
|
private final List<InterfaceContractValidator<?, ?>> validators; |
30
|
|
|
|
31
|
|
|
@Autowired |
32
|
|
|
public ValidationController( |
33
|
|
|
JudgeD judgeD, |
34
|
|
|
ServiceContractsRepository serviceContractsRepository, |
35
|
|
|
List<InterfaceContractValidator<?, ?>> validators |
36
|
|
|
) { |
37
|
|
|
this.judgeD = judgeD; |
38
|
|
|
this.serviceContractsRepository = serviceContractsRepository; |
39
|
|
|
this.validators = validators; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
View Code Duplication |
@GetMapping(value = "/environment-compatibility-report/{environment}/{serviceName}:{serviceVersion:.+}", produces = MediaType.APPLICATION_JSON_VALUE) |
|
|
|
|
43
|
|
|
@ApiOperation(value = "Get validation report for contract between given service and given environment", nickname = "Validate against environment") |
44
|
|
|
@ApiResponses(value = { |
45
|
|
|
@ApiResponse(code = 200, message = "Success", response = String.class, responseContainer = "list"), |
46
|
|
|
@ApiResponse(code = 500, message = "Failure"), |
47
|
|
|
@ApiResponse(code = 404, message = "Service not found") |
48
|
|
|
}) |
49
|
|
|
public List<ContractValidationReportDto> validateAgainstEnvironment( |
50
|
|
|
@PathVariable("environment") String environment, |
51
|
|
|
@PathVariable("serviceName") String serviceName, |
52
|
|
|
@PathVariable("serviceVersion") String serviceVersion |
53
|
|
|
) { |
54
|
|
|
ServiceContracts validatedServiceContracts = this.serviceContractsRepository.find(serviceName, serviceVersion) |
55
|
|
|
.orElseThrow(ResourceNotFoundException::new); |
56
|
|
|
|
57
|
|
|
List<EnvironmentValidatorResult> collect = this.validators.stream() |
58
|
|
|
.map(validator -> |
59
|
|
|
this.judgeD.validateServiceAgainstEnv( |
60
|
|
|
validatedServiceContracts, |
61
|
|
|
environment, |
62
|
|
|
validator |
63
|
|
|
)) |
64
|
|
|
.collect(Collectors.toList()); |
65
|
|
|
return toDtos(collect, serviceName, serviceVersion); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
View Code Duplication |
@GetMapping(value = "/environment-compatibility-report/{serviceName}:{serviceVersion:.+}", produces = MediaType.APPLICATION_JSON_VALUE) |
|
|
|
|
69
|
|
|
@ApiOperation(value = "Get validation report for contract between given service and given environment", nickname = "Validate against environment") |
70
|
|
|
@ApiResponses(value = { |
71
|
|
|
@ApiResponse(code = 200, message = "Success", response = String.class, responseContainer = "list"), |
72
|
|
|
@ApiResponse(code = 500, message = "Failure"), |
73
|
|
|
@ApiResponse(code = 404, message = "Service not found") |
74
|
|
|
}) |
75
|
|
|
public List<ContractValidationReportDto> validateAgainstEnvironments( |
76
|
|
|
@PathVariable("serviceName") String serviceName, |
77
|
|
|
@PathVariable("serviceVersion") String serviceVersion, |
78
|
|
|
@RequestParam("environment") List<String> environments |
79
|
|
|
) { |
80
|
|
|
ServiceContracts validatedServiceContracts = this.serviceContractsRepository.find(serviceName, serviceVersion) |
81
|
|
|
.orElseThrow(ResourceNotFoundException::new); |
82
|
|
|
|
83
|
|
|
List<EnvironmentValidatorResult> collect = this.validators.stream() |
84
|
|
|
.map(validator -> |
85
|
|
|
this.judgeD.validateServiceAgainstEnv( |
86
|
|
|
validatedServiceContracts, |
87
|
|
|
environments, |
88
|
|
|
validator |
89
|
|
|
)) |
90
|
|
|
.collect(Collectors.toList()); |
91
|
|
|
return toDtos(collect, serviceName, serviceVersion); |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|