Skip to content

Commit 2e25488

Browse files
authored
chore: initial generator config (#126)
PR: #126
1 parent 457f3b8 commit 2e25488

File tree

52 files changed

+4294
-1
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+4294
-1
lines changed

LICENSE-HEADER.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Copyright (C) 2025 Expedia, Inc.
2+
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
13+
limitations under the License.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.expediagroup.sdk.xap.generator.mustache
2+
3+
import com.samskivert.mustache.Mustache
4+
import com.samskivert.mustache.Template
5+
import java.io.Serializable
6+
import java.io.Writer
7+
import org.openapitools.codegen.CodegenResponse
8+
9+
class AllowedMediaTypesLambda : Mustache.Lambda, Serializable {
10+
override fun execute(
11+
fragment: Template.Fragment,
12+
writer: Writer,
13+
) {
14+
val response: CodegenResponse = fragment.context() as CodegenResponse
15+
if (response.is2xx) {
16+
val mediaTypes: List<String> =
17+
response.content.keys.filter {
18+
!it.contains("xml", ignoreCase = true)
19+
}
20+
21+
val context = mapOf("mediaTypes" to mediaTypes)
22+
fragment.execute(context, writer)
23+
}
24+
}
25+
}

generator/build.gradle.kts

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,71 @@
1+
import com.expediagroup.sdk.xap.generator.mustache.AllowedMediaTypesLambda
2+
import org.openapitools.codegen.CodegenConstants
3+
14
plugins {
25
id("com.expediagroup.sdk.openapigenerator") version "0.0.9-alpha"
6+
id("com.github.hierynomus.license-base") version "0.16.1"
37
}
48

59
group = project.property("GROUP_ID") as String
610

711
dependencies {
812
api("org.openapitools:openapi-generator:7.11.0")
913
}
14+
15+
openApiGenerate {
16+
inputSpec = System.getProperty("inputSpec") ?: "$projectDir/src/main/resources/transformedSpecs.yaml"
17+
18+
packageName = "com.expediagroup.sdk.xap"
19+
invokerPackage = "com.expediagroup.sdk.xap"
20+
apiPackage = "com.expediagroup.sdk.xap.operations"
21+
modelPackage = "com.expediagroup.sdk.xap.models"
22+
23+
dryRun = false
24+
cleanupOutput = false
25+
generateApiDocumentation = false
26+
generateApiTests = false
27+
generateModelTests = false
28+
enablePostProcessFile = true
29+
30+
templateDir = "$projectDir/src/main/resources/templates"
31+
configFile = "$projectDir/src/main/resources/generator-config.yaml"
32+
outputDir = "$rootDir/xap-sdk/src/main/kotlin"
33+
34+
additionalProperties.put(CodegenConstants.ENUM_PROPERTY_NAMING, "UPPERCASE")
35+
additionalProperties.put("allowedMediaTypes", AllowedMediaTypesLambda())
36+
37+
configOptions.put("sourceFolder", "")
38+
39+
globalProperties.put("supportingFiles", "Room.kt")
40+
}
41+
42+
license {
43+
header = rootProject.file("LICENSE-HEADER.txt")
44+
skipExistingHeaders = true
45+
strictCheck = true
46+
includes(
47+
listOf(
48+
"$rootDir/xap-sdk/src/main/kotlin/**/*.kt"
49+
)
50+
)
51+
}
52+
53+
tasks.named("openApiGenerate").configure {
54+
doLast {
55+
// Format code
56+
project.providers.exec {
57+
commandLine(
58+
"../gradlew ktlintFormat".split(" "),
59+
)
60+
workingDir = File("$rootDir/xap-sdk").absoluteFile
61+
}
62+
63+
// Add license headers
64+
project.providers.exec {
65+
commandLine(
66+
"../gradlew licenseFormatMain".split(" "),
67+
)
68+
workingDir = File("$rootDir/xap-sdk").absoluteFile
69+
}
70+
}
71+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
files:
2+
operation_params.mustache:
3+
templateType: API
4+
destinationFilename: Params.kt
5+
room.mustache:
6+
templateType: SupportingFiles
7+
destinationFilename: Room.kt
8+
folder: com/expediagroup/sdk/xap/models
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
root = true
2+
3+
[*]
4+
indent_style = space
5+
indent_size = 2
6+
end_of_line = lf
7+
charset = utf-8
8+
insert_final_newline = true
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
build/
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": "./node_modules/gts/"
3+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
...require('gts/.prettierrc.json')
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
rule:
2+
kind: user_type
3+
inside:
4+
kind: parameter
5+
regex: freeCancellationEndDateTime
6+
stopBy:
7+
kind: class_declaration
8+
regex: Builder
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
rule:
2+
kind: user_type
3+
pattern: $TYPE
4+
inside:
5+
any:
6+
- kind: class_parameter
7+
regex: freeCancellationEndDateTime
8+
- kind: nullable_type
9+
inside:
10+
kind: class_parameter
11+
regex: freeCancellationEndDateTime

0 commit comments

Comments
 (0)