Skip to content

Commit 57b0a29

Browse files
authored
Merge pull request #3 from Wei18/feat/gen-code-from-yml
Feature: generating *yml and *.swift from openapi.yml
2 parents 1f69984 + 80ce10f commit 57b0a29

File tree

7 files changed

+39380
-26
lines changed

7 files changed

+39380
-26
lines changed

.github/workflows/actions/setup/action.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,16 @@ runs:
1515
with:
1616
swift-version: ${{ inputs.swift }}
1717
- uses: irgaly/setup-mint@v1
18+
- uses: chrisdickinson/setup-yq@latest
19+
1820
- name: "Xcode Cache"
1921
if: contains(inputs.os, 'macos')
2022
uses: irgaly/xcode-cache@v1
2123
with:
2224
key: xcode-cache-deriveddata-${{ github.workflow }}-${{ github.sha }}
2325
restore-keys: |
2426
xcode-cache-deriveddata-${{ github.workflow }}-
27+
2528
- name: "Swift Package Manager Cache"
2629
uses: actions/cache@v3
2730
with:

Makefile

Lines changed: 41 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
# Special-Targets #
44
# https://www.gnu.org/software/make/manual/html_node/Special-Targets.html
55
.DEFAULT_GOAL := install
6-
SUBDIRS := $(wildcard Sources/*)
6+
OPENAPI_PATH := Submodule/github/rest-api-description/descriptions/api.github.com/api.github.com.yaml
7+
.SECONDARY: $(%.yml)
78

89
.PHONY: force
910
force:
@@ -14,28 +15,47 @@ Submodule: force
1415
git commit -m "[Make] Pull $$(git submodule status Submodule/github/rest-api-description)" || true
1516
echo "::notice:: make $@"
1617

17-
OPENAPI_FILES := $(addsuffix /openapi.yml, $(SUBDIRS))
18-
%/openapi.yml: Submodule
19-
ln -sf ../../Submodule/github/rest-api-description/descriptions/api.github.com/api.github.com.yaml $@
20-
git add $@
18+
TAG_NAMES := $(shell yq -r '.tags[].name' $(OPENAPI_PATH))
19+
SUBDIRS := $(addprefix Sources/, $(TAG_NAMES))
20+
OPENAPI_CONFIG_FILES := $(addsuffix /openapi-generator-config.yml, $(SUBDIRS))
21+
%/openapi-generator-config.yml: Submodule
22+
mkdir -p "$(@D)"
23+
@tag_name=$(shell basename $(shell dirname $@)); \
24+
echo "generate:" > $@; \
25+
echo " - types" >> $@; \
26+
echo " - client" >> $@; \
27+
echo "" >> $@; \
28+
echo "" >> $@; \
29+
echo "filter:" >> $@; \
30+
echo " tags:" >> $@; \
31+
echo " - $$tag_name" >> $@; \
32+
echo "" >> $@; \
33+
echo "" >> $@; \
34+
echo "accessModifier: public" >> $@; \
35+
echo "" >> $@;
36+
# git add $@ # INTERMEDIATE file after *.swift
37+
38+
%/openapi.yml: %/openapi-generator-config.yml Submodule
39+
ln -sf ../../$(OPENAPI_PATH) $@
40+
# git add $@ # INTERMEDIATE file after *.swift
2141

2242
SWIFT_FILES := $(addsuffix /Client.swift, $(SUBDIRS))
23-
%.swift: $(OPENAPI_FILES)
43+
%/Client.swift: %/openapi.yml
2444
mint run apple/swift-openapi-generator generate $(@D)/openapi.yml \
25-
--config $(@D)/openapi-generator-config.yml \
26-
--output-directory $(@D)
27-
git add $@ $(@D)/Types.swift
45+
--config $(@D)/openapi-generator-config.yml \
46+
--output-directory $(@D)
47+
git add $(@D)
48+
git commit -m "[Make] Sync *.swift" || true
2849

29-
install-files: $(SWIFT_FILES)
30-
git commit -m "[Make] Re-link openapi.yml & re-gen swift files." || true
50+
install: $(SWIFT_FILES)
3151
echo "::notice:: make $@"
32-
52+
3353
#XCFrameworks:
3454
# mint run giginet/Scipio create . \
35-
# --embed-debug-symbols \
36-
# --support-simulators
55+
# --embed-debug-symbols \
56+
# --support-simulators
3757
# echo "::notice:: make $@"
38-
#
58+
3959
#XCFRAMEWORKS := $(wildcard XCFrameworks/*.xcframework)
4060
#ZIP_FILES := $(XCFRAMEWORKS:%.xcframework=%.zip)
4161
#%.zip: %.xcframework
@@ -47,14 +67,12 @@ install-files: $(SWIFT_FILES)
4767
# git commit -m "[Make] Re-gen framework zips" || true
4868
# echo "::notice:: make $@"
4969

50-
install: install-files
51-
52-
.build/docs: ## Need env GITHUB_PAGES is created as 'true'
53-
swift package --allow-writing-to-directory $@ generate-documentation \
54-
--disable-indexing \
55-
--output-path $@ \
56-
--transform-for-static-hosting \
57-
--hosting-base-path github-rest-api-swift-openapi;
70+
#.build/docs: ## Need env GITHUB_PAGES is created as 'true'
71+
# swift package --allow-writing-to-directory $@ generate-documentation \
72+
# --disable-indexing \
73+
# --output-path $@ \
74+
# --transform-for-static-hosting \
75+
# --hosting-base-path github-rest-api-swift-openapi;
5876

5977
.PHONY: help
6078
.SILENT: help

Package.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import Foundation
88
/// which can be useful when generating client code for a subset of a large API,
99
/// or splitting an implementation of a server across multiple modules.
1010
enum GitHubRestAPIOpenAPITag: String, CaseIterable {
11+
case actions
1112
case activity
1213
case apps
1314
case billing
@@ -59,9 +60,9 @@ enum GitHubRestAPIOpenAPITag: String, CaseIterable {
5960
.product(name: "OpenAPIURLSession", package: "swift-openapi-urlsession"),
6061
],
6162
path: "Sources/\(rawValue)",
62-
resources: [
63-
.copy("openapi-generator-config.yml"),
64-
.copy("openapi.yml"),
63+
exclude: [
64+
"openapi-generator-config.yml",
65+
"openapi.yml",
6566
]
6667
)
6768
}

0 commit comments

Comments
 (0)