Skip to content

Commit

Permalink
chore(deps): Bump com.github.gantsign.maven:ktlint-maven-plugin from …
Browse files Browse the repository at this point in the history
…2.0.0 to 3.0.0 in /generator (#66)

PR: #66
  • Loading branch information
dependabot[bot] authored Oct 3, 2023
1 parent 5187ef0 commit 5ff074d
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 109 deletions.
2 changes: 1 addition & 1 deletion generator/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@

<!-- Plugin Versions -->
<exec-maven-plugin.version>3.1.0</exec-maven-plugin.version>
<ktlint-plugin.version>2.0.0</ktlint-plugin.version>
<ktlint-plugin.version>3.0.0</ktlint-plugin.version>
<maven-compiler-plugin.version>3.11.0</maven-compiler-plugin.version>
<maven-jar-plugin.version>3.3.0</maven-jar-plugin.version>
<maven-resources-plugin.version>3.3.1</maven-resources-plugin.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,72 +21,73 @@ import org.openapitools.codegen.CodegenProperty
import org.openapitools.codegen.CodegenResponse
import org.openapitools.codegen.model.OperationsMap

val mustacheHelpers = mapOf(
"removeLeadingSlash" to {
Mustache.Lambda { fragment, writer -> writer.write(fragment.execute().removePrefix("/")) }
},
"processMapperType" to {
Mustache.Lambda { fragment, writer ->
val codegenProperty: CodegenProperty = fragment.context() as CodegenProperty
if (codegenProperty.dataType == Constant.ERROR) {
writer.write("ModelErrorMapper")
} else {
writer.write(fragment.execute())
val mustacheHelpers =
mapOf(
"removeLeadingSlash" to {
Mustache.Lambda { fragment, writer -> writer.write(fragment.execute().removePrefix("/")) }
},
"processMapperType" to {
Mustache.Lambda { fragment, writer ->
val codegenProperty: CodegenProperty = fragment.context() as CodegenProperty
if (codegenProperty.dataType == Constant.ERROR) {
writer.write("ModelErrorMapper")
} else {
writer.write(fragment.execute())
}
}
}
},
"processErrorType" to {
Mustache.Lambda { fragment, writer ->
val response: CodegenResponse = fragment.context() as CodegenResponse
writer.write(if (response.dataType == Constant.ERROR) Constant.MODEL_ERROR else fragment.execute())
}
},
"assignDiscriminators" to {
Mustache.Lambda { fragment, writer ->
val model = fragment.context() as CodegenModel
getParentDiscriminator(model)?.let {
writer.write("@JsonProperty(\"${it.originalName}\")\n")
writer.write("readonly ${it.name} = '${it.value}'\n")
},
"processErrorType" to {
Mustache.Lambda { fragment, writer ->
val response: CodegenResponse = fragment.context() as CodegenResponse
writer.write(if (response.dataType == Constant.ERROR) Constant.MODEL_ERROR else fragment.execute())
}
}
},
"isNotDiscriminator" to {
Mustache.Lambda { fragment, writer ->
val discriminators: List<String> = getDiscriminators(fragment.context(1) as CodegenModel)
val property: CodegenProperty = fragment.context() as CodegenProperty
if (!discriminators.contains(property.baseName)) {
writer.write(fragment.execute())
},
"assignDiscriminators" to {
Mustache.Lambda { fragment, writer ->
val model = fragment.context() as CodegenModel
getParentDiscriminator(model)?.let {
writer.write("@JsonProperty(\"${it.originalName}\")\n")
writer.write("readonly ${it.name} = '${it.value}'\n")
}
}
}
},
"callSuperConstructor" to {
Mustache.Lambda { fragment, writer ->
val model: CodegenModel = fragment.context() as CodegenModel
model.parentModel?.let {
val discriminators: MutableList<String> = getDiscriminators(model)
writer.write("super({\n")
it.allVars.filterNot { variable ->
variable.isDiscriminator || discriminators.contains(variable.baseName)
}.forEach { variable ->
writer.write("${variable.name}: ${model.classVarName}.${variable.name},\n")
},
"isNotDiscriminator" to {
Mustache.Lambda { fragment, writer ->
val discriminators: List<String> = getDiscriminators(fragment.context(1) as CodegenModel)
val property: CodegenProperty = fragment.context() as CodegenProperty
if (!discriminators.contains(property.baseName)) {
writer.write(fragment.execute())
}
}
},
"callSuperConstructor" to {
Mustache.Lambda { fragment, writer ->
val model: CodegenModel = fragment.context() as CodegenModel
model.parentModel?.let {
val discriminators: MutableList<String> = getDiscriminators(model)
writer.write("super({\n")
it.allVars.filterNot { variable ->
variable.isDiscriminator || discriminators.contains(variable.baseName)
}.forEach { variable ->
writer.write("${variable.name}: ${model.classVarName}.${variable.name},\n")
}
writer.write("})")
}
writer.write("})")
}
}
},
"defineApiExceptions" to {
Mustache.Lambda { fragment, writer ->
val dataTypes: MutableSet<String> = mutableSetOf()
val operationsMap: OperationsMap = fragment.context() as OperationsMap
operationsMap.operations.operation.forEach { operation ->
operation.responses.forEach { response ->
response.takeIf { !it.is2xx }?.dataType?.let { if (it == Constant.ERROR) Constant.MODEL_ERROR else it }?.takeIf { !dataTypes.contains(it) }?.also {
writer.write("export class ExpediaGroupApi$it extends ExpediaGroupApiError ")
writer.write("{constructor(readonly statusCode: number, readonly errorObject: $it) {super(statusCode, errorObject);}}\n")
dataTypes.add(it)
},
"defineApiExceptions" to {
Mustache.Lambda { fragment, writer ->
val dataTypes: MutableSet<String> = mutableSetOf()
val operationsMap: OperationsMap = fragment.context() as OperationsMap
operationsMap.operations.operation.forEach { operation ->
operation.responses.forEach { response ->
response.takeIf { !it.is2xx }?.dataType?.let { if (it == Constant.ERROR) Constant.MODEL_ERROR else it }?.takeIf { !dataTypes.contains(it) }?.also {
writer.write("export class ExpediaGroupApi$it extends ExpediaGroupApiError ")
writer.write("{constructor(readonly statusCode: number, readonly errorObject: $it) {super(statusCode, errorObject);}}\n")
dataTypes.add(it)
}
}
}
}
}
},
)
},
)
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,18 @@ import org.openapitools.codegen.config.CodegenConfigurator
*/
@Command(name = "generate", description = "Let's build an EG Travel SDK!")
class OpenApiSdkGenerator {
private val supportingFiles = listOf(
"ApiError.ts",
"client/index.ts",
"models/index.ts",
"tsconfig.json",
"typedoc.json",
"package.json",
".prettierrc",
"index.ts",
"README.md",
)
private val supportingFiles =
listOf(
"ApiError.ts",
"client/index.ts",
"models/index.ts",
"tsconfig.json",
"typedoc.json",
"package.json",
".prettierrc",
"index.ts",
"README.md",
)

companion object {
/**
Expand Down Expand Up @@ -70,46 +71,48 @@ class OpenApiSdkGenerator {
fun run() {
try {
val lowercaseNamespace: String = namespace.replace(Constant.NON_ALPHANUMERIC_REGEX, Constant.EMPTY_STRING).lowercase()
val config = CodegenConfigurator().apply {
setGeneratorName("typescript")
setTemplateDir("templates/expediagroup-sdk")
setInputSpec(inputFile)
setOutputDir(outputDirectory)
setArtifactVersion(version)
setArtifactId("expediagroup-nodejs-sdk-$lowercaseNamespace")
setModelPackage("models")
setApiPackage("client")
setApiNameSuffix("Client")
val config =
CodegenConfigurator().apply {
setGeneratorName("typescript")
setTemplateDir("templates/expediagroup-sdk")
setInputSpec(inputFile)
setOutputDir(outputDirectory)
setArtifactVersion(version)
setArtifactId("expediagroup-nodejs-sdk-$lowercaseNamespace")
setModelPackage("models")
setApiPackage("client")
setApiNameSuffix("Client")

addGlobalProperty(CodegenConstants.APIS, "")
addGlobalProperty(CodegenConstants.MODELS, "")
addGlobalProperty(CodegenConstants.SUPPORTING_FILES, supportingFiles.joinToString(","))
addGlobalProperty(CodegenConstants.APIS, "")
addGlobalProperty(CodegenConstants.MODELS, "")
addGlobalProperty(CodegenConstants.SUPPORTING_FILES, supportingFiles.joinToString(","))

addAdditionalProperty(CodegenConstants.ENUM_PROPERTY_NAMING, "UPPERCASE")
addAdditionalProperty(CodegenConstants.SORT_PARAMS_BY_REQUIRED_FLAG, true)
addAdditionalProperty(CodegenConstants.ENUM_PROPERTY_NAMING, "UPPERCASE")
addAdditionalProperty(CodegenConstants.SORT_PARAMS_BY_REQUIRED_FLAG, true)

// Template specific properties
addAdditionalProperty("namespace", lowercaseNamespace)
// Template specific properties
addAdditionalProperty("namespace", lowercaseNamespace)

// Mustache Helpers
mustacheHelpers.forEach { (name, function) -> addAdditionalProperty(name, function()) }
}
val generatorInput = config.toClientOptInput().apply {
userDefinedTemplates(
listOf(
ModelTemplate("model/modelMapper.mustache", "Mapper.ts"),
SupportingFile("error/apiError.mustache", "models/error/", "ApiError.ts"),
SupportingFile("package.mustache", "package.json"),
SupportingFile("typedoc.mustache", "typedoc.json"),
SupportingFile("tsconfig.mustache", "tsconfig.json"),
SupportingFile("prettierrc.mustache", ".prettierrc"),
SupportingFile("index.mustache", "index.ts"),
SupportingFile("api/index.mustache", "client/index.ts"),
SupportingFile("model/index.mustache", "models/index.ts"),
SupportingFile("README.mustache", "README.md"),
),
)
}
// Mustache Helpers
mustacheHelpers.forEach { (name, function) -> addAdditionalProperty(name, function()) }
}
val generatorInput =
config.toClientOptInput().apply {
userDefinedTemplates(
listOf(
ModelTemplate("model/modelMapper.mustache", "Mapper.ts"),
SupportingFile("error/apiError.mustache", "models/error/", "ApiError.ts"),
SupportingFile("package.mustache", "package.json"),
SupportingFile("typedoc.mustache", "typedoc.json"),
SupportingFile("tsconfig.mustache", "tsconfig.json"),
SupportingFile("prettierrc.mustache", ".prettierrc"),
SupportingFile("index.mustache", "index.ts"),
SupportingFile("api/index.mustache", "client/index.ts"),
SupportingFile("model/index.mustache", "models/index.ts"),
SupportingFile("README.mustache", "README.md"),
),
)
}

val generator = DefaultGenerator(false).apply { opts(generatorInput) }
generator.generate()
Expand Down

0 comments on commit 5ff074d

Please sign in to comment.