-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
extract codegen cli as separate module
- Loading branch information
Showing
11 changed files
with
136 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,35 @@ | ||
name: Test | ||
name: Build the Distribution | ||
|
||
on: [push] | ||
on: | ||
push: | ||
branches: [ master ] | ||
pull_request: | ||
branches: [ master ] | ||
|
||
jobs: | ||
build: | ||
|
||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v1 | ||
- name: Set up JDK | ||
uses: actions/[email protected] | ||
with: | ||
java-version: 11 | ||
- name: Build with Gradle | ||
run: ./gradlew test | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
|
||
- name: Set up JDK 11 | ||
uses: actions/setup-java@v1 | ||
with: | ||
java-version: 11 | ||
|
||
- name: Grant execute permission for gradlew | ||
run: chmod +x gradlew | ||
|
||
- name: Build with Gradle | ||
run: gradle clean build | ||
|
||
- name: Dist | ||
run: gradle cli:distZip | ||
|
||
- name: Upload binary | ||
uses: actions/upload-artifact@v2 | ||
with: | ||
name: apifi-codegen | ||
path: cli/build/distributions/apifi-codegen.zip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package apifi.cli | ||
|
||
import apifi.codegen.CodegenIO | ||
import com.github.ajalt.clikt.core.CliktCommand | ||
import com.github.ajalt.clikt.parameters.options.option | ||
import com.github.ajalt.clikt.parameters.options.required | ||
import com.github.ajalt.clikt.parameters.types.file | ||
|
||
|
||
/** | ||
* Entry point - The main function | ||
*/ | ||
fun main(args: Array<String>) = ApifiCli().main(args) | ||
|
||
|
||
/** | ||
* Implementation of CLI using Apifi API | ||
* | ||
* Can use env variable to pass in sensitive information | ||
*/ | ||
class ApifiCli : CliktCommand( // command name is inferred as apifi-cli | ||
name = "apifi-codegen", | ||
help = """ | ||
Generates Kotlin Source files for given Open API Spec file | ||
""" | ||
) { | ||
private val inputFile by option("-f", "--input-file", help = "Open API Spec file that is entry point, this file can refer to another yaml files") | ||
.file(canBeFile = true, canBeDir = false, mustExist = true) | ||
.required() | ||
|
||
private val outDir by option("-o", "--out-dir", help = "Output dir where source should be generated") | ||
.file(canBeFile = false, canBeDir = true, mustExist = true) | ||
.required() | ||
|
||
private val basePackage by option("-p", "--base-package", help = "package name for generated classes") | ||
.required() | ||
|
||
|
||
override fun run() { | ||
CodegenIO().execute(inputFile, outDir, basePackage) | ||
} | ||
} | ||
|
||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package apifi.codegen | ||
|
||
import apifi.parser.OpenApiSpecReader | ||
import io.swagger.v3.parser.OpenAPIV3Parser | ||
import java.io.File | ||
|
||
|
||
class CodegenIO { | ||
private val openAPIV3Parser = OpenAPIV3Parser() | ||
private val openApiSpecReader = OpenApiSpecReader() | ||
private val codeGenerator = CodeGenerator() | ||
|
||
fun execute(specFile: File, outputDir: File, basePackageName: String) { | ||
outputDir.mkdirs() | ||
|
||
if (!specFile.isFile || !outputDir.isDirectory) { | ||
throw Exception("invalid spec file or output directory") | ||
} | ||
|
||
val openApi = openAPIV3Parser.read(specFile.absolutePath) | ||
val spec = openApiSpecReader.read(openApi) | ||
val fileSpecs = codeGenerator.generate(spec, "$basePackageName.${specFile.nameWithoutExtension}") | ||
|
||
fileSpecs.forEach { fileSpec -> | ||
val outFileParentDir = File(outputDir, fileSpec.packageName.replace(".", File.separator)) | ||
outFileParentDir.mkdirs() | ||
File(outFileParentDir, fileSpec.name).writeText(fileSpec.toString()) | ||
} | ||
} | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
rootProject.name = 'apifi' | ||
include 'codegen' | ||
include 'codegen' | ||
include 'cli' | ||
include 'runtime' |