Skip to content

Pin App Store Connect API spec #143

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 25 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,12 @@ $(SWIFTLINT_BIN):
@mv .tmp/swiftlint/swiftlint $@
@ln -s swiftlint-$(SWIFTLINT_VERSION) .tmp/swiftlint/swiftlint

SPEC_URL = https://developer.apple.com/sample-code/app-store-connect/app-store-connect-openapi-specification.zip
SPEC_STRING := $(shell cat Sources/DeveloperAPI/spec-version.txt)
SPEC_COMMIT = $(word 1,$(SPEC_STRING))
SPEC_VERSION = $(word 2,$(SPEC_STRING))
SPEC_URL_BASE = https://raw.githubusercontent.com/EvanBacon/App-Store-Connect-OpenAPI-Spec
SPEC_URL = $(SPEC_URL_BASE)/$(SPEC_COMMIT)/specs/$(SPEC_VERSION).json
SPEC_BASE = openapi/base-$(SPEC_VERSION).json

.PHONY: api
# Regenerate the OpenAPI client code
Expand All @@ -159,14 +164,23 @@ api: openapi/openapi.json
.PHONY: update-api
# Update OpenAPI spec and regenerate the client code
update-api:
@+$(MAKE) -B api

openapi/openapi.json: openapi/base.json Sources/DeveloperAPI/patch.js
node Sources/DeveloperAPI/patch.js < openapi/base.json > openapi/openapi.json

openapi/base.json:
@+$(MAKE) update-api-version
@+$(MAKE) api

.PHONY: update-api-version
# Just update the OpenAPI spec version
update-api-version:
latest_commit=$$(curl -fsSL \
'https://api.github.com/repos/EvanBacon/App-Store-Connect-OpenAPI-Spec/commits?per_page=1' \
| jq -r '.[0].sha'); \
echo "$$latest_commit" > Sources/DeveloperAPI/spec-version.txt; \
curl -fsSL "$(SPEC_URL_BASE)/$$latest_commit/specs/latest.json" \
| jq -r '.info.version' >> Sources/DeveloperAPI/spec-version.txt

openapi/openapi.json: $(SPEC_BASE) Sources/DeveloperAPI/patch.js
node Sources/DeveloperAPI/patch.js < $(SPEC_BASE) > openapi/openapi.json

$(SPEC_BASE):
@mkdir -p openapi
# piping curl|bsdtar concatenates xattrs into the JSON :thonk:
curl -fsSL "$(SPEC_URL)" -o openapi/spec.zip
bsdtar -xO -f openapi/spec.zip > openapi/base.json
rm -f openapi/spec.zip
@rm -f openapi/base*.json
curl -fsSL "$(SPEC_URL)" -o "$@"
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ let package = Package(
dependencies: [
.product(name: "OpenAPIRuntime", package: "swift-openapi-runtime"),
],
exclude: ["openapi-generator-config.yaml", "patch.js"]
exclude: ["openapi-generator-config.yaml", "patch.js", "spec-version.txt"]
),
.target(
name: "XKit",
Expand Down
2 changes: 2 additions & 0 deletions Sources/DeveloperAPI/spec-version.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
a210f7e8a6591416fbf6c2d718783ba27d9e050a
4.0.0