Skip to content

Commit

Permalink
spotlessApply
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Farr <[email protected]>
  • Loading branch information
Xtansia committed Aug 22, 2024
1 parent cfd83af commit 7ef9449
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,10 @@ private static String responseClassName(@Nonnull OperationGroup operationGroup)
private static String classBaseName(@Nonnull OperationGroup operationGroup) {
Objects.requireNonNull(operationGroup, "operationGroup must not be null");
switch (operationGroup.toString()) {
case "tasks.get": return "GetTasks";
default: return Strings.toPascalCase(operationGroup.getName());
case "tasks.get":
return "GetTasks";
default:
return Strings.toPascalCase(operationGroup.getName());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -284,15 +284,9 @@ private void visitInto(OpenApiSchema schema, ObjectShape shape) {
final var additionalProperties = new ArrayList<OpenApiSchema>();
final var required = collectObjectProperties(schema, properties, additionalProperties);

properties.forEach((k, v) -> {
shape.addBodyField(new Field(
k,
mapType(v),
required.contains(k),
v.getDescription().orElse(null),
null
));
});
properties.forEach(
(k, v) -> { shape.addBodyField(new Field(k, mapType(v), required.contains(k), v.getDescription().orElse(null), null)); }
);

if (!additionalProperties.isEmpty()) {
var valueSchema = additionalProperties.size() == 1 ? additionalProperties.get(0) : OpenApiSchema.ANONYMOUS_UNTYPED;
Expand All @@ -310,9 +304,9 @@ private void visitInto(OpenApiSchema schema, ObjectShape shape) {
}

private Set<String> collectObjectProperties(
OpenApiSchema schema,
Map<String, OpenApiSchema> properties,
List<OpenApiSchema> additionalProperties
OpenApiSchema schema,
Map<String, OpenApiSchema> properties,
List<OpenApiSchema> additionalProperties
) {
if (schema.has$ref()) {
return collectObjectProperties(schema.resolve(), properties, additionalProperties);
Expand All @@ -339,18 +333,18 @@ private Set<String> collectObjectProperties(
return required;
}

schema.getProperties()
.ifPresent(props -> props.forEach((k, v) -> {
var existing = properties.get(k);
if (existing != null) {
var existingType = existing.determineSingleType().orElse(null);
var newType = v.determineSingleType().orElse(null);
if (existingType != null && (existingType == OpenApiSchemaType.Object || existingType == OpenApiSchemaType.Array || existingType != newType)) {
v = OpenApiSchema.ANONYMOUS_UNTYPED;
}
}
properties.put(k, v);
}));
schema.getProperties().ifPresent(props -> props.forEach((k, v) -> {
var existing = properties.get(k);
if (existing != null) {
var existingType = existing.determineSingleType().orElse(null);
var newType = v.determineSingleType().orElse(null);
if (existingType != null
&& (existingType == OpenApiSchemaType.Object || existingType == OpenApiSchemaType.Array || existingType != newType)) {
v = OpenApiSchema.ANONYMOUS_UNTYPED;
}
}
properties.put(k, v);
}));

schema.getAdditionalProperties().ifPresent(additionalProperties::add);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@
public class OpenApiSchema extends OpenApiRefElement<OpenApiSchema> {
private static final JsonPointer ANONYMOUS = JsonPointer.of("<anonymous>");

public static final OpenApiSchema ANONYMOUS_UNTYPED = builder().withPointer(ANONYMOUS.append("untyped"))
.build();
public static final OpenApiSchema ANONYMOUS_UNTYPED = builder().withPointer(ANONYMOUS.append("untyped")).build();
public static final OpenApiSchema ANONYMOUS_OBJECT = builder().withPointer(ANONYMOUS.append("object"))
.withTypes(OpenApiSchemaType.Object)
.build();
Expand Down Expand Up @@ -134,7 +133,7 @@ protected OpenApiSchema(@Nullable OpenApiElement<?> parent, @Nonnull JsonPointer

var extensions = schema.getExtensions();

//noinspection unchecked
// noinspection unchecked
deprecatedEnums = Maps.tryGet(extensions, "x-deprecated-enums").map(e -> (Collection<String>) e).map(HashSet::new).orElse(null);
}

Expand Down Expand Up @@ -225,7 +224,9 @@ public Optional<List<String>> getEnums() {
}

@Nonnull
public Optional<Set<String>> getDeprecatedEnums() { return Sets.unmodifiableOpt(deprecatedEnums); }
public Optional<Set<String>> getDeprecatedEnums() {
return Sets.unmodifiableOpt(deprecatedEnums);
}

@Nonnull
public Optional<OpenApiSchema> getItems() {
Expand Down

0 comments on commit 7ef9449

Please sign in to comment.