205 lines
8.7 KiB
Groovy
205 lines
8.7 KiB
Groovy
import org.openapitools.generator.gradle.plugin.tasks.GenerateTask
|
|
|
|
plugins {
|
|
id "org.openapi.generator" version "6.2.1"
|
|
id "java-library"
|
|
}
|
|
|
|
def specFile = "$projectDir/src/main/openapi/config.yaml"
|
|
|
|
// Deprecated -- can be removed once airbyte-server is converted to use the per-domain endpoints generated by generateApiServer
|
|
task generateApiServerLegacy(type: GenerateTask) {
|
|
def serverOutputDir = "$buildDir/generated/api/server"
|
|
|
|
inputs.file specFile
|
|
outputs.dir serverOutputDir
|
|
|
|
generatorName = "jaxrs-spec"
|
|
inputSpec = specFile
|
|
outputDir = serverOutputDir
|
|
|
|
apiPackage = "io.airbyte.api.generated"
|
|
invokerPackage = "io.airbyte.api.invoker.generated"
|
|
modelPackage = "io.airbyte.api.model.generated"
|
|
|
|
schemaMappings = [
|
|
'OAuthConfiguration' : 'com.fasterxml.jackson.databind.JsonNode',
|
|
'SourceDefinitionSpecification' : 'com.fasterxml.jackson.databind.JsonNode',
|
|
'SourceConfiguration' : 'com.fasterxml.jackson.databind.JsonNode',
|
|
'DestinationDefinitionSpecification': 'com.fasterxml.jackson.databind.JsonNode',
|
|
'DestinationConfiguration' : 'com.fasterxml.jackson.databind.JsonNode',
|
|
'StreamJsonSchema' : 'com.fasterxml.jackson.databind.JsonNode',
|
|
'StateBlob' : 'com.fasterxml.jackson.databind.JsonNode',
|
|
'FieldSchema' : 'com.fasterxml.jackson.databind.JsonNode',
|
|
]
|
|
|
|
generateApiDocumentation = false
|
|
|
|
configOptions = [
|
|
dateLibrary : "java8",
|
|
generatePom : "false",
|
|
interfaceOnly: "true",
|
|
/*
|
|
JAX-RS generator does not respect nullable properties defined in the OpenApi Spec.
|
|
It means that if a field is not nullable but not set it is still returning a null value for this field in the serialized json.
|
|
The below Jackson annotation is made to only keep non null values in serialized json.
|
|
We are not yet using nullable=true properties in our OpenApi so this is a valid workaround at the moment to circumvent the default JAX-RS behavior described above.
|
|
Feel free to read the conversation on https://github.com/airbytehq/airbyte/pull/13370 for more details.
|
|
*/
|
|
additionalModelTypeAnnotations: "\n@com.fasterxml.jackson.annotation.JsonInclude(com.fasterxml.jackson.annotation.JsonInclude.Include.NON_NULL)",
|
|
]
|
|
}
|
|
|
|
task generateApiServer(type: GenerateTask) {
|
|
def serverOutputDir = "$buildDir/generated/api/server"
|
|
|
|
inputs.file specFile
|
|
outputs.dir serverOutputDir
|
|
|
|
generatorName = "jaxrs-spec"
|
|
inputSpec = specFile
|
|
outputDir = serverOutputDir
|
|
|
|
apiPackage = "io.airbyte.api.generated"
|
|
invokerPackage = "io.airbyte.api.invoker.generated"
|
|
modelPackage = "io.airbyte.api.model.generated"
|
|
|
|
schemaMappings = [
|
|
'OAuthConfiguration' : 'com.fasterxml.jackson.databind.JsonNode',
|
|
'SourceDefinitionSpecification' : 'com.fasterxml.jackson.databind.JsonNode',
|
|
'SourceConfiguration' : 'com.fasterxml.jackson.databind.JsonNode',
|
|
'DestinationDefinitionSpecification': 'com.fasterxml.jackson.databind.JsonNode',
|
|
'DestinationConfiguration' : 'com.fasterxml.jackson.databind.JsonNode',
|
|
'StreamJsonSchema' : 'com.fasterxml.jackson.databind.JsonNode',
|
|
'StateBlob' : 'com.fasterxml.jackson.databind.JsonNode',
|
|
'FieldSchema' : 'com.fasterxml.jackson.databind.JsonNode',
|
|
]
|
|
|
|
generateApiDocumentation = false
|
|
|
|
configOptions = [
|
|
dateLibrary : "java8",
|
|
generatePom : "false",
|
|
interfaceOnly: "true",
|
|
/*
|
|
JAX-RS generator does not respect nullable properties defined in the OpenApi Spec.
|
|
It means that if a field is not nullable but not set it is still returning a null value for this field in the serialized json.
|
|
The below Jackson annotation is made to only keep non null values in serialized json.
|
|
We are not yet using nullable=true properties in our OpenApi so this is a valid workaround at the moment to circumvent the default JAX-RS behavior described above.
|
|
Feel free to read the conversation on https://github.com/airbytehq/airbyte/pull/13370 for more details.
|
|
*/
|
|
additionalModelTypeAnnotations: "\n@com.fasterxml.jackson.annotation.JsonInclude(com.fasterxml.jackson.annotation.JsonInclude.Include.NON_NULL)",
|
|
|
|
// Generate separate classes for each endpoint "domain"
|
|
useTags: "true"
|
|
]
|
|
}
|
|
|
|
compileJava.dependsOn tasks.generateApiServerLegacy, tasks.generateApiServer
|
|
|
|
task generateApiClient(type: GenerateTask) {
|
|
def clientOutputDir = "$buildDir/generated/api/client"
|
|
|
|
inputs.file specFile
|
|
outputs.dir clientOutputDir
|
|
|
|
generatorName = "java"
|
|
inputSpec = specFile
|
|
outputDir = clientOutputDir
|
|
|
|
apiPackage = "io.airbyte.api.client.generated"
|
|
invokerPackage = "io.airbyte.api.client.invoker.generated"
|
|
modelPackage = "io.airbyte.api.client.model.generated"
|
|
|
|
schemaMappings = [
|
|
'OAuthConfiguration' : 'com.fasterxml.jackson.databind.JsonNode',
|
|
'SourceDefinitionSpecification' : 'com.fasterxml.jackson.databind.JsonNode',
|
|
'SourceConfiguration' : 'com.fasterxml.jackson.databind.JsonNode',
|
|
'DestinationDefinitionSpecification': 'com.fasterxml.jackson.databind.JsonNode',
|
|
'DestinationConfiguration' : 'com.fasterxml.jackson.databind.JsonNode',
|
|
'StreamJsonSchema' : 'com.fasterxml.jackson.databind.JsonNode',
|
|
'StateBlob' : 'com.fasterxml.jackson.databind.JsonNode',
|
|
'FieldSchema' : 'com.fasterxml.jackson.databind.JsonNode',
|
|
]
|
|
|
|
library = "native"
|
|
|
|
generateApiDocumentation = false
|
|
|
|
configOptions = [
|
|
dateLibrary : "java8",
|
|
generatePom : "false",
|
|
interfaceOnly: "true"
|
|
]
|
|
}
|
|
compileJava.dependsOn tasks.generateApiClient
|
|
|
|
task generateApiDocs(type: GenerateTask) {
|
|
def docsOutputDir = "$buildDir/generated/api/docs"
|
|
|
|
generatorName = "html"
|
|
inputSpec = specFile
|
|
outputDir = docsOutputDir
|
|
|
|
apiPackage = "io.airbyte.api.client.generated"
|
|
invokerPackage = "io.airbyte.api.client.invoker.generated"
|
|
modelPackage = "io.airbyte.api.client.model.generated"
|
|
|
|
schemaMappings = [
|
|
'OAuthConfiguration' : 'com.fasterxml.jackson.databind.JsonNode',
|
|
'SourceDefinitionSpecification' : 'com.fasterxml.jackson.databind.JsonNode',
|
|
'SourceConfiguration' : 'com.fasterxml.jackson.databind.JsonNode',
|
|
'DestinationDefinitionSpecification': 'com.fasterxml.jackson.databind.JsonNode',
|
|
'DestinationConfiguration' : 'com.fasterxml.jackson.databind.JsonNode',
|
|
'StreamJsonSchema' : 'com.fasterxml.jackson.databind.JsonNode',
|
|
'StateBlob' : 'com.fasterxml.jackson.databind.JsonNode',
|
|
'FieldSchema' : 'com.fasterxml.jackson.databind.JsonNode',
|
|
]
|
|
|
|
generateApiDocumentation = false
|
|
|
|
configOptions = [
|
|
dateLibrary : "java8",
|
|
generatePom : "false",
|
|
interfaceOnly: "true"
|
|
]
|
|
|
|
doLast {
|
|
def target = file(rootProject.file("docs/reference/api/generated-api-html"))
|
|
delete target
|
|
mkdir target
|
|
copy {
|
|
from outputDir
|
|
include "**/*.html"
|
|
includeEmptyDirs = false
|
|
into target
|
|
}
|
|
}
|
|
}
|
|
compileJava.dependsOn tasks.generateApiDocs
|
|
|
|
dependencies {
|
|
implementation group: 'com.fasterxml.jackson.datatype', name: 'jackson-datatype-jsr310'
|
|
|
|
implementation group: 'io.swagger', name: 'swagger-annotations', version: '1.6.2'
|
|
|
|
implementation group: 'javax.annotation', name: 'javax.annotation-api', version: '1.3.2'
|
|
implementation group: 'javax.ws.rs', name: 'javax.ws.rs-api', version: '2.1.1'
|
|
implementation group: 'javax.validation', name: 'validation-api', version: '2.0.1.Final'
|
|
|
|
implementation group: 'org.openapitools', name: 'jackson-databind-nullable', version: '0.2.1'
|
|
}
|
|
|
|
sourceSets {
|
|
main {
|
|
java {
|
|
srcDirs "$buildDir/generated/api/server/src/gen/java", "$buildDir/generated/api/client/src/main/java", "$projectDir/src/main/java"
|
|
}
|
|
resources {
|
|
srcDir "$projectDir/src/main/openapi/"
|
|
}
|
|
}
|
|
}
|
|
|
|
Task publishArtifactsTask = getPublishArtifactsTask("$rootProject.ext.version", project)
|