From d0223efe6aad3ee716c25c920acd997456bb3d0e Mon Sep 17 00:00:00 2001 From: Andrew Montgomery Date: Mon, 21 Oct 2024 09:55:19 -0500 Subject: [PATCH 1/3] Reorganize openapi files --- openapi/{spec.yaml => openapi.yaml} | 0 openapi/{ => templates}/model.mustache | 0 openapi/{ => templates}/modelInlineEnumDeclaration.mustache | 0 openapi/{ => templates}/modelObject.mustache | 0 4 files changed, 0 insertions(+), 0 deletions(-) rename openapi/{spec.yaml => openapi.yaml} (100%) rename openapi/{ => templates}/model.mustache (100%) rename openapi/{ => templates}/modelInlineEnumDeclaration.mustache (100%) rename openapi/{ => templates}/modelObject.mustache (100%) diff --git a/openapi/spec.yaml b/openapi/openapi.yaml similarity index 100% rename from openapi/spec.yaml rename to openapi/openapi.yaml diff --git a/openapi/model.mustache b/openapi/templates/model.mustache similarity index 100% rename from openapi/model.mustache rename to openapi/templates/model.mustache diff --git a/openapi/modelInlineEnumDeclaration.mustache b/openapi/templates/modelInlineEnumDeclaration.mustache similarity index 100% rename from openapi/modelInlineEnumDeclaration.mustache rename to openapi/templates/modelInlineEnumDeclaration.mustache diff --git a/openapi/modelObject.mustache b/openapi/templates/modelObject.mustache similarity index 100% rename from openapi/modelObject.mustache rename to openapi/templates/modelObject.mustache From 672e037afae33939943c610d7dca10bc6cd295fc Mon Sep 17 00:00:00 2001 From: Andrew Montgomery Date: Mon, 21 Oct 2024 10:37:48 -0500 Subject: [PATCH 2/3] Update `generate` command to use official docker image, swift package format --- .gitignore | 2 +- Makefile | 54 ++++++++----------- .../.openapi-generator-ignore | 37 +++++++++++++ .../.openapi-generator/FILES | 13 +++++ .../.openapi-generator/VERSION | 1 + 5 files changed, 75 insertions(+), 32 deletions(-) create mode 100644 openapi/GravatarOpenAPIClient/.openapi-generator-ignore create mode 100644 openapi/GravatarOpenAPIClient/.openapi-generator/FILES create mode 100644 openapi/GravatarOpenAPIClient/.openapi-generator/VERSION diff --git a/.gitignore b/.gitignore index 6b6b275c..35c5ae6a 100644 --- a/.gitignore +++ b/.gitignore @@ -49,5 +49,5 @@ fastlane/test_output vendor/swiftgen # Other -openapi-generator/ +openapi/GravatarOpenAPIClient/Sources/ Demo/Demo/Secrets.swift diff --git a/Makefile b/Makefile index 4e7bafd2..54bca19f 100644 --- a/Makefile +++ b/Makefile @@ -9,13 +9,16 @@ SWIFTFORMAT_CACHE = ~/Library/Caches/com.charcoaldesign.swiftformat # The following values can be changed here, or passed on the command line. -OPENAPI_GENERATOR_GIT_URL ?= https://github.com/openapitools/openapi-generator +OPENAPI_GENERATOR_DOCKER_IMAGE ?= openapitools/openapi-generator-cli OPENAPI_GENERATOR_GIT_TAG ?= v7.5.0 -OPENAPI_GENERATOR_CLONE_DIR ?= $(CURRENT_MAKEFILE_DIR)/openapi-generator -OPENAPI_YAML_PATH ?= $(CURRENT_MAKEFILE_DIR)/openapi/spec.yaml -MODEL_TEMPLATE_PATH ?= $(CURRENT_MAKEFILE_DIR)/openapi OUTPUT_DIRECTORY ?= $(CURRENT_MAKEFILE_DIR)/Sources/Gravatar/OpenApi/Generated +OPENAPI_PROJECT_NAME ?= GravatarOpenAPIClient +OPENAPI_REL_DIR ?= openapi +OPENAPI_DIR ?= $(CURRENT_MAKEFILE_DIR)/$(OPENAPI_REL_DIR) +OPENAPI_GENERATED_DIR ?= $(CURRENT_MAKEFILE_DIR)/openapi/$(OPENAPI_PROJECT_NAME) +OPENAPI_CLIENT_PROPERTIES ?= projectName=$(OPENAPI_PROJECT_NAME),useSPMFileStructure=true + # Derived values (don't change these). CURRENT_MAKEFILE_PATH := $(abspath $(lastword $(MAKEFILE_LIST))) CURRENT_MAKEFILE_DIR := $(patsubst %/,%,$(dir $(CURRENT_MAKEFILE_PATH))) @@ -108,20 +111,17 @@ install-and-generate: $(OPENAPI_GENERATOR_CLONE_DIR) # Clones and setup the open "$(OPENAPI_GENERATOR_CLONE_DIR)"/run-in-docker.sh mvn package make generate -generate: $(OUTPUT_DIRECTORY) # Generates the open-api model - cp "$(OPENAPI_YAML_PATH)" "$(OPENAPI_GENERATOR_CLONE_DIR)"/openapi.yaml - mkdir -p "$(OPENAPI_GENERATOR_CLONE_DIR)"/templates - cp "$(MODEL_TEMPLATE_PATH)"/*.mustache "$(OPENAPI_GENERATOR_CLONE_DIR)"/templates/ - rm -rf "$(OPENAPI_GENERATOR_CLONE_DIR)"/generated/OpenAPIClient/Classes/OpenAPIs/Models/* - "$(OPENAPI_GENERATOR_CLONE_DIR)"/run-in-docker.sh generate -i openapi.yaml \ - --global-property models \ - -t templates \ - -g swift5 \ - -o ./generated \ - -p packageName=Gravatar \ - --additional-properties=useJsonEncodable=false,readonlyProperties=true && \ - rsync -av --delete "$(OPENAPI_GENERATOR_CLONE_DIR)"/generated/OpenAPIClient/Classes/OpenAPIs/Models/ "$(OUTPUT_DIRECTORY)/" && \ - make swiftformat && \ +generate: $(OPENAPI_GENERATED_DIR) # Generates the open-api model + rm -rf "$(OPENAPI_GENERATED_DIR)"/* && \ + docker run --rm \ + -v $(OPENAPI_DIR):/local openapitools/openapi-generator-cli:"$(OPENAPI_GENERATOR_GIT_TAG)" generate \ + -i /local/openapi.yaml \ + -o /local/GravatarOpenAPIClient \ + -t /local/templates \ + -g swift5 \ + -p packageName=Gravatar \ + --additional-properties=useJsonEncodable=false,readonlyProperties=true,$(OPENAPI_CLIENT_PROPERTIES) && \ + make swiftformat && \ echo "DONE! 🎉" generate-strings: bundle-install @@ -142,20 +142,12 @@ clean: # Clean everything, including the checkout of swift-openapi-generator. dump: # Dump all derived values used by the Makefile. @echo "CURRENT_MAKEFILE_PATH = $(CURRENT_MAKEFILE_PATH)" @echo "CURRENT_MAKEFILE_DIR = $(CURRENT_MAKEFILE_DIR)" - @echo "OPENAPI_GENERATOR_GIT_URL = $(OPENAPI_GENERATOR_GIT_URL)" + @echo "OPENAPI_GENERATOR_DOCKER_IMAGE = $(OPENAPI_GENERATOR_DOCKER_IMAGE)" @echo "OPENAPI_GENERATOR_GIT_TAG = $(OPENAPI_GENERATOR_GIT_TAG)" - @echo "OPENAPI_GENERATOR_CLONE_DIR = $(OPENAPI_GENERATOR_CLONE_DIR)" - @echo "OPENAPI_YAML_PATH = $(OPENAPI_YAML_PATH)" + @echo "OPENAPI_DIR = $(OPENAPI_DIR)" + @echo "OPENAPI_GENERATED_DIR = $(OPENAPI_GENERATED_DIR)" + @echo "OPENAPI_CLIENT_PROPERTIES = $(OPENAPI_CLIENT_PROPERTIES)" @echo "OUTPUT_DIRECTORY = $(OUTPUT_DIRECTORY)" -$(OPENAPI_GENERATOR_CLONE_DIR): - git \ - -c advice.detachedHead=false \ - clone \ - --branch "$(OPENAPI_GENERATOR_GIT_TAG)" \ - --depth 1 \ - "$(OPENAPI_GENERATOR_GIT_URL)" \ - $@ - -$(OUTPUT_DIRECTORY): +$(OPENAPI_GENERATED_DIR): mkdir -p "$@" diff --git a/openapi/GravatarOpenAPIClient/.openapi-generator-ignore b/openapi/GravatarOpenAPIClient/.openapi-generator-ignore new file mode 100644 index 00000000..e3283984 --- /dev/null +++ b/openapi/GravatarOpenAPIClient/.openapi-generator-ignore @@ -0,0 +1,37 @@ +# OpenAPI Generator Ignore +# Generated by openapi-generator https://github.com/openapitools/openapi-generator + +# Use this file to prevent files from being overwritten by the generator. +# The patterns follow closely to .gitignore or .dockerignore. + +# As an example, the C# client generator defines ApiClient.cs. +# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line: +#ApiClient.cs + +# You can match any string of characters against a directory, file or extension with a single asterisk (*): +#foo/*/qux +# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux + +# You can recursively match patterns against a directory, file or extension with a double asterisk (**): +#foo/**/qux +# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux + +# You can also negate patterns with an exclamation (!). +# For example, you can ignore all files in a docs folder with the file extension .md: +#docs/*.md +# Then explicitly reverse the ignore rule for a single file: +#!docs/README.md + +.gitignore +.swiftformat +docs/ +Cartfile +git_push.sh +GravatarOpenAPIClient.podspec +Package.swift +project.yml +README.md + +# Skip all sources except 'Models' +Sources/GravatarOpenAPIClient/ +!Sources/GravatarOpenAPIClient/Models/ diff --git a/openapi/GravatarOpenAPIClient/.openapi-generator/FILES b/openapi/GravatarOpenAPIClient/.openapi-generator/FILES new file mode 100644 index 00000000..d75e1219 --- /dev/null +++ b/openapi/GravatarOpenAPIClient/.openapi-generator/FILES @@ -0,0 +1,13 @@ +Sources/GravatarOpenAPIClient/Models/AssociatedResponse.swift +Sources/GravatarOpenAPIClient/Models/Avatar.swift +Sources/GravatarOpenAPIClient/Models/CryptoWalletAddress.swift +Sources/GravatarOpenAPIClient/Models/GalleryImage.swift +Sources/GravatarOpenAPIClient/Models/Interest.swift +Sources/GravatarOpenAPIClient/Models/Language.swift +Sources/GravatarOpenAPIClient/Models/Link.swift +Sources/GravatarOpenAPIClient/Models/ModelError.swift +Sources/GravatarOpenAPIClient/Models/Profile.swift +Sources/GravatarOpenAPIClient/Models/ProfileContactInfo.swift +Sources/GravatarOpenAPIClient/Models/ProfilePayments.swift +Sources/GravatarOpenAPIClient/Models/SetEmailAvatarRequest.swift +Sources/GravatarOpenAPIClient/Models/VerifiedAccount.swift diff --git a/openapi/GravatarOpenAPIClient/.openapi-generator/VERSION b/openapi/GravatarOpenAPIClient/.openapi-generator/VERSION new file mode 100644 index 00000000..18bb4182 --- /dev/null +++ b/openapi/GravatarOpenAPIClient/.openapi-generator/VERSION @@ -0,0 +1 @@ +7.5.0 From 1ef109ab35410561d78ff7f54edf85ebfc4fba63 Mon Sep 17 00:00:00 2001 From: Andrew Montgomery Date: Mon, 21 Oct 2024 10:39:53 -0500 Subject: [PATCH 3/3] Rsync the generated models --- Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile b/Makefile index 54bca19f..59cb50fa 100644 --- a/Makefile +++ b/Makefile @@ -121,6 +121,7 @@ generate: $(OPENAPI_GENERATED_DIR) # Generates the open-api model -g swift5 \ -p packageName=Gravatar \ --additional-properties=useJsonEncodable=false,readonlyProperties=true,$(OPENAPI_CLIENT_PROPERTIES) && \ + rsync -av --delete "$(OPENAPI_GENERATED_DIR)/Sources/$(OPENAPI_PROJECT_NAME)/Models/" "$(OUTPUT_DIRECTORY)/" && \ make swiftformat && \ echo "DONE! 🎉"