Elffuss BraidHub

kikocis/dataspace-portal public

main · 2.5 KiBRawPermalink
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
14plugins {
15 `java-library`
16 alias(libs.plugins.openapiYamlGen) // ./gradlew clean resolve
17 alias(libs.plugins.openapiCodegen) // ./gradlew openApiValidate && ./gradlew openApiGenerate
18}
19
20dependencies {
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
33val openapiFileDir = project.layout.buildDirectory.get().asFile.toString()
34val openapiFileFilename = "authority-portal.yaml"
35val openapiFile = "$openapiFileDir/$openapiFileFilename"
36
37var typescriptClientOutput = "../authority-portal-api-client-ts/src/generated"
38
39tasks.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
47task<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
74tasks.withType<org.gradle.jvm.tasks.Jar> {
75 dependsOn("resolve")
76 dependsOn("openApiGenerateTypeScriptClient")
77 from(openapiFileDir) {
78 include(openapiFileFilename)
79 }
80}