Skip to content

Commit

Permalink
Fix review suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
lnash94 committed Sep 26, 2024
1 parent b497212 commit b8eb6a4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ SYNOPSIS

DESCRIPTION
Sanitize the OpenAPI contract file according to the best naming
practices of Ballerina. The OpenAPI contract is flatten and the type
schema names are made Ballerina friendly. The Ballerina name
extensions are added to the schemas which can not be modified
practices of Ballerina. The Ballerina name extensions are added to the schemas which can not be modified
directly.


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,27 +136,27 @@ private void processOperationWithInlineObjectSchema(Operation operation) {
}

private void processParametersWithInlineObjectSchema(List<Parameter> parameters) {
if (parameters == null) {
if (Objects.isNull(parameters)) {
return;
}

for (Parameter parameter : parameters) {
if (parameter.getSchema() != null) {
if (Objects.nonNull(parameter.getSchema())) {
updateInlineObjectSchema(parameter.getSchema());
}
}
}

private void processResponsesWithInlineObjectSchema(Map<String, ApiResponse> responses) {
responses.forEach((status, response) -> {
if (response.getContent() != null) {
if (Objects.nonNull(response.getContent())) {
updateInlineObjectInContent(response.getContent());
}
});
}

private void updateInlineObjectSchema(Schema<?> schema) {
if (schema == null) {
if (Objects.isNull(schema)) {
return;
}
handleInlineObjectSchemaInComposedSchema(schema);
Expand All @@ -175,27 +175,28 @@ private void handleInlineObjectSchemaInComposedSchema(Schema<?> schema) {
}

private void processSubSchemas(List<Schema> subSchemas) {
if (subSchemas != null) {
if (Objects.nonNull(subSchemas)) {
subSchemas.forEach(this::updateInlineObjectSchema);
}
}

private static void handleInlineObjectSchema(Schema<?> schema) {
if (isInlineObjectSchema(schema)) {
Map<String, Schema> properties = schema.getProperties();
if (properties != null && !properties.isEmpty()) {
if (Objects.nonNull(properties) && !properties.isEmpty()) {
schema.setProperties(getPropertiesWithBallerinaNameExtension(properties));
}
}
}

private static boolean isInlineObjectSchema(Schema<?> schema) {
return schema instanceof ObjectSchema ||
(schema.getType() == null && schema.get$ref() == null && schema.getProperties() != null);
(Objects.isNull(schema.getType()) && Objects.isNull(schema.get$ref()) &&
Objects.nonNull(schema.getProperties()));
}

private void handleInlineObjectSchemaItems(Schema<?> schema) {
if (schema.getItems() != null) {
if (Objects.nonNull(schema.getItems())) {
updateInlineObjectSchema(schema.getItems());
}
}
Expand All @@ -207,7 +208,7 @@ private void handleInlineObjectSchemaInAdditionalProperties(Schema<?> schema) {
}

private void handleInlineObjectSchemaProperties(Schema<?> schema) {
if (schema.getProperties() != null) {
if (Objects.nonNull(schema.getProperties())) {
schema.getProperties().values().forEach(this::updateInlineObjectSchema);
}
}
Expand Down

0 comments on commit b8eb6a4

Please sign in to comment.