Skip to content

Commit

Permalink
OpenAPI 기반 스키마 생성 (#11)
Browse files Browse the repository at this point in the history
* docs: README

* feat: add schema generator

* feat: edit roadmap

* fix: ci

* fix: dokka

* docs: add javadoc badge

* docs: remove sourcelink

* feat: make PortOneApi properties private

* style: unused import
  • Loading branch information
finalchild authored Oct 11, 2024
1 parent d33a30c commit e27e0d8
Show file tree
Hide file tree
Showing 327 changed files with 67,988 additions and 28 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,18 @@ jobs:
- name: Checkout sources
uses: actions/checkout@v4

- name: Install git-filter-repo
uses: awalsh128/cache-apt-pkgs-action@latest
with:
packages: git-filter-repo
version: "1.0"

- name: Set github username
run: |
git config --global user.name runner
git config --global user.email "[email protected]"
git config --global init.defaultBranch main
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v4

Expand Down
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,11 @@

# Ignore Gradle build output directory
build
!common/build
common/build/**
!common/build/generated
common/build/generated/**
!common/build/generated/sources
common/build/generated/sources/**
!common/build/generated/sources/schemaCode
!common/build/generated/sources/schemaCode/**
48 changes: 43 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,47 @@
JVM 서버 환경에서 포트원 V2 결제 시스템에 연동하기 위한 SDK입니다. 코틀린, 스칼라, 자바 등의 언어에서 사용할 수 있습니다.


## 의존성
JVM 11 이상이 필요합니다.

현대적인 코틀린 환경을 사용해 구현합니다. 내부 HTTP 클라이언트로는 OkHttp 엔진의 Ktor를 사용합니다. JSON 직렬화를 위해 kotlinx.serialization을 사용합니다.


## 설치
[![Maven Central Version](https://img.shields.io/maven-central/v/io.portone/server-sdk)](https://central.sonatype.com/artifact/io.portone/server-sdk)
[![javadoc](https://javadoc.io/badge2/io.portone/server-sdk/javadoc.svg)](https://javadoc.io/doc/io.portone/server-sdk)

메이븐 중앙 저장소를 통해 설치합니다.

### 그래들
```Gradle Kotlin DSL
dependencies {
implementation("io.portone:server-sdk:x.y.z")
}
repositories {
mavenCentral()
}
```

### 메이븐
```XML
<dependencies>
<dependency>
<groupId>io.portone</groupId>
<artifactId>server-sdk</artifactId>
<version>x.y.z</version>
</dependency>
</dependencies>
```

### 앰퍼
```YAML
dependencies:
- io.portone:server-sdk:x.y.z
```
## 버전
[유의적 버전 2.0.0](https://semver.org/spec/v2.0.0.html)을 사용합니다.
Expand All @@ -13,13 +54,10 @@ JVM 서버 환경에서 포트원 V2 결제 시스템에 연동하기 위한 SDK
SDK의 버전을 업데이트한 경우 코드 호환성이 깨질 수 있습니다. 이 경우 코드 작업이 필요합니다.
## 의존성
현대적인 코틀린 환경을 사용합니다. 내부 HTTP 클라이언트로는 OkHttp 엔진의 Ktor를 사용합니다. JSON 직렬화를 위해 kotlinx.serialization을 사용합니다.


## 개발 로드맵
* [x] 웹훅 검증을 위한 `WebhookVerifier` 제공
* [ ] REST API 연동
* [x] REST API 연동
* [ ] 웹훅 스키마 생성

REST API 연동이 완료되어 SDK를 이용해 간편하게 결제 시스템에 연동할 수 있게 된 후 1.0.0을 릴리스할 예정입니다.

Expand Down
14 changes: 14 additions & 0 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
plugins {
kotlin("jvm") version "2.0.20"
kotlin("plugin.serialization") version "2.0.20"

}

dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.7.1")
implementation("com.squareup:kotlinpoet-jvm:1.18.1")
}

repositories {
mavenCentral()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package io.portone.openapi

import kotlinx.serialization.json.Json
import kotlinx.serialization.json.jsonObject
import org.gradle.api.DefaultTask
import org.gradle.api.file.DirectoryProperty
import org.gradle.api.file.RegularFileProperty
import org.gradle.api.tasks.InputFile
import org.gradle.api.tasks.OutputDirectory
import org.gradle.api.tasks.TaskAction
import java.nio.file.Files

abstract class GenerateSchemaCodeTask : DefaultTask() {
@get:InputFile
abstract val inputFile: RegularFileProperty

@get:OutputDirectory
abstract val outputDirectory: DirectoryProperty

@TaskAction
fun generateSchemaCode() {
val document = Json.parseToJsonElement(Files.readString(inputFile.get().asFile.toPath())).jsonObject
SchemaGenerator(document, listOf(
"/payments",
"/payment-schedules",
"/identity-verifications",
"/billing-keys",
"/cash-receipts",
"/kakaopay",
), outputDirectory.get().asFile.toPath()).generateFiles()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package io.portone.openapi

import com.squareup.kotlinpoet.FileSpec
import com.squareup.kotlinpoet.KModifier
import com.squareup.kotlinpoet.PropertySpec
import org.gradle.api.DefaultTask
import org.gradle.api.file.DirectoryProperty
import org.gradle.api.provider.Property
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.OutputDirectory
import org.gradle.api.tasks.TaskAction

abstract class GenerateVersionCodeTask : DefaultTask() {
@get:Input
abstract val version: Property<String>

@get:OutputDirectory
abstract val outputDirectory: DirectoryProperty

@TaskAction
fun generateVersionCode() {
val outputDirectory = this.outputDirectory.get().asFile.toPath()

FileSpec.builder("io.portone.sdk.server", "Version")
.addProperty(PropertySpec.builder("SDK_VERSION", String::class, KModifier.CONST, KModifier.INTERNAL).initializer("%S", version.get()).build())
.build().writeTo(outputDirectory)
}
}
90 changes: 90 additions & 0 deletions buildSrc/src/main/kotlin/io/portone/openapi/PatchCodeTask.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package io.portone.openapi

import org.gradle.api.DefaultTask
import org.gradle.api.file.DirectoryProperty
import org.gradle.api.tasks.InputDirectory
import org.gradle.api.tasks.OutputDirectory
import org.gradle.api.tasks.TaskAction
import java.io.ByteArrayOutputStream
import java.nio.file.Files
import kotlin.io.path.listDirectoryEntries
import kotlin.io.path.relativeTo

abstract class PatchCodeTask : DefaultTask() {
@get:InputDirectory
abstract val originDirectory: DirectoryProperty

@get:InputDirectory
abstract val patchesDirectory: DirectoryProperty

@get:OutputDirectory
abstract val outputDirectory: DirectoryProperty

companion object {
private const val TAG_NAME = "patch-base"
}

@TaskAction
fun patchCode() {
val originDirectory = this.originDirectory.get().asFile.toPath()
val patchesDirectory = this.patchesDirectory.get().asFile.toPath()
val outputDirectory = this.outputDirectory.get().asFile.toPath()

Files.createDirectories(outputDirectory)

project.exec {
it.workingDir = outputDirectory.toFile()
it.executable = "git"
it.args = listOf("init")
it.isIgnoreExitValue = true
}

project.exec {
it.workingDir = outputDirectory.toFile()
it.executable = "git"
it.args = listOf("config", "commit.gpgSign", "false")
}

project.exec {
it.workingDir = project.rootProject.projectDir
it.executable = "git"
it.args = listOf("tag", TAG_NAME)
}

project.exec {
it.workingDir = project.rootProject.projectDir
it.executable = "git"
// use joinToString("/") because git filter-repo doesn't support '\' (windows path separator) in filter
it.args = listOf("filter-repo", "--force", "--subdirectory-filter", originDirectory.relativeTo(project.rootProject.projectDir.toPath()).joinToString("/"), "--target", outputDirectory.toString())
}

project.exec {
it.workingDir = project.rootProject.projectDir
it.executable = "git"
it.args = listOf("tag", "-d", TAG_NAME)
}

project.exec {
it.workingDir = outputDirectory.toFile()
it.executable = "git"
it.args = listOf("checkout", TAG_NAME)
}

project.exec {
it.workingDir = outputDirectory.toFile()
it.executable = "git"
it.args = listOf("am", "--abort")
it.standardOutput = ByteArrayOutputStream()
it.errorOutput = ByteArrayOutputStream()
it.isIgnoreExitValue = true
}

val patchFiles = patchesDirectory.listDirectoryEntries("*.patch").sorted()

project.exec {
it.workingDir = outputDirectory.toFile()
it.executable = "git"
it.args = listOf("am", "--3way", *patchFiles.map { it.toString() }.toTypedArray())
}
}
}
36 changes: 36 additions & 0 deletions buildSrc/src/main/kotlin/io/portone/openapi/SavePatchTask.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package io.portone.openapi

import org.gradle.api.DefaultTask
import org.gradle.api.file.DirectoryProperty
import org.gradle.api.tasks.InputDirectory
import org.gradle.api.tasks.OutputDirectory
import org.gradle.api.tasks.TaskAction
import java.nio.file.Files

abstract class SavePatchTask : DefaultTask() {
@get:InputDirectory
abstract val inputDirectory: DirectoryProperty

@get:OutputDirectory
abstract val outputDirectory: DirectoryProperty


companion object {
private const val TAG_NAME = "patch-base"
}

@TaskAction
fun patchCode() {
val inputDirectory = this.inputDirectory.get().asFile.toPath()
val outputDirectory = this.outputDirectory.get().asFile.toPath()

Files.createDirectories(outputDirectory)

project.exec {
it.workingDir = inputDirectory.toFile()
it.executable = "git"
it.args = listOf("format-patch", "--zero-commit", "--no-stat", "--minimal", "-N", "-o", outputDirectory.toString(), TAG_NAME)
}

}
}
Loading

0 comments on commit e27e0d8

Please sign in to comment.