-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bump PMD with fixes #25
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,6 @@ | |
import io.swagger.v3.oas.models.OpenAPI; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.Optional; | ||
import nva.commons.core.JacocoGenerated; | ||
import nva.commons.core.attempt.Failure; | ||
|
@@ -24,10 +23,10 @@ public class ApiData { | |
|
||
private final RestApi awsRestApi; | ||
private final OpenAPI openapiApiGateway; | ||
private Optional<OpenAPI> openapiApiGithub; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Optional fields are a no-no, I replaced this with a private getter…it serves little real purpose aside hiding null checks. I suspect we simply have a suboptimal design here (typically, we see this kind of thing when the OO is off), which should probably be rectified. |
||
private final String rawYaml; | ||
private final Stage stage; | ||
private static final Logger logger = LoggerFactory.getLogger(ApiData.class); | ||
private OpenAPI openapiApiGithub; | ||
|
||
public ApiData(RestApi awsRestApi, OpenAPI openapiApiGateway, String rawYaml, Stage stage) { | ||
this.awsRestApi = awsRestApi; | ||
|
@@ -64,6 +63,10 @@ public int getDashesInPath() { | |
return Try.attempt(this::getNumberOfDashesInBasePath).orElse(this::handleGetDashesFailure); | ||
} | ||
|
||
private Optional<OpenAPI> getOpenapiApiGithub() { | ||
return Optional.ofNullable(openapiApiGithub); | ||
} | ||
|
||
public void setMatchingGithubOpenapi(List<Pair<S3Object, OpenAPI>> templateOpenapiDocs) { | ||
var title = this.openapiApiGateway.getInfo().getTitle(); | ||
var matchingGithubOpenApi = templateOpenapiDocs.stream() | ||
|
@@ -73,16 +76,15 @@ public void setMatchingGithubOpenapi(List<Pair<S3Object, OpenAPI>> templateOpena | |
.equals(title)) | ||
.findFirst(); | ||
if (matchingGithubOpenApi.isPresent()) { | ||
logger.info("Using matching github openapi at " + matchingGithubOpenApi.get().getLeft().key()+ " for " + title); | ||
this.openapiApiGithub = Optional.of(matchingGithubOpenApi.get().getRight()); | ||
logger.info("Using matching github openapi at " | ||
+ matchingGithubOpenApi.get().getLeft().key()+ " for " + title); | ||
this.openapiApiGithub = matchingGithubOpenApi.get().getRight(); | ||
} else { | ||
logger.warn("No matching github openapi found for " + title); | ||
this.openapiApiGithub = Optional.empty(); | ||
} | ||
; | ||
} | ||
|
||
public ApiData setEmptySchemasIfNull() { | ||
public ApiData applyEmptySchemasIfNull() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Setters traditionally return void. I agree strongly with this pattern. |
||
if (isNull(this.openapiApiGateway.getComponents())) { | ||
this.openapiApiGateway.setComponents(new Components()); | ||
} | ||
|
@@ -93,27 +95,29 @@ public ApiData setEmptySchemasIfNull() { | |
} | ||
|
||
public ApiData overridePropsFromGithub() { | ||
if (this.openapiApiGithub.isPresent()) { | ||
var openApiGithub = getOpenapiApiGithub(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is here, it really adds nothing. Probably, there is a missing object. |
||
if (openApiGithub.isPresent()) { | ||
this.openapiApiGateway.getPaths().forEach((pathKey, pathItem) -> { | ||
pathItem.readOperationsMap().forEach((httpMethod, operation) -> { | ||
if (nonNull(operation.getParameters())) { | ||
operation.getParameters().forEach(parameter -> { | ||
var operationInGithub = Optional.ofNullable(openapiApiGithub.get().getPaths().get(pathKey).readOperationsMap() | ||
var operationInGithub = | ||
Optional.ofNullable(openApiGithub.get().getPaths().get(pathKey).readOperationsMap() | ||
.get(httpMethod)); | ||
operationInGithub.ifPresent(value -> operation.setParameters(value.getParameters())); | ||
}); | ||
} | ||
}); | ||
}); | ||
if (nonNull(this.openapiApiGithub.get().getComponents()) | ||
&& nonNull(this.openapiApiGithub.get().getComponents().getSchemas()) | ||
if (nonNull(openApiGithub.get().getComponents()) | ||
&& nonNull(openApiGithub.get().getComponents().getSchemas()) | ||
) { | ||
this.openapiApiGithub.get().getComponents().getSchemas().forEach(((key,value) -> { | ||
openApiGithub.get().getComponents().getSchemas().forEach((key,value) -> { | ||
if (isNull(this.openapiApiGateway.getComponents().getSchemas().get(key))) { | ||
logger.info("Adding schema " + key + " from github"); | ||
this.openapiApiGateway.getComponents().getSchemas().put(key, value); | ||
} | ||
})); | ||
}); | ||
} | ||
|
||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,6 @@ | |
import io.swagger.v3.oas.models.PathItem; | ||
import io.swagger.v3.oas.models.media.Schema; | ||
import io.swagger.v3.oas.models.parameters.Parameter; | ||
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 java.util.Collection; | ||
|
@@ -118,8 +117,8 @@ private void removeTags(OpenAPI api) { | |
|
||
private void mergeSecurity(OpenAPI api) { | ||
if (nonNull(api.getSecurity())) { | ||
for (SecurityRequirement securityRequirement : api.getSecurity()) { | ||
logger.info("adding security req {}", securityRequirement.toString()); | ||
for (var securityRequirement : api.getSecurity()) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was a cheap trick to avoid the prescription to use the interface, which here would have been quite harmful. It is not just us that makes things difficult on ourselves. |
||
logger.info("adding security req {}", securityRequirement); | ||
this.baseTemplate.addSecurityItem(securityRequirement); | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We share Pub-API's PMD spec, but this isn't relevant for us…weird. Probably need to decide what to do about "Standard" and local colour in another meeting.