Skip to content

Commit

Permalink
chore: Deprecate Spec Processing Logic (#221)
Browse files Browse the repository at this point in the history
  • Loading branch information
mohnoor94 authored Jun 18, 2023
1 parent 8005566 commit c3df6f7
Show file tree
Hide file tree
Showing 18 changed files with 154 additions and 1,261 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/generator-verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
working-directory: generator/openapi
run: |
mvn clean install
mvn exec:java "-Dnamespace=exemplar" "-DsdkVersion=0.0.1-exemplar" "-Dspec=${{ secrets.SPEC_FILE }}"
mvn exec:java "-Dnamespace=exemplar" "-DsdkVersion=1.0.0" "-Dspec=./src/test/resources/exemplar.yaml"
- uses: actions/upload-artifact@v2
with:
name: sdk
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ internal fun getParentDiscriminator(model: CodegenModel): MutableList<Discrimina
}
return discriminators
}

internal data class Discriminator(
val originalName: String,
val name: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/
package com.expediagroup.openworld.sdk.generators.openapi

import com.expediagroup.openworld.sdk.generators.openapi.processor.YamlProcessor
import com.expediagroup.openworld.sdk.model.ClientGenerationException
import com.expediagroup.openworld.sdk.product.Product
import com.expediagroup.openworld.sdk.product.ProductFamily
Expand All @@ -27,13 +26,6 @@ import org.openapitools.codegen.CodegenConstants
import org.openapitools.codegen.DefaultGenerator
import org.openapitools.codegen.SupportingFile
import org.openapitools.codegen.config.CodegenConfigurator
import java.io.File
import java.io.FileInputStream
import java.io.FileOutputStream
import java.nio.file.Files
import java.util.Base64
import java.util.zip.ZipInputStream
import kotlin.io.path.writeBytes

/**
* Configures the OpenAPI Generator based on command line parameters to generate an EG Travel SDK project
Expand Down Expand Up @@ -81,12 +73,9 @@ class OpenApiSdkGenerator {
try {
val product = Product(namespace, programmingLanguage)
val config = CodegenConfigurator().apply {
val path = prepareSpecFile()
val processedFilePath = preProcessSpecFile(path)

setGeneratorName("kotlin")
setTemplateDir("templates/openworld-sdk")
setInputSpec(processedFilePath)
setInputSpec(inputFile)
setOutputDir(outputDirectory)
setArtifactId(product.artifactId)
setArtifactVersion(version)
Expand Down Expand Up @@ -147,30 +136,4 @@ class OpenApiSdkGenerator {
throw ClientGenerationException("Failed to generate SDK", e)
}
}

private fun preProcessSpecFile(path: String): String {
val yamlProcessor = YamlProcessor(path, namespace)
return yamlProcessor.process()
}

private fun prepareSpecFile(): String {
val buffer = ByteArray(1024)
val zipInputStream = ZipInputStream(FileInputStream(prepareTmpZipFile()))
val tempFile = Files.createTempFile("", zipInputStream.nextEntry?.name).toFile()
val fileOutputStream = FileOutputStream(tempFile)
var len: Int
while (zipInputStream.read(buffer).also { len = it } > 0) {
fileOutputStream.write(buffer, 0, len)
}
zipInputStream.closeEntry()
fileOutputStream.close()
zipInputStream.close()
return tempFile.absolutePath
}

private fun prepareTmpZipFile(): File {
val tmpFile = Files.createTempFile("", "tmp")
tmpFile.writeBytes(Base64.getDecoder().decode(inputFile))
return tmpFile.toFile()
}
}

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
package com.expediagroup.openworld.sdk.product

import com.expediagroup.openworld.sdk.generators.openapi.Constant
val NON_ALPHANUMERIC_REGEX = Regex("[^a-zA-Z0-9]")

class Product(
inputNamespace: String,
Expand All @@ -26,7 +26,7 @@ class Product(
ProgrammingLanguage.from(programmingLanguage)
)

val namespace: String = inputNamespace.replace(Constant.NON_ALPHANUMERIC_REGEX, "").lowercase()
val namespace: String = inputNamespace.replace(NON_ALPHANUMERIC_REGEX, "").lowercase()

val apiPackage: String
get() = "com.expediagroup.openworld.sdk.$namespace.client"
Expand Down
Loading

0 comments on commit c3df6f7

Please sign in to comment.