From 9ac02b53833f4549c1d25a154a32d7f88585ccc0 Mon Sep 17 00:00:00 2001 From: Dmitri Bourlatchkov Date: Tue, 20 Dec 2022 14:59:42 -0500 Subject: [PATCH] Make generated OpenAPI type names more readable (#5732) 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 --- .../client/http/HttpClientBuilder.java | 7 ++--- .../internal/TranslatingVersionNessieApi.java | 4 +-- .../api/v1/http/HttpTreeApi.java | 24 +++++++-------- .../projectnessie/api/v2/ApiAttributesV2.java | 19 ------------ .../api/v2/http/HttpTreeApi.java | 30 +++++++++---------- .../org/projectnessie/model/CommitMeta.java | 17 +++++------ .../ser/Views.java} | 12 ++++++-- .../model/TestModelObjectsSerialization.java | 7 ++--- .../model/ser/TestCommitMetaDeserializer.java | 20 +++++-------- .../services/rest/RestTreeResource.java | 24 +++++++-------- .../services/rest/RestV2TreeResource.java | 30 +++++++++---------- .../versioned/CommitMetaSerializer.java | 4 +-- .../versioned/TestCommitMetaSerializer.java | 6 ++-- .../transfer/ExportImportTestUtil.java | 4 +-- 14 files changed, 93 insertions(+), 115 deletions(-) delete mode 100644 model/src/main/java/org/projectnessie/api/v2/ApiAttributesV2.java rename model/src/main/java/org/projectnessie/{api/v1/ApiAttributesV1.java => model/ser/Views.java} (64%) diff --git a/clients/client/src/main/java/org/projectnessie/client/http/HttpClientBuilder.java b/clients/client/src/main/java/org/projectnessie/client/http/HttpClientBuilder.java index 6c42dfdedd8..bd795e8b38d 100644 --- a/clients/client/src/main/java/org/projectnessie/client/http/HttpClientBuilder.java +++ b/clients/client/src/main/java/org/projectnessie/client/http/HttpClientBuilder.java @@ -37,8 +37,6 @@ 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; @@ -46,6 +44,7 @@ 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()}. @@ -287,13 +286,13 @@ public API build(Class 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); } diff --git a/compatibility/common/src/main/java/org/projectnessie/tools/compatibility/internal/TranslatingVersionNessieApi.java b/compatibility/common/src/main/java/org/projectnessie/tools/compatibility/internal/TranslatingVersionNessieApi.java index 70c236efc10..4cfeff0bdd7 100644 --- a/compatibility/common/src/main/java/org/projectnessie/tools/compatibility/internal/TranslatingVersionNessieApi.java +++ b/compatibility/common/src/main/java/org/projectnessie/tools/compatibility/internal/TranslatingVersionNessieApi.java @@ -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. @@ -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() diff --git a/model/src/main/java/org/projectnessie/api/v1/http/HttpTreeApi.java b/model/src/main/java/org/projectnessie/api/v1/http/HttpTreeApi.java index e425a1a8113..001f86480a3 100644 --- a/model/src/main/java/org/projectnessie/api/v1/http/HttpTreeApi.java +++ b/model/src/main/java/org/projectnessie/api/v1/http/HttpTreeApi.java @@ -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; @@ -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) @@ -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 @@ -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 @@ -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, @@ -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 @@ -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", @@ -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", @@ -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", @@ -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", @@ -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", @@ -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", @@ -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.", diff --git a/model/src/main/java/org/projectnessie/api/v2/ApiAttributesV2.java b/model/src/main/java/org/projectnessie/api/v2/ApiAttributesV2.java deleted file mode 100644 index 52ddbd14cd4..00000000000 --- a/model/src/main/java/org/projectnessie/api/v2/ApiAttributesV2.java +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Copyright (C) 2022 Dremio - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.projectnessie.api.v2; - -/** This class is used to define JSON views for REST API v2 parameters and payload objects. */ -public final class ApiAttributesV2 {} diff --git a/model/src/main/java/org/projectnessie/api/v2/http/HttpTreeApi.java b/model/src/main/java/org/projectnessie/api/v2/http/HttpTreeApi.java index fb9b16ba21b..5dd1fa1304c 100644 --- a/model/src/main/java/org/projectnessie/api/v2/http/HttpTreeApi.java +++ b/model/src/main/java/org/projectnessie/api/v2/http/HttpTreeApi.java @@ -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; @@ -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") @@ -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 @@ -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, @@ -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; @@ -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), @@ -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), @@ -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 @@ -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", @@ -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", @@ -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( @@ -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.", @@ -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), @@ -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), @@ -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), @@ -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), diff --git a/model/src/main/java/org/projectnessie/model/CommitMeta.java b/model/src/main/java/org/projectnessie/model/CommitMeta.java index 43a84a96054..b6c7f7be676 100644 --- a/model/src/main/java/org/projectnessie/model/CommitMeta.java +++ b/model/src/main/java/org/projectnessie/model/CommitMeta.java @@ -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( @@ -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 getAllAuthors(); @@ -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 getAllSignedOffBy(); /** @@ -144,7 +143,7 @@ public String getSignedOffBy() { */ @NotNull @Value.Derived - @JsonView(ApiAttributesV1.class) + @JsonView(Views.V1.class) public Map getProperties() { HashMap firstElements = new HashMap<>(); for (Map.Entry> entry : getAllProperties().entrySet()) { @@ -157,12 +156,12 @@ public Map getProperties() { } @NotNull - @JsonView(ApiAttributesV2.class) + @JsonView(Views.V2.class) @JsonInclude(JsonInclude.Include.NON_EMPTY) public abstract Map> getAllProperties(); @NotNull - @JsonView(ApiAttributesV2.class) + @JsonView(Views.V2.class) @JsonInclude(JsonInclude.Include.NON_EMPTY) public abstract List getParentCommitHashes(); diff --git a/model/src/main/java/org/projectnessie/api/v1/ApiAttributesV1.java b/model/src/main/java/org/projectnessie/model/ser/Views.java similarity index 64% rename from model/src/main/java/org/projectnessie/api/v1/ApiAttributesV1.java rename to model/src/main/java/org/projectnessie/model/ser/Views.java index aa24549cf6a..a5d42bd04f2 100644 --- a/model/src/main/java/org/projectnessie/api/v1/ApiAttributesV1.java +++ b/model/src/main/java/org/projectnessie/model/ser/Views.java @@ -13,7 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.projectnessie.api.v1; +package org.projectnessie.model.ser; -/** This class is used to define JSON views for REST API v1 parameters and payload objects. */ -public final class ApiAttributesV1 {} +public abstract class Views { + + /** This class defines the JSON view for REST API v1 parameters and payload objects. */ + public static final class V1 {} + + /** This class defines the JSON view for REST API v2 parameters and payload objects. */ + public static final class V2 {} +} diff --git a/model/src/test/java/org/projectnessie/model/TestModelObjectsSerialization.java b/model/src/test/java/org/projectnessie/model/TestModelObjectsSerialization.java index 18b272bfb96..0b9adffca96 100644 --- a/model/src/test/java/org/projectnessie/model/TestModelObjectsSerialization.java +++ b/model/src/test/java/org/projectnessie/model/TestModelObjectsSerialization.java @@ -29,9 +29,8 @@ import org.junit.jupiter.api.parallel.ExecutionMode; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; -import org.projectnessie.api.v1.ApiAttributesV1; -import org.projectnessie.api.v2.ApiAttributesV2; import org.projectnessie.model.LogResponse.LogEntry; +import org.projectnessie.model.ser.Views; /** * This test merely checks the JSON serialization/deserialization of the model classes, with an @@ -114,7 +113,7 @@ static List goodCases() { .authorTime(Instant.ofEpochSecond(1)) .commitTime(Instant.ofEpochSecond(2)) .build(), - ApiAttributesV2.class, + Views.V2.class, CommitMeta.class, Json.from("hash", HASH) .add("committer", "c1") @@ -195,7 +194,7 @@ public Case(Class deserializeAs, Json deserializedJson) { } public Case(Object obj, Class deserializeAs, Json deserializedJson) { - this(obj, ApiAttributesV1.class, deserializeAs, deserializedJson); + this(obj, Views.V1.class, deserializeAs, deserializedJson); } public Case( diff --git a/model/src/test/java/org/projectnessie/model/ser/TestCommitMetaDeserializer.java b/model/src/test/java/org/projectnessie/model/ser/TestCommitMetaDeserializer.java index 51d99d6bd7b..0653bb27da4 100644 --- a/model/src/test/java/org/projectnessie/model/ser/TestCommitMetaDeserializer.java +++ b/model/src/test/java/org/projectnessie/model/ser/TestCommitMetaDeserializer.java @@ -25,8 +25,6 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; -import org.projectnessie.api.v1.ApiAttributesV1; -import org.projectnessie.api.v2.ApiAttributesV2; import org.projectnessie.model.CommitMeta; class TestCommitMetaDeserializer { @@ -42,7 +40,7 @@ private CommitMeta deser(Class view, CommitMeta value) throws JsonProcessingE } @ParameterizedTest - @ValueSource(classes = {Object.class, ApiAttributesV1.class, ApiAttributesV2.class}) + @ValueSource(classes = {Object.class, Views.V1.class, Views.V2.class}) void testAuthor(Class view) throws JsonProcessingException { CommitMeta meta = deser(view, CommitMeta.builder().message("m").author("t1").author("t2").build()); @@ -50,7 +48,7 @@ void testAuthor(Class view) throws JsonProcessingException { } @ParameterizedTest - @ValueSource(classes = {Object.class, ApiAttributesV2.class}) + @ValueSource(classes = {Object.class, Views.V2.class}) void testAllAuthors(Class view) throws JsonProcessingException { CommitMeta meta = deser( @@ -61,14 +59,12 @@ void testAllAuthors(Class view) throws JsonProcessingException { @Test void testAllAuthorsTruncated() throws JsonProcessingException { CommitMeta meta = - deser( - ApiAttributesV1.class, - CommitMeta.builder().message("m").author("t1").author("t2").build()); + deser(Views.V1.class, CommitMeta.builder().message("m").author("t1").author("t2").build()); assertThat(meta.getAllAuthors()).containsExactly("t1"); } @ParameterizedTest - @ValueSource(classes = {Object.class, ApiAttributesV1.class, ApiAttributesV2.class}) + @ValueSource(classes = {Object.class, Views.V1.class, Views.V2.class}) void testSignedOffBy(Class view) throws JsonProcessingException { CommitMeta meta = deser( @@ -83,7 +79,7 @@ void testSignedOffBy(Class view) throws JsonProcessingException { } @ParameterizedTest - @ValueSource(classes = {Object.class, ApiAttributesV2.class}) + @ValueSource(classes = {Object.class, Views.V2.class}) void testAllSignedOffBy(Class view) throws JsonProcessingException { CommitMeta meta = deser(view, CommitMeta.builder().message("m").signedOffBy("s1").signedOffBy("s2").build()); @@ -91,7 +87,7 @@ void testAllSignedOffBy(Class view) throws JsonProcessingException { } @ParameterizedTest - @ValueSource(classes = {Object.class, ApiAttributesV1.class, ApiAttributesV2.class}) + @ValueSource(classes = {Object.class, Views.V1.class, Views.V2.class}) void testSimpleProperties(Class view) throws JsonProcessingException { CommitMeta meta = deser( @@ -107,7 +103,7 @@ void testSimpleProperties(Class view) throws JsonProcessingException { } @ParameterizedTest - @ValueSource(classes = {Object.class, ApiAttributesV2.class}) + @ValueSource(classes = {Object.class, Views.V2.class}) void testListProperties(Class view) throws JsonProcessingException { CommitMeta meta = deser( @@ -137,7 +133,7 @@ void testListProperties(Class view) throws JsonProcessingException { void testListPropertiesTruncated() throws JsonProcessingException { CommitMeta meta = deser( - ApiAttributesV1.class, + Views.V1.class, CommitMeta.builder() .message("m") .putAllProperties("k1", Arrays.asList("v1a", "v1b")) diff --git a/servers/rest-services/src/main/java/org/projectnessie/services/rest/RestTreeResource.java b/servers/rest-services/src/main/java/org/projectnessie/services/rest/RestTreeResource.java index 1056e233685..bcbcc9ef2f9 100644 --- a/servers/rest-services/src/main/java/org/projectnessie/services/rest/RestTreeResource.java +++ b/servers/rest-services/src/main/java/org/projectnessie/services/rest/RestTreeResource.java @@ -21,7 +21,6 @@ import javax.inject.Inject; import javax.ws.rs.core.Context; import javax.ws.rs.core.SecurityContext; -import org.projectnessie.api.v1.ApiAttributesV1; import org.projectnessie.api.v1.http.HttpTreeApi; import org.projectnessie.api.v1.params.CommitLogParams; import org.projectnessie.api.v1.params.EntriesParams; @@ -38,6 +37,7 @@ import org.projectnessie.model.Operations; import org.projectnessie.model.Reference; import org.projectnessie.model.ReferencesResponse; +import org.projectnessie.model.ser.Views; import org.projectnessie.services.authz.Authorizer; import org.projectnessie.services.config.ServerConfig; import org.projectnessie.services.impl.TreeApiImplWithAuthorization; @@ -78,20 +78,20 @@ private TreeService resource() { securityContext == null ? null : securityContext.getUserPrincipal()); } - @JsonView(ApiAttributesV1.class) + @JsonView(Views.V1.class) @Override public ReferencesResponse getAllReferences(ReferencesParams params) { Preconditions.checkArgument(params.pageToken() == null, "Paging not supported"); return resource().getAllReferences(params.fetchOption(), params.filter()); } - @JsonView(ApiAttributesV1.class) + @JsonView(Views.V1.class) @Override public Branch getDefaultBranch() throws NessieNotFoundException { return resource().getDefaultBranch(); } - @JsonView(ApiAttributesV1.class) + @JsonView(Views.V1.class) @Override public Reference createReference(String sourceRefName, Reference reference) throws NessieNotFoundException, NessieConflictException { @@ -100,13 +100,13 @@ public Reference createReference(String sourceRefName, Reference reference) reference.getName(), reference.getType(), reference.getHash(), sourceRefName); } - @JsonView(ApiAttributesV1.class) + @JsonView(Views.V1.class) @Override public Reference getReferenceByName(GetReferenceParams params) throws NessieNotFoundException { return resource().getReferenceByName(params.getRefName(), params.fetchOption()); } - @JsonView(ApiAttributesV1.class) + @JsonView(Views.V1.class) @Override public EntriesResponse getEntries(String refName, EntriesParams params) throws NessieNotFoundException { @@ -115,7 +115,7 @@ public EntriesResponse getEntries(String refName, EntriesParams params) .getEntries(refName, params.hashOnRef(), params.namespaceDepth(), params.filter()); } - @JsonView(ApiAttributesV1.class) + @JsonView(Views.V1.class) @Override public LogResponse getCommitLog(String ref, CommitLogParams params) throws NessieNotFoundException { @@ -130,7 +130,7 @@ public LogResponse getCommitLog(String ref, CommitLogParams params) params.pageToken()); } - @JsonView(ApiAttributesV1.class) + @JsonView(Views.V1.class) @Override public void assignReference( Reference.ReferenceType referenceType, @@ -141,7 +141,7 @@ public void assignReference( resource().assignReference(referenceType, referenceName, expectedHash, assignTo); } - @JsonView(ApiAttributesV1.class) + @JsonView(Views.V1.class) @Override public void deleteReference( Reference.ReferenceType referenceType, String referenceName, String expectedHash) @@ -149,7 +149,7 @@ public void deleteReference( resource().deleteReference(referenceType, referenceName, expectedHash); } - @JsonView(ApiAttributesV1.class) + @JsonView(Views.V1.class) @Override public MergeResponse transplantCommitsIntoBranch( String branchName, String expectedHash, String message, Transplant transplant) @@ -169,7 +169,7 @@ public MergeResponse transplantCommitsIntoBranch( transplant.isReturnConflictAsResult()); } - @JsonView(ApiAttributesV1.class) + @JsonView(Views.V1.class) @Override public MergeResponse mergeRefIntoBranch(String branchName, String expectedHash, Merge merge) throws NessieNotFoundException, NessieConflictException { @@ -188,7 +188,7 @@ public MergeResponse mergeRefIntoBranch(String branchName, String expectedHash, merge.isReturnConflictAsResult()); } - @JsonView(ApiAttributesV1.class) + @JsonView(Views.V1.class) @Override public Branch commitMultipleOperations( String branchName, String expectedHash, Operations operations) diff --git a/servers/rest-services/src/main/java/org/projectnessie/services/rest/RestV2TreeResource.java b/servers/rest-services/src/main/java/org/projectnessie/services/rest/RestV2TreeResource.java index b80d7bbd007..237f700c4c7 100644 --- a/servers/rest-services/src/main/java/org/projectnessie/services/rest/RestV2TreeResource.java +++ b/servers/rest-services/src/main/java/org/projectnessie/services/rest/RestV2TreeResource.java @@ -21,7 +21,6 @@ import javax.inject.Inject; import javax.ws.rs.core.Context; import javax.ws.rs.core.SecurityContext; -import org.projectnessie.api.v2.ApiAttributesV2; import org.projectnessie.api.v2.http.HttpTreeApi; import org.projectnessie.api.v2.params.CommitLogParams; import org.projectnessie.api.v2.params.DiffParams; @@ -48,6 +47,7 @@ import org.projectnessie.model.Reference; import org.projectnessie.model.ReferencesResponse; import org.projectnessie.model.SingleReferenceResponse; +import org.projectnessie.model.ser.Views; import org.projectnessie.services.authz.Authorizer; import org.projectnessie.services.config.ServerConfig; import org.projectnessie.services.impl.ContentApiImplWithAuthorization; @@ -118,13 +118,13 @@ private ContentService content() { securityContext == null ? null : securityContext.getUserPrincipal()); } - @JsonView(ApiAttributesV2.class) + @JsonView(Views.V2.class) @Override public ReferencesResponse getAllReferences(ReferencesParams params) { return tree().getAllReferences(params.fetchOption(), params.filter()); } - @JsonView(ApiAttributesV2.class) + @JsonView(Views.V2.class) @Override public SingleReferenceResponse createReference( String name, Reference.ReferenceType type, Reference reference) @@ -140,7 +140,7 @@ public SingleReferenceResponse createReference( return SingleReferenceResponse.builder().reference(created).build(); } - @JsonView(ApiAttributesV2.class) + @JsonView(Views.V2.class) @Override public SingleReferenceResponse getReferenceByName(GetReferenceParams params) throws NessieNotFoundException { @@ -150,7 +150,7 @@ public SingleReferenceResponse getReferenceByName(GetReferenceParams params) .build(); } - @JsonView(ApiAttributesV2.class) + @JsonView(Views.V2.class) @Override public EntriesResponse getEntries(String ref, EntriesParams params) throws NessieNotFoundException { @@ -158,7 +158,7 @@ public EntriesResponse getEntries(String ref, EntriesParams params) return tree().getEntries(reference.getName(), reference.getHash(), null, params.filter()); } - @JsonView(ApiAttributesV2.class) + @JsonView(Views.V2.class) @Override public LogResponse getCommitLog(String ref, CommitLogParams params) throws NessieNotFoundException { @@ -174,7 +174,7 @@ public LogResponse getCommitLog(String ref, CommitLogParams params) params.pageToken()); } - @JsonView(ApiAttributesV2.class) + @JsonView(Views.V2.class) @Override public DiffResponse getDiff(DiffParams params) throws NessieNotFoundException { Reference from = resolveRef(params.getFromRef()); @@ -182,7 +182,7 @@ public DiffResponse getDiff(DiffParams params) throws NessieNotFoundException { return diff().getDiff(from.getName(), from.getHash(), to.getName(), to.getHash()); } - @JsonView(ApiAttributesV2.class) + @JsonView(Views.V2.class) @Override public SingleReferenceResponse assignReference( Reference.ReferenceType type, String ref, Reference assignTo) @@ -193,7 +193,7 @@ public SingleReferenceResponse assignReference( return SingleReferenceResponse.builder().reference(updated).build(); } - @JsonView(ApiAttributesV2.class) + @JsonView(Views.V2.class) @Override public SingleReferenceResponse deleteReference(Reference.ReferenceType type, String ref) throws NessieConflictException, NessieNotFoundException { @@ -202,7 +202,7 @@ public SingleReferenceResponse deleteReference(Reference.ReferenceType type, Str return SingleReferenceResponse.builder().reference(reference).build(); } - @JsonView(ApiAttributesV2.class) + @JsonView(Views.V2.class) @Override public ContentResponse getContent(ContentKey key, String ref) throws NessieNotFoundException { Reference reference = resolveRef(ref); @@ -210,7 +210,7 @@ public ContentResponse getContent(ContentKey key, String ref) throws NessieNotFo return ContentResponse.builder().content(content).build(); } - @JsonView(ApiAttributesV2.class) + @JsonView(Views.V2.class) @Override public GetMultipleContentsResponse getSeveralContents(String ref, List keys) throws NessieNotFoundException { @@ -219,7 +219,7 @@ public GetMultipleContentsResponse getSeveralContents(String ref, List k return getMultipleContents(ref, request.build()); } - @JsonView(ApiAttributesV2.class) + @JsonView(Views.V2.class) @Override public GetMultipleContentsResponse getMultipleContents( String ref, GetMultipleContentsRequest request) throws NessieNotFoundException { @@ -228,7 +228,7 @@ public GetMultipleContentsResponse getMultipleContents( .getMultipleContents(reference.getName(), reference.getHash(), request.getRequestedKeys()); } - @JsonView(ApiAttributesV2.class) + @JsonView(Views.V2.class) @Override public MergeResponse transplantCommitsIntoBranch(String branch, Transplant transplant) throws NessieNotFoundException, NessieConflictException { @@ -248,7 +248,7 @@ public MergeResponse transplantCommitsIntoBranch(String branch, Transplant trans transplant.isReturnConflictAsResult()); } - @JsonView(ApiAttributesV2.class) + @JsonView(Views.V2.class) @Override public MergeResponse mergeRefIntoBranch(String branch, Merge merge) throws NessieNotFoundException, NessieConflictException { @@ -268,7 +268,7 @@ public MergeResponse mergeRefIntoBranch(String branch, Merge merge) merge.isReturnConflictAsResult()); } - @JsonView(ApiAttributesV2.class) + @JsonView(Views.V2.class) @Override public CommitResponse commitMultipleOperations(String branch, Operations operations) throws NessieNotFoundException, NessieConflictException { diff --git a/versioned/spi/src/main/java/org/projectnessie/versioned/CommitMetaSerializer.java b/versioned/spi/src/main/java/org/projectnessie/versioned/CommitMetaSerializer.java index 836697e985e..5ba75632661 100644 --- a/versioned/spi/src/main/java/org/projectnessie/versioned/CommitMetaSerializer.java +++ b/versioned/spi/src/main/java/org/projectnessie/versioned/CommitMetaSerializer.java @@ -20,9 +20,9 @@ import com.google.protobuf.ByteString.Output; import java.io.IOException; import java.io.InputStream; -import org.projectnessie.api.v1.ApiAttributesV1; import org.projectnessie.model.CommitMeta; import org.projectnessie.model.ImmutableCommitMeta; +import org.projectnessie.model.ser.Views; public class CommitMetaSerializer implements Serializer { @@ -35,7 +35,7 @@ public ByteString toBytes(CommitMeta value) { try (Output out = ByteString.newOutput()) { // Store commit metadata using v1 format. This is to allow rolling upgrades to server // versions with v2 support. - MAPPER.writerWithView(ApiAttributesV1.class).writeValue(out, value); + MAPPER.writerWithView(Views.V1.class).writeValue(out, value); return out.toByteString(); } catch (IOException e) { throw new RuntimeException(String.format("Couldn't serialize commit meta %s", value), e); diff --git a/versioned/spi/src/test/java/org/projectnessie/versioned/TestCommitMetaSerializer.java b/versioned/spi/src/test/java/org/projectnessie/versioned/TestCommitMetaSerializer.java index 150820ae82d..346cdc34812 100644 --- a/versioned/spi/src/test/java/org/projectnessie/versioned/TestCommitMetaSerializer.java +++ b/versioned/spi/src/test/java/org/projectnessie/versioned/TestCommitMetaSerializer.java @@ -22,9 +22,9 @@ import com.google.protobuf.ByteString; import java.time.Instant; import org.junit.jupiter.api.Test; -import org.projectnessie.api.v1.ApiAttributesV1; import org.projectnessie.model.CommitMeta; import org.projectnessie.model.ImmutableCommitMeta; +import org.projectnessie.model.ser.Views; public class TestCommitMetaSerializer { @@ -42,9 +42,7 @@ void testCommitSerde() throws JsonProcessingException { ByteString expectedBytes = ByteString.copyFrom( - new ObjectMapper() - .writerWithView(ApiAttributesV1.class) - .writeValueAsBytes(expectedCommit)); + new ObjectMapper().writerWithView(Views.V1.class).writeValueAsBytes(expectedCommit)); CommitMeta actualCommit = CommitMetaSerializer.METADATA_SERIALIZER.fromBytes(expectedBytes); assertThat(actualCommit).isEqualTo(expectedCommit); ByteString actualBytes = CommitMetaSerializer.METADATA_SERIALIZER.toBytes(expectedCommit); diff --git a/versioned/transfer/src/test/java/org/projectnessie/versioned/transfer/ExportImportTestUtil.java b/versioned/transfer/src/test/java/org/projectnessie/versioned/transfer/ExportImportTestUtil.java index 5beaaa6c613..d0f732d04c5 100644 --- a/versioned/transfer/src/test/java/org/projectnessie/versioned/transfer/ExportImportTestUtil.java +++ b/versioned/transfer/src/test/java/org/projectnessie/versioned/transfer/ExportImportTestUtil.java @@ -23,8 +23,8 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; -import org.projectnessie.api.v1.ApiAttributesV1; import org.projectnessie.model.CommitMeta; +import org.projectnessie.model.ser.Views; import org.projectnessie.versioned.Hash; import org.projectnessie.versioned.persist.adapter.CommitLogEntry; @@ -41,7 +41,7 @@ static ByteString commitMeta(int i) { try { return ByteString.copyFromUtf8( MAPPER - .writerWithView(ApiAttributesV1.class) + .writerWithView(Views.V1.class) .writeValueAsString(CommitMeta.fromMessage("commit # " + i))); } catch (JsonProcessingException e) { throw new RuntimeException(e);