| 1 | /* |
| 2 | * Copyright (c) 2024 sovity GmbH |
| 3 | * |
| 4 | * This program and the accompanying materials are made available under the |
| 5 | * terms of the Apache License, Version 2.0 which is available at |
| 6 | * https://www.apache.org/licenses/LICENSE-2.0 |
| 7 | * |
| 8 | * SPDX-License-Identifier: Apache-2.0 |
| 9 | * |
| 10 | * Contributors: |
| 11 | * sovity GmbH - initial implementation |
| 12 | */ |
| 13 | |
| 14 | plugins { |
| 15 | `java-library` |
| 16 | alias(libs.plugins.openapiYamlGen) // ./gradlew clean resolve |
| 17 | alias(libs.plugins.openapiCodegen) // ./gradlew openApiValidate && ./gradlew openApiGenerate |
| 18 | } |
| 19 | |
| 20 | dependencies { |
| 21 | annotationProcessor(libs.lombok) |
| 22 | compileOnly(libs.lombok) |
| 23 | |
| 24 | api(libs.jakarta.wsRsApi) |
| 25 | api(libs.jakarta.validation) |
| 26 | api(libs.swaggerCore.annotations) |
| 27 | api(libs.sovity.edc.wrapperCommonApi) { isChanging = libs.sovity.edc.wrapperCommonApi.get().version?.endsWith("SNAPSHOT") ?: false } |
| 28 | |
| 29 | implementation(libs.swaggerCore.jaxrs2) |
| 30 | implementation(libs.jakarta.servletApi) |
| 31 | } |
| 32 | |
| 33 | val openapiFileDir = project.layout.buildDirectory.get().asFile.toString() |
| 34 | val openapiFileFilename = "authority-portal.yaml" |
| 35 | val openapiFile = "$openapiFileDir/$openapiFileFilename" |
| 36 | |
| 37 | var typescriptClientOutput = "../authority-portal-api-client-ts/src/generated" |
| 38 | |
| 39 | tasks.withType<io.swagger.v3.plugins.gradle.tasks.ResolveTask> { |
| 40 | outputDir = file(openapiFileDir) |
| 41 | outputFileName = openapiFileFilename.removeSuffix(".yaml") |
| 42 | prettyPrint = true |
| 43 | outputFormat = io.swagger.v3.plugins.gradle.tasks.ResolveTask.Format.YAML |
| 44 | classpath = sourceSets["main"].runtimeClasspath |
| 45 | } |
| 46 | |
| 47 | task<org.openapitools.generator.gradle.plugin.tasks.GenerateTask>("openApiGenerateTypeScriptClient") { |
| 48 | validateSpec.set(false) |
| 49 | dependsOn("resolve") |
| 50 | generatorName.set("typescript-fetch") |
| 51 | configOptions.set(mutableMapOf( |
| 52 | "supportsES6" to "true", |
| 53 | "npmVersion" to libs.versions.npmVersion.get(), |
| 54 | "typescriptThreePlus" to "true", |
| 55 | )) |
| 56 | |
| 57 | inputSpec.set(openapiFile) |
| 58 | val outputDirectory = buildFile.parentFile.resolve(typescriptClientOutput).normalize() |
| 59 | outputDir.set(outputDirectory.toString()) |
| 60 | |
| 61 | doFirst { |
| 62 | project.delete(fileTree(outputDirectory).exclude("**/.gitignore")) |
| 63 | } |
| 64 | |
| 65 | doLast { |
| 66 | outputDirectory.resolve("src/generated").renameTo(outputDirectory) |
| 67 | project.delete(fileTree(outputDirectory).include( |
| 68 | ".openapi-generator", |
| 69 | ".openapi-generator-ignore" |
| 70 | )) |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | tasks.withType<org.gradle.jvm.tasks.Jar> { |
| 75 | dependsOn("resolve") |
| 76 | dependsOn("openApiGenerateTypeScriptClient") |
| 77 | from(openapiFileDir) { |
| 78 | include(openapiFileFilename) |
| 79 | } |
| 80 | } |