Skip to content

Commit

Permalink
Make generated OpenAPI type names more readable (#5732)
Browse files Browse the repository at this point in the history
Rename JSON view classes and make them inner classes with short and
readable names.

If the view class is an inner classes, the OpenAPI generator
apparently uses its simple name as a suffix for related type names
in the YAML.

Also move view classes under the `model` package since they are
referenced from model classes.

Following up on #5424
  • Loading branch information
dimas-b authored Dec 20, 2022
1 parent 3bc36c7 commit 9ac02b5
Show file tree
Hide file tree
Showing 14 changed files with 93 additions and 115 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,14 @@
import javax.net.ssl.SNIHostName;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLParameters;
import org.projectnessie.api.v1.ApiAttributesV1;
import org.projectnessie.api.v2.ApiAttributesV2;
import org.projectnessie.client.NessieClientBuilder;
import org.projectnessie.client.NessieConfigConstants;
import org.projectnessie.client.api.NessieApi;
import org.projectnessie.client.auth.NessieAuthentication;
import org.projectnessie.client.auth.NessieAuthenticationProvider;
import org.projectnessie.client.http.v1api.HttpApiV1;
import org.projectnessie.client.http.v2api.HttpApiV2;
import org.projectnessie.model.ser.Views;

/**
* A builder class that creates a {@link NessieHttpClient} via {@link HttpClientBuilder#builder()}.
Expand Down Expand Up @@ -287,13 +286,13 @@ public <API extends NessieApi> API build(Class<API> apiVersion) {
Objects.requireNonNull(apiVersion, "API version class must be non-null");

if (apiVersion.isAssignableFrom(HttpApiV1.class)) {
builder.setJsonView(ApiAttributesV1.class);
builder.setJsonView(Views.V1.class);
NessieHttpClient client = new NessieHttpClient(authentication, tracing, builder);
return (API) new HttpApiV1(client);
}

if (apiVersion.isAssignableFrom(HttpApiV2.class)) {
builder.setJsonView(ApiAttributesV2.class);
builder.setJsonView(Views.V2.class);
HttpClient httpClient = NessieHttpClient.buildClient(authentication, tracing, builder);
return (API) new HttpApiV2(httpClient);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.projectnessie.api.v1.ApiAttributesV1;
import org.projectnessie.client.api.NessieApi;
import org.projectnessie.error.ErrorCode;
import org.projectnessie.error.ImmutableNessieError;
import org.projectnessie.error.NessieError;
import org.projectnessie.model.ser.Views;

/**
* Translates between the current and old Nessie version API and model.
Expand Down Expand Up @@ -266,7 +266,7 @@ String serializeWith(ClassLoader classLoader, Object o) {
try {
// Must use the view class from the client, whose version may be different from the test's
// version.
Class<?> jsonViewV1 = classLoader.loadClass(ApiAttributesV1.class.getName());
Class<?> jsonViewV1 = classLoader.loadClass(Views.V1.class.getName());
objectMapper =
objectMapper
.getClass()
Expand Down
24 changes: 12 additions & 12 deletions model/src/main/java/org/projectnessie/api/v1/http/HttpTreeApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import org.eclipse.microprofile.openapi.annotations.responses.APIResponse;
import org.eclipse.microprofile.openapi.annotations.responses.APIResponses;
import org.eclipse.microprofile.openapi.annotations.tags.Tag;
import org.projectnessie.api.v1.ApiAttributesV1;
import org.projectnessie.api.v1.TreeApi;
import org.projectnessie.api.v1.params.CommitLogParams;
import org.projectnessie.api.v1.params.EntriesParams;
Expand All @@ -53,6 +52,7 @@
import org.projectnessie.model.Operations;
import org.projectnessie.model.Reference;
import org.projectnessie.model.ReferencesResponse;
import org.projectnessie.model.ser.Views;

@Tag(name = "v1")
@Consumes(value = MediaType.APPLICATION_JSON)
Expand All @@ -77,7 +77,7 @@ public interface HttpTreeApi extends TreeApi {
schema = @Schema(implementation = ReferencesResponse.class))),
@APIResponse(responseCode = "401", description = "Invalid credentials provided"),
})
@JsonView(ApiAttributesV1.class)
@JsonView(Views.V1.class)
ReferencesResponse getAllReferences(@BeanParam ReferencesParams params);

@Override
Expand All @@ -97,7 +97,7 @@ public interface HttpTreeApi extends TreeApi {
@APIResponse(responseCode = "401", description = "Invalid credentials provided"),
@APIResponse(responseCode = "404", description = "Default branch not found.")
})
@JsonView(ApiAttributesV1.class)
@JsonView(Views.V1.class)
Branch getDefaultBranch() throws NessieNotFoundException;

@Override
Expand Down Expand Up @@ -131,7 +131,7 @@ public interface HttpTreeApi extends TreeApi {
@APIResponse(responseCode = "403", description = "Not allowed to create reference"),
@APIResponse(responseCode = "409", description = "Reference already exists"),
})
@JsonView(ApiAttributesV1.class)
@JsonView(Views.V1.class)
Reference createReference(
@Parameter(description = "Source named reference") @QueryParam("sourceRefName")
String sourceRefName,
Expand Down Expand Up @@ -165,7 +165,7 @@ Reference createReference(
@APIResponse(responseCode = "403", description = "Not allowed to view the given reference"),
@APIResponse(responseCode = "404", description = "Ref not found")
})
@JsonView(ApiAttributesV1.class)
@JsonView(Views.V1.class)
Reference getReferenceByName(@BeanParam GetReferenceParams params) throws NessieNotFoundException;

@Override
Expand Down Expand Up @@ -215,7 +215,7 @@ Reference createReference(
description = "Not allowed to view the given reference or fetch entries for it"),
@APIResponse(responseCode = "404", description = "Ref not found")
})
@JsonView(ApiAttributesV1.class)
@JsonView(Views.V1.class)
EntriesResponse getEntries(
@Parameter(
description = "name of ref to fetch from",
Expand Down Expand Up @@ -271,7 +271,7 @@ EntriesResponse getEntries(
description = "Not allowed to view the given reference or get commit log for it"),
@APIResponse(responseCode = "404", description = "Ref doesn't exists")
})
@JsonView(ApiAttributesV1.class)
@JsonView(Views.V1.class)
LogResponse getCommitLog(
@Parameter(
description = "ref to show log from",
Expand All @@ -297,7 +297,7 @@ LogResponse getCommitLog(
@APIResponse(responseCode = "404", description = "One or more references don't exist"),
@APIResponse(responseCode = "409", description = "Update conflict")
})
@JsonView(ApiAttributesV1.class)
@JsonView(Views.V1.class)
void assignReference(
@Parameter(
description = "Reference type to reassign",
Expand Down Expand Up @@ -338,7 +338,7 @@ void assignReference(
@APIResponse(responseCode = "404", description = "Ref doesn't exists"),
@APIResponse(responseCode = "409", description = "update conflict"),
})
@JsonView(ApiAttributesV1.class)
@JsonView(Views.V1.class)
void deleteReference(
@Parameter(
description = "Reference type to delete",
Expand Down Expand Up @@ -392,7 +392,7 @@ void deleteReference(
@APIResponse(responseCode = "404", description = "Ref doesn't exists"),
@APIResponse(responseCode = "409", description = "update conflict")
})
@JsonView(ApiAttributesV1.class)
@JsonView(Views.V1.class)
MergeResponse transplantCommitsIntoBranch(
@Parameter(
description = "Branch to transplant into",
Expand Down Expand Up @@ -454,7 +454,7 @@ MergeResponse transplantCommitsIntoBranch(
@APIResponse(responseCode = "404", description = "Ref doesn't exists"),
@APIResponse(responseCode = "409", description = "update conflict")
})
@JsonView(ApiAttributesV1.class)
@JsonView(Views.V1.class)
MergeResponse mergeRefIntoBranch(
@Parameter(
description = "Branch to merge into",
Expand Down Expand Up @@ -506,7 +506,7 @@ MergeResponse mergeRefIntoBranch(
@APIResponse(responseCode = "404", description = "Provided ref doesn't exists"),
@APIResponse(responseCode = "409", description = "Update conflict")
})
@JsonView(ApiAttributesV1.class)
@JsonView(Views.V1.class)
Branch commitMultipleOperations(
@Parameter(
description = "Branch to change, defaults to default branch.",
Expand Down
19 changes: 0 additions & 19 deletions model/src/main/java/org/projectnessie/api/v2/ApiAttributesV2.java

This file was deleted.

30 changes: 15 additions & 15 deletions model/src/main/java/org/projectnessie/api/v2/http/HttpTreeApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
import org.eclipse.microprofile.openapi.annotations.responses.APIResponse;
import org.eclipse.microprofile.openapi.annotations.responses.APIResponses;
import org.eclipse.microprofile.openapi.annotations.tags.Tag;
import org.projectnessie.api.v2.ApiAttributesV2;
import org.projectnessie.api.v2.TreeApi;
import org.projectnessie.api.v2.params.CommitLogParams;
import org.projectnessie.api.v2.params.DiffParams;
Expand All @@ -71,6 +70,7 @@
import org.projectnessie.model.Reference;
import org.projectnessie.model.ReferencesResponse;
import org.projectnessie.model.SingleReferenceResponse;
import org.projectnessie.model.ser.Views;

@Consumes(value = MediaType.APPLICATION_JSON)
@Path("v2/trees")
Expand All @@ -97,7 +97,7 @@ public interface HttpTreeApi extends TreeApi {
schema = @Schema(implementation = ReferencesResponse.class))),
@APIResponse(responseCode = "401", description = "Invalid credentials provided"),
})
@JsonView(ApiAttributesV2.class)
@JsonView(Views.V2.class)
ReferencesResponse getAllReferences(@BeanParam ReferencesParams params);

@Override
Expand Down Expand Up @@ -131,7 +131,7 @@ public interface HttpTreeApi extends TreeApi {
responseCode = "409",
description = "Another reference with the same name already exists"),
})
@JsonView(ApiAttributesV2.class)
@JsonView(Views.V2.class)
SingleReferenceResponse createReference(
@Parameter(required = true, description = REF_NAME_DESCRIPTION) @QueryParam("name")
String name,
Expand Down Expand Up @@ -172,7 +172,7 @@ SingleReferenceResponse createReference(
@APIResponse(responseCode = "403", description = "Not allowed to view the given reference"),
@APIResponse(responseCode = "404", description = "Ref not found")
})
@JsonView(ApiAttributesV2.class)
@JsonView(Views.V2.class)
SingleReferenceResponse getReferenceByName(@BeanParam GetReferenceParams params)
throws NessieNotFoundException;

Expand Down Expand Up @@ -213,7 +213,7 @@ SingleReferenceResponse getReferenceByName(@BeanParam GetReferenceParams params)
description = "Not allowed to view the given reference or fetch entries for it"),
@APIResponse(responseCode = "404", description = "Ref not found")
})
@JsonView(ApiAttributesV2.class)
@JsonView(Views.V2.class)
EntriesResponse getEntries(
@Parameter(
schema = @Schema(pattern = REF_NAME_PATH_ELEMENT_REGEX),
Expand Down Expand Up @@ -270,7 +270,7 @@ EntriesResponse getEntries(
description = "Not allowed to view the given reference or get commit log for it"),
@APIResponse(responseCode = "404", description = "Ref doesn't exists")
})
@JsonView(ApiAttributesV2.class)
@JsonView(Views.V2.class)
LogResponse getCommitLog(
@Parameter(
schema = @Schema(pattern = REF_NAME_PATH_ELEMENT_REGEX),
Expand Down Expand Up @@ -325,7 +325,7 @@ LogResponse getCommitLog(
@APIResponse(responseCode = "403", description = "Not allowed to view the given fromRef/toRef"),
@APIResponse(responseCode = "404", description = "fromRef/toRef not found"),
})
@JsonView(ApiAttributesV2.class)
@JsonView(Views.V2.class)
DiffResponse getDiff(@BeanParam DiffParams params) throws NessieNotFoundException;

@Override
Expand Down Expand Up @@ -353,7 +353,7 @@ LogResponse getCommitLog(
responseCode = "409",
description = "Update conflict or expected hash / type mismatch")
})
@JsonView(ApiAttributesV2.class)
@JsonView(Views.V2.class)
SingleReferenceResponse assignReference(
@Parameter(
description = "Optional expected type of the reference being reassigned",
Expand Down Expand Up @@ -398,7 +398,7 @@ SingleReferenceResponse assignReference(
@APIResponse(responseCode = "404", description = "Ref doesn't exists"),
@APIResponse(responseCode = "409", description = "update conflict"),
})
@JsonView(ApiAttributesV2.class)
@JsonView(Views.V2.class)
SingleReferenceResponse deleteReference(
@Parameter(
description = "Optional expected type of the reference being deleted",
Expand Down Expand Up @@ -441,7 +441,7 @@ SingleReferenceResponse deleteReference(
responseCode = "404",
description = "Table not found on 'ref' or non-existent reference")
})
@JsonView(ApiAttributesV2.class)
@JsonView(Views.V2.class)
ContentResponse getContent(
@Parameter(description = KEY_PARAMETER_DESCRIPTION) @PathParam("key") ContentKey key,
@Parameter(
Expand Down Expand Up @@ -485,7 +485,7 @@ ContentResponse getContent(
description = "Not allowed to view the given reference or read object content for a key"),
@APIResponse(responseCode = "404", description = "Provided ref doesn't exists")
})
@JsonView(ApiAttributesV2.class)
@JsonView(Views.V2.class)
GetMultipleContentsResponse getSeveralContents(
@Parameter(
description = "Reference to use.",
Expand Down Expand Up @@ -526,7 +526,7 @@ GetMultipleContentsResponse getSeveralContents(
description = "Not allowed to view the given reference or read object content for a key"),
@APIResponse(responseCode = "404", description = "Provided ref doesn't exists")
})
@JsonView(ApiAttributesV2.class)
@JsonView(Views.V2.class)
GetMultipleContentsResponse getMultipleContents(
@Parameter(
schema = @Schema(pattern = REF_NAME_PATH_ELEMENT_REGEX),
Expand Down Expand Up @@ -584,7 +584,7 @@ GetMultipleContentsResponse getMultipleContents(
@APIResponse(responseCode = "404", description = "Ref doesn't exists"),
@APIResponse(responseCode = "409", description = "update conflict")
})
@JsonView(ApiAttributesV2.class)
@JsonView(Views.V2.class)
MergeResponse transplantCommitsIntoBranch(
@Parameter(
schema = @Schema(pattern = REF_NAME_PATH_ELEMENT_REGEX),
Expand Down Expand Up @@ -643,7 +643,7 @@ MergeResponse transplantCommitsIntoBranch(
@APIResponse(responseCode = "404", description = "Ref doesn't exists"),
@APIResponse(responseCode = "409", description = "update conflict")
})
@JsonView(ApiAttributesV2.class)
@JsonView(Views.V2.class)
MergeResponse mergeRefIntoBranch(
@Parameter(
schema = @Schema(pattern = REF_NAME_PATH_ELEMENT_REGEX),
Expand Down Expand Up @@ -695,7 +695,7 @@ MergeResponse mergeRefIntoBranch(
@APIResponse(responseCode = "404", description = "Provided ref doesn't exists"),
@APIResponse(responseCode = "409", description = "Update conflict")
})
@JsonView(ApiAttributesV2.class)
@JsonView(Views.V2.class)
CommitResponse commitMultipleOperations(
@Parameter(
schema = @Schema(pattern = REF_NAME_PATH_ELEMENT_REGEX),
Expand Down
17 changes: 8 additions & 9 deletions model/src/main/java/org/projectnessie/model/CommitMeta.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,8 @@
import org.eclipse.microprofile.openapi.annotations.media.Schema;
import org.eclipse.microprofile.openapi.annotations.media.SchemaProperty;
import org.immutables.value.Value;
import org.projectnessie.api.v1.ApiAttributesV1;
import org.projectnessie.api.v2.ApiAttributesV2;
import org.projectnessie.model.ser.CommitMetaDeserializer;
import org.projectnessie.model.ser.Views;

@Value.Immutable
@Schema(
Expand Down Expand Up @@ -89,13 +88,13 @@ public abstract class CommitMeta {
/** The author of a commit. This is the original committer. */
@Nullable
@Value.Derived
@JsonView(ApiAttributesV1.class)
@JsonView(Views.V1.class)
public String getAuthor() {
return getAllAuthors().isEmpty() ? null : getAllAuthors().get(0);
}

@NotNull
@JsonView(ApiAttributesV2.class)
@JsonView(Views.V2.class)
@JsonProperty("authors")
public abstract List<String> getAllAuthors();

Expand All @@ -107,13 +106,13 @@ public String getAuthor() {
*/
@Nullable
@Value.Derived
@JsonView(ApiAttributesV1.class)
@JsonView(Views.V1.class)
public String getSignedOffBy() {
return getAllSignedOffBy().isEmpty() ? null : getAllSignedOffBy().get(0);
}

@NotNull
@JsonView(ApiAttributesV2.class)
@JsonView(Views.V2.class)
public abstract List<String> getAllSignedOffBy();

/**
Expand Down Expand Up @@ -144,7 +143,7 @@ public String getSignedOffBy() {
*/
@NotNull
@Value.Derived
@JsonView(ApiAttributesV1.class)
@JsonView(Views.V1.class)
public Map<String, String> getProperties() {
HashMap<String, String> firstElements = new HashMap<>();
for (Map.Entry<String, List<String>> entry : getAllProperties().entrySet()) {
Expand All @@ -157,12 +156,12 @@ public Map<String, String> getProperties() {
}

@NotNull
@JsonView(ApiAttributesV2.class)
@JsonView(Views.V2.class)
@JsonInclude(JsonInclude.Include.NON_EMPTY)
public abstract Map<String, List<String>> getAllProperties();

@NotNull
@JsonView(ApiAttributesV2.class)
@JsonView(Views.V2.class)
@JsonInclude(JsonInclude.Include.NON_EMPTY)
public abstract List<String> getParentCommitHashes();

Expand Down
Loading

0 comments on commit 9ac02b5

Please sign in to comment.