Skip to content

Commit

Permalink
[WEAV-15] Open API Generator 를 통한 네트워크 레이어 구축 (#5)
Browse files Browse the repository at this point in the history
* [WEAV-15] OAS Submodule Config, OAS Module Added.

* [WEAV-15] OAS 네트워크 레이어 구축, 일부 파일 scope 변경

* [WEAV-15] Middleware 생성

* [WEAV-15] network client middleware add, refresh token flow
  • Loading branch information
jisu15-kim authored Sep 8, 2024
1 parent 90f5e8d commit 75c6157
Show file tree
Hide file tree
Showing 29 changed files with 2,453 additions and 71 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "OpenApiGenerator/Sources/openapi-generator-cli/3days-oas"]
path = OpenApiGenerator/Sources/openapi-generator-cli/3days-oas
url = https://github.com/Student-Center/3days-oas.git
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
api:
$(MAKE) -C OpenApiGenerator generate

.PHONY: api
1 change: 1 addition & 0 deletions OpenApiGenerator/.swift-openapi-generator
Submodule .swift-openapi-generator added at 81ea61
86 changes: 86 additions & 0 deletions OpenApiGenerator/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# To see how to drive this makefile use:
#
# % make help

# The following values can be changed here, or passed on the command line.
SWIFT_OPENAPI_GENERATOR_GIT_URL ?= https://github.com/apple/swift-openapi-generator
SWIFT_OPENAPI_GENERATOR_GIT_TAG ?= 1.0.0
SWIFT_OPENAPI_GENERATOR_CLONE_DIR ?= $(CURRENT_MAKEFILE_DIR)/.swift-openapi-generator
SWIFT_OPENAPI_GENERATOR_BUILD_CONFIGURATION ?= debug
OPENAPI_YAML_PATH ?= $(CURRENT_MAKEFILE_DIR)/Sources/openapi-generator-cli/3days-oas/openapi.yaml
OPENAPI_GENERATOR_CONFIG_PATH ?= $(CURRENT_MAKEFILE_DIR)/Sources/openapi-generator-cli/openapi-generator-config.yaml
OUTPUT_DIRECTORY ?= $(CURRENT_MAKEFILE_DIR)/Sources/OpenapiGenerated

# Derived values (don't change these).
CURRENT_MAKEFILE_PATH := $(abspath $(lastword $(MAKEFILE_LIST)))
CURRENT_MAKEFILE_DIR := $(patsubst %/,%,$(dir $(CURRENT_MAKEFILE_PATH)))
SWIFT_OPENAPI_GENERATOR_BIN := $(SWIFT_OPENAPI_GENERATOR_CLONE_DIR)/.build/$(SWIFT_OPENAPI_GENERATOR_BUILD_CONFIGURATION)/swift-openapi-generator

# If no target is specified, display help
.DEFAULT_GOAL := help

help: # Display this help.
@-+echo "Run make with one of the following targets:"
@-+echo
@-+grep -Eh "^[a-z-]+:.*#" $(CURRENT_MAKEFILE_PATH) | sed -E 's/^(.*:)(.*#+)(.*)/ \1 @@@ \3 /' | column -t -s "@@@"
@-+echo
@-+echo "The following options can be overriden on the command line:"
@-+echo
@-+echo " SWIFT_OPENAPI_GENERATOR_GIT_URL (e.g. https://github.com/apple/swift-openapi-generator)"
@-+echo " SWIFT_OPENAPI_GENERATOR_GIT_TAG (e.g. 1.0.0)"
@-+echo " SWIFT_OPENAPI_GENERATOR_CLONE_DIR (e.g. .swift-openapi-generator)"
@-+echo " SWIFT_OPENAPI_GENERATOR_BUILD_CONFIGURATION (e.g. release)"
@-+echo " OPENAPI_YAML_PATH (e.g. openapi.yaml)"
@-+echo " OPENAPI_GENERATOR_CONFIG_PATH (e.g. openapi-generator-config.yaml)"
@-+echo " OUTPUT_DIRECTORY (e.g. Sources/ManualGeneratorInvocationClient/Generated)"

generate: $(SWIFT_OPENAPI_GENERATOR_BIN) $(OPENAPI_YAML_PATH) $(OPENAPI_GENERATOR_CONFIG_PATH) $(OUTPUT_DIRECTORY) # Generate the sources using swift-openapi-generator.
$< generate \
--config "$(OPENAPI_GENERATOR_CONFIG_PATH)" \
--output-directory "$(OUTPUT_DIRECTORY)" \
"$(OPENAPI_YAML_PATH)"

build: # Runs swift build.
swift build

clean: # Delete the output directory used for generated sources.
@echo 'Delete entire directory: $(OUTPUT_DIRECTORY)? [y/N] ' && read ans && [ $${ans:-N} = y ] || (echo "Aborted"; exit 1)
rm -rf "$(OUTPUT_DIRECTORY)"

clean-all: clean # Clean everything, including the checkout of swift-openapi-generator.
@echo 'Delete checkout of swift-openapi-generator $(SWIFT_OPENAPI_GENERATOR_CLONE_DIR)? [y/N] ' && read ans && [ $${ans:-N} = y ] || (echo "Aborted"; exit 1)
rm -rf "$(SWIFT_OPENAPI_GENERATOR_CLONE_DIR)"


dump: # Dump all derived values used by the Makefile.
@echo "CURRENT_MAKEFILE_PATH = $(CURRENT_MAKEFILE_PATH)"
@echo "CURRENT_MAKEFILE_DIR = $(CURRENT_MAKEFILE_DIR)"
@echo "SWIFT_OPENAPI_GENERATOR_GIT_URL = $(SWIFT_OPENAPI_GENERATOR_GIT_URL)"
@echo "SWIFT_OPENAPI_GENERATOR_GIT_TAG = $(SWIFT_OPENAPI_GENERATOR_GIT_TAG)"
@echo "SWIFT_OPENAPI_GENERATOR_CLONE_DIR = $(SWIFT_OPENAPI_GENERATOR_CLONE_DIR)"
@echo "SWIFT_OPENAPI_GENERATOR_BUILD_CONFIGURATION = $(SWIFT_OPENAPI_GENERATOR_BUILD_CONFIGURATION)"
@echo "SWIFT_OPENAPI_GENERATOR_BIN = $(SWIFT_OPENAPI_GENERATOR_BIN)"
@echo "OPENAPI_YAML_PATH = $(OPENAPI_YAML_PATH)"
@echo "OPENAPI_GENERATOR_CONFIG_PATH = $(OPENAPI_GENERATOR_CONFIG_PATH)"
@echo "OUTPUT_DIRECTORY = $(OUTPUT_DIRECTORY)"

$(SWIFT_OPENAPI_GENERATOR_CLONE_DIR):
git \
-c advice.detachedHead=false \
clone \
--branch "$(SWIFT_OPENAPI_GENERATOR_GIT_TAG)" \
--depth 1 \
"$(SWIFT_OPENAPI_GENERATOR_GIT_URL)" \
$@

$(SWIFT_OPENAPI_GENERATOR_BIN): $(SWIFT_OPENAPI_GENERATOR_CLONE_DIR)
swift \
build \
--package-path "$(SWIFT_OPENAPI_GENERATOR_CLONE_DIR)" \
--configuration "$(SWIFT_OPENAPI_GENERATOR_BUILD_CONFIGURATION)" \
--product swift-openapi-generator

$(OUTPUT_DIRECTORY):
mkdir -p "$@"

.PHONY: help generate build clean clean-all dump
96 changes: 96 additions & 0 deletions OpenApiGenerator/Package.resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
{
"originHash" : "257f13f9f6c7356bd444df4a683c88a4dc97d3371ee8cb84757aa32c29c3ca50",
"pins" : [
{
"identity" : "openapikit",
"kind" : "remoteSourceControl",
"location" : "https://github.com/mattpolzin/OpenAPIKit",
"state" : {
"revision" : "4991b7e39a19cd1d0d11fe24fc64a601b4820144",
"version" : "3.2.0"
}
},
{
"identity" : "swift-algorithms",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-algorithms",
"state" : {
"revision" : "f6919dfc309e7f1b56224378b11e28bab5bccc42",
"version" : "1.2.0"
}
},
{
"identity" : "swift-argument-parser",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-argument-parser",
"state" : {
"revision" : "41982a3656a71c768319979febd796c6fd111d5c",
"version" : "1.5.0"
}
},
{
"identity" : "swift-collections",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-collections",
"state" : {
"revision" : "9bf03ff58ce34478e66aaee630e491823326fd06",
"version" : "1.1.3"
}
},
{
"identity" : "swift-http-types",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-http-types",
"state" : {
"revision" : "ae67c8178eb46944fd85e4dc6dd970e1f3ed6ccd",
"version" : "1.3.0"
}
},
{
"identity" : "swift-numerics",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-numerics.git",
"state" : {
"revision" : "0a5bc04095a675662cf24757cc0640aa2204253b",
"version" : "1.0.2"
}
},
{
"identity" : "swift-openapi-generator",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-openapi-generator",
"state" : {
"revision" : "99859083e53912612b56b4b8713a971c20dab3ef",
"version" : "1.3.0"
}
},
{
"identity" : "swift-openapi-runtime",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-openapi-runtime",
"state" : {
"revision" : "26e8ae3515d1ff3607e924ac96fc0094775f55e8",
"version" : "1.5.0"
}
},
{
"identity" : "swift-openapi-urlsession",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-openapi-urlsession",
"state" : {
"revision" : "9bf4c712ad7989d6a91dbe68748b8829a50837e4",
"version" : "1.0.2"
}
},
{
"identity" : "yams",
"kind" : "remoteSourceControl",
"location" : "https://github.com/jpsim/Yams",
"state" : {
"revision" : "3036ba9d69cf1fd04d433527bc339dc0dc75433d",
"version" : "5.1.3"
}
}
],
"version" : 3
}
36 changes: 36 additions & 0 deletions OpenApiGenerator/Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// swift-tools-version: 5.10
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
name: "OpenapiGenerator",
platforms: [.macOS(.v10_15), .iOS(.v13), .tvOS(.v13), .watchOS(.v6)],
products: [
.library(
name: "OpenapiGenerated",
targets: ["OpenapiGenerated"]
),
],
dependencies: [
.package(url: "https://github.com/apple/swift-openapi-generator", from: "1.0.0"),
.package(url: "https://github.com/apple/swift-openapi-runtime", from: "1.0.0"),
.package(url: "https://github.com/apple/swift-openapi-urlsession", from: "1.0.0"),
],
targets: [
.executableTarget(
name: "openapi-generator-cli",
dependencies: [
.product(name: "OpenAPIRuntime", package: "swift-openapi-runtime")
],
plugins: []
),
.target(
name: "OpenapiGenerated",
dependencies: [
.product(name: "OpenAPIURLSession", package: "swift-openapi-urlsession"),
],
plugins: []
)
]
)
Loading

0 comments on commit 75c6157

Please sign in to comment.