Skip to content

Commit

Permalink
Isolate OpenAPI-generated classes in separate modules (apache#539)
Browse files Browse the repository at this point in the history
  • Loading branch information
adutra authored Dec 12, 2024
1 parent 6a71d8e commit 32174be
Show file tree
Hide file tree
Showing 14 changed files with 334 additions and 168 deletions.
36 changes: 36 additions & 0 deletions api/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you 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.
-->

# Apache Polaris API Modules

This directory contains the API modules for Apache Polaris.

## Modules

- [`polaris-api-management-model`](management-model): contains the model classes for the Polaris
Management API.
- [`polaris-api-management-service`](management-service): contains the service classes for the
Polaris Management API.
- [`polaris-api-iceberg-service`](iceberg-service): contains the service classes for the Polaris
Iceberg REST API.

The classes in these modules are generated from the OpenAPI specification files in the
[`spec`](../spec) directory.
111 changes: 111 additions & 0 deletions api/iceberg-service/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.
*/

plugins {
alias(libs.plugins.openapi.generator)
id("polaris-client")
}

dependencies {
implementation(platform(libs.iceberg.bom))
implementation("org.apache.iceberg:iceberg-api")
implementation("org.apache.iceberg:iceberg-core")

compileOnly(libs.jakarta.annotation.api)
compileOnly(libs.jakarta.inject.api)
compileOnly(libs.jakarta.validation.api)
compileOnly(libs.swagger.annotations)

implementation(libs.jakarta.servlet.api)
implementation(libs.jakarta.ws.rs.api)

compileOnly(platform(libs.micrometer.bom))
compileOnly("io.micrometer:micrometer-core")

compileOnly(platform(libs.jackson.bom))
compileOnly("com.fasterxml.jackson.core:jackson-annotations")
}

openApiGenerate {
inputSpec = "$rootDir/spec/rest-catalog-open-api.yaml"
generatorName = "jaxrs-resteasy"
outputDir = "$projectDir/build/generated"
apiPackage = "org.apache.polaris.service.catalog.api"
ignoreFileOverride = "$rootDir/.openapi-generator-ignore"
removeOperationIdPrefix = true
templateDir = "$rootDir/server-templates"
globalProperties.put("apis", "")
globalProperties.put("models", "false")
globalProperties.put("apiDocs", "false")
globalProperties.put("modelTests", "false")
configOptions.put("resourceName", "catalog")
configOptions.put("useTags", "true")
configOptions.put("useBeanValidation", "false")
configOptions.put("sourceFolder", "src/main/java")
configOptions.put("useJakartaEe", "true")
openapiNormalizer.put("REFACTOR_ALLOF_WITH_PROPERTIES_ONLY", "true")
additionalProperties.put("apiNamePrefix", "IcebergRest")
additionalProperties.put("apiNameSuffix", "")
additionalProperties.put("metricsPrefix", "polaris")
serverVariables.put("basePath", "api/catalog")
importMappings =
mapOf(
"CatalogConfig" to "org.apache.iceberg.rest.responses.ConfigResponse",
"CommitTableResponse" to "org.apache.iceberg.rest.responses.LoadTableResponse",
"CreateNamespaceRequest" to "org.apache.iceberg.rest.requests.CreateNamespaceRequest",
"CreateNamespaceResponse" to "org.apache.iceberg.rest.responses.CreateNamespaceResponse",
"CreateTableRequest" to "org.apache.iceberg.rest.requests.CreateTableRequest",
"ErrorModel" to "org.apache.iceberg.rest.responses.ErrorResponse",
"GetNamespaceResponse" to "org.apache.iceberg.rest.responses.GetNamespaceResponse",
"ListNamespacesResponse" to "org.apache.iceberg.rest.responses.ListNamespacesResponse",
"ListTablesResponse" to "org.apache.iceberg.rest.responses.ListTablesResponse",
"LoadCredentialsResponse" to "org.apache.iceberg.rest.responses.LoadCredentialsResponse",
"LoadTableResult" to "org.apache.iceberg.rest.responses.LoadTableResponse",
"LoadViewResult" to "org.apache.iceberg.rest.responses.LoadTableResponse",
"OAuthTokenResponse" to "org.apache.iceberg.rest.responses.OAuthTokenResponse",
"OAuthErrorResponse" to "org.apache.iceberg.rest.responses.OAuthErrorResponse",
"RenameTableRequest" to "org.apache.iceberg.rest.requests.RenameTableRequest",
"ReportMetricsRequest" to "org.apache.iceberg.rest.requests.ReportMetricsRequest",
"UpdateNamespacePropertiesRequest" to
"org.apache.iceberg.rest.requests.UpdateNamespacePropertiesRequest",
"UpdateNamespacePropertiesResponse" to
"org.apache.iceberg.rest.responses.UpdateNamespacePropertiesResponse",
"CommitTransactionRequest" to "org.apache.iceberg.rest.requests.CommitTransactionRequest",
"CreateViewRequest" to "org.apache.iceberg.rest.requests.CreateViewRequest",
"RegisterTableRequest" to "org.apache.iceberg.rest.requests.RegisterTableRequest",
"IcebergErrorResponse" to "org.apache.iceberg.rest.responses.ErrorResponse",
"OAuthError" to "org.apache.iceberg.rest.responses.ErrorResponse",

// Custom types defined below
"CommitViewRequest" to "org.apache.polaris.service.types.CommitViewRequest",
"TokenType" to "org.apache.polaris.service.types.TokenType",
"CommitTableRequest" to "org.apache.polaris.service.types.CommitTableRequest",
"NotificationRequest" to "org.apache.polaris.service.types.NotificationRequest",
"TableUpdateNotification" to "org.apache.polaris.service.types.TableUpdateNotification",
"NotificationType" to "org.apache.polaris.service.types.NotificationType"
)
}

listOf("sourcesJar", "compileJava").forEach { task ->
tasks.named(task) { dependsOn("openApiGenerate") }
}

sourceSets {
main { java { srcDir(project.layout.buildDirectory.dir("generated/src/main/java")) } }
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@
import io.swagger.annotations.ApiModelProperty;
import java.util.Objects;

@jakarta.annotation.Generated(
value = "org.openapitools.codegen.languages.JavaResteasyServerCodegen",
date = "2024-05-25T00:53:53.298853423Z[UTC]",
comments = "Generator version: 7.5.0")
public class NotificationRequest {

private NotificationType notificationType;
Expand Down Expand Up @@ -73,12 +69,14 @@ public int hashCode() {

@Override
public String toString() {
return """
class NotificationRequest {
notificationType: %s
payload: %s
}"""
.formatted(toIndentedString(notificationType), toIndentedString(payload));
return "class NotificationRequest {\n"
+ " notificationType: "
+ toIndentedString(notificationType)
+ "\n"
+ " payload: "
+ toIndentedString(payload)
+ "\n"
+ "}";
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
package org.apache.polaris.service.types;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.base.Preconditions;
import io.swagger.annotations.ApiModelProperty;
import java.util.Objects;
import org.apache.iceberg.TableMetadata;
Expand Down Expand Up @@ -125,20 +124,23 @@ public int hashCode() {

@Override
public String toString() {
return """
class TableUpdateNotification {
tableName: %s
timestamp: %s
tableUuid: %s
metadataLocation: %s
metadata: %s
}"""
.formatted(
toIndentedString(tableName),
toIndentedString(timestamp),
toIndentedString(tableUuid),
toIndentedString(metadataLocation),
toIndentedString(metadata));
return "class TableUpdateNotification {\n"
+ " tableName: "
+ toIndentedString(tableName)
+ "\n"
+ " timestamp: "
+ toIndentedString(timestamp)
+ "\n"
+ " tableUuid: "
+ toIndentedString(tableUuid)
+ "\n"
+ " metadataLocation: "
+ toIndentedString(metadataLocation)
+ "\n"
+ " metadata: "
+ toIndentedString(metadata)
+ "\n"
+ "}";
}

/**
Expand Down Expand Up @@ -166,19 +168,25 @@ public static final class Builder {
private Builder() {}

public final Builder tableName(String tableName) {
Preconditions.checkArgument(tableName != null, "Null table name supplied");
if (tableName == null) {
throw new IllegalArgumentException("Null table name supplied");
}
this.tableName = tableName;
return this;
}

public final Builder timestamp(Long timestamp) {
Preconditions.checkArgument(timestamp != null, "timestamp can't be null");
if (timestamp == null) {
throw new IllegalArgumentException("timestamp can't be null");
}
this.timestamp = timestamp;
return this;
}

public final Builder metadataLocation(String metadataLocation) {
Preconditions.checkArgument(metadataLocation != null, "metadataLocation can't be null");
if (metadataLocation == null) {
throw new IllegalArgumentException("metadataLocation can't be null");
}
this.metadataLocation = metadataLocation;
return this;
}
Expand All @@ -189,7 +197,9 @@ public final Builder metadata(TableMetadata metadata) {
}

public final Builder tableUuid(String tableUuid) {
Preconditions.checkArgument(tableUuid != null, "timestamp can't be null");
if (tableUuid == null) {
throw new IllegalArgumentException("timestamp can't be null");
}
this.tableUuid = tableUuid;
return this;
}
Expand Down
62 changes: 62 additions & 0 deletions api/management-model/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.
*/

plugins {
alias(libs.plugins.openapi.generator)
id("polaris-client")
}

dependencies {
compileOnly(platform(libs.jackson.bom))
compileOnly("com.fasterxml.jackson.core:jackson-annotations")
compileOnly(libs.jakarta.annotation.api)
compileOnly(libs.jakarta.validation.api)
compileOnly(libs.swagger.annotations)
}

openApiGenerate {
inputSpec = "$rootDir/spec/polaris-management-service.yml"
generatorName = "jaxrs-resteasy"
outputDir = "$projectDir/build/generated"
modelPackage = "org.apache.polaris.core.admin.model"
ignoreFileOverride = "$rootDir/.openapi-generator-ignore"
removeOperationIdPrefix = true
templateDir = "$rootDir/server-templates"
globalProperties.put("apis", "false")
globalProperties.put("models", "")
globalProperties.put("apiDocs", "false")
globalProperties.put("modelTests", "false")
configOptions.put("useBeanValidation", "true")
configOptions.put("sourceFolder", "src/main/java")
configOptions.put("useJakartaEe", "true")
configOptions.put("generateBuilders", "true")
configOptions.put("generateConstructorWithAllArgs", "true")
additionalProperties.put("apiNamePrefix", "Polaris")
additionalProperties.put("apiNameSuffix", "Api")
additionalProperties.put("metricsPrefix", "polaris")
serverVariables = mapOf("basePath" to "api/v1")
}

listOf("sourcesJar", "compileJava").forEach { task ->
tasks.named(task) { dependsOn("openApiGenerate") }
}

sourceSets {
main { java { srcDir(project.layout.buildDirectory.dir("generated/src/main/java")) } }
}
Loading

0 comments on commit 32174be

Please sign in to comment.