From 09f2e1bb4b1c786167681895c3fb6d8f894fa661 Mon Sep 17 00:00:00 2001 From: Mathias Poimer Date: Mon, 8 Apr 2024 14:53:43 +0200 Subject: [PATCH 1/2] Added OpenAPI Generator --- LICENSE | 2 +- README.md | 10 +++++ cookiecutter.json | 1 + hooks/post_gen_project.sh | 4 ++ .../.swiftlint.yml | 1 + .../APIGeneration/.openapi-generator-ignore | 4 ++ .../APIGeneration/generator-config.json | 9 +++++ .../APIGeneration/make | 20 ++++++++++ .../Modules/Core/Package.swift | 39 ++++++++++++++++--- .../generateModels | 4 ++ 10 files changed, 88 insertions(+), 6 deletions(-) create mode 100644 {{cookiecutter.projectDirectory}}/APIGeneration/.openapi-generator-ignore create mode 100644 {{cookiecutter.projectDirectory}}/APIGeneration/generator-config.json create mode 100755 {{cookiecutter.projectDirectory}}/APIGeneration/make create mode 100755 {{cookiecutter.projectDirectory}}/generateModels diff --git a/LICENSE b/LICENSE index dd55f10..61a2385 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2022 aaa - all about apps GmbH +Copyright (c) 2024 aaa - all about apps GmbH Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 3ec189a..08e8e1e 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,16 @@ npm install -g texterify Follow the configuration steps described in the [documentation](https://github.com/chrztoph/texterify-cli#configuration). +#### OpenAPI Generator Setup + +Install [OpenAPI Generator](https://github.com/OpenAPITools/openapi-generator) + +``` +brew install openapi-generator +``` + +Configuration can be edited in `APIGeneration/generator-config.json`, `APIGeneration/make` and `APIGeneration/.openapi-generator-ignore` + ## Steps 1. Run `cookiecutter gh:allaboutapps/ios-starter`. diff --git a/cookiecutter.json b/cookiecutter.json index 8ab2401..da3d4e6 100644 --- a/cookiecutter.json +++ b/cookiecutter.json @@ -5,6 +5,7 @@ "teamName": "aaa - all about apps Gmbh", "bundleIdentifier": "at.allaboutapps.{{cookiecutter.projectName|lower|replace(' ', '-')}}", "deploymentTarget": "16.0", + "swaggerURL": "https://petstore.swagger.io/v2/swagger.json", "texterifyProjectId": "NONE", "texterifyExportConfigurationId": "NONE", "defaultLanguageCode": "en", diff --git a/hooks/post_gen_project.sh b/hooks/post_gen_project.sh index dc2bc0a..625ac34 100755 --- a/hooks/post_gen_project.sh +++ b/hooks/post_gen_project.sh @@ -8,4 +8,8 @@ xcodegen {%- endif %} +{%- if cookiecutter.swaggerURL != 'NONE' %} + ./generateModels +{%- endif %} + printf 'all done - enjoy \xf0\x9f\x9a\x80\n' diff --git a/{{cookiecutter.projectDirectory}}/.swiftlint.yml b/{{cookiecutter.projectDirectory}}/.swiftlint.yml index bedd8de..497dc02 100644 --- a/{{cookiecutter.projectDirectory}}/.swiftlint.yml +++ b/{{cookiecutter.projectDirectory}}/.swiftlint.yml @@ -31,6 +31,7 @@ excluded: - Modules/Core/Sources/Assets/Colors.swift - Modules/Core/Sources/Assets/Images.swift - Modules/Core/Sources/Assets/Strings.swift + - Modules/Core/Sources/Models/Generated/* # configurable rules can be customized from this configuration file line_length: diff --git a/{{cookiecutter.projectDirectory}}/APIGeneration/.openapi-generator-ignore b/{{cookiecutter.projectDirectory}}/APIGeneration/.openapi-generator-ignore new file mode 100644 index 0000000..00e28d2 --- /dev/null +++ b/{{cookiecutter.projectDirectory}}/APIGeneration/.openapi-generator-ignore @@ -0,0 +1,4 @@ +# OpenAPI Generator Ignore + +# example usage +# **/Modules/Core/Sources/Models/Generated/**/Filename.swift \ No newline at end of file diff --git a/{{cookiecutter.projectDirectory}}/APIGeneration/generator-config.json b/{{cookiecutter.projectDirectory}}/APIGeneration/generator-config.json new file mode 100644 index 0000000..26e7157 --- /dev/null +++ b/{{cookiecutter.projectDirectory}}/APIGeneration/generator-config.json @@ -0,0 +1,9 @@ +{ + "projectName": "{{cookiecutter.projectName}}", + "readonlyProperties": true, + "responseAs": "Combine", + "swiftPackagePath": "/", + "validateSpec": false, + "validatable": false, + "useJsonEncodable": false +} \ No newline at end of file diff --git a/{{cookiecutter.projectDirectory}}/APIGeneration/make b/{{cookiecutter.projectDirectory}}/APIGeneration/make new file mode 100755 index 0000000..3455508 --- /dev/null +++ b/{{cookiecutter.projectDirectory}}/APIGeneration/make @@ -0,0 +1,20 @@ +#!/bin/bash +cd $(dirname $0) + +# if you want to supply your swagger.yml directly, +# comment the next two lines and create a swagger.yml +rm -rf swagger.yml; +curl -o swagger.yml {{cookiecutter.swaggerURL}}; + +rm -rf ../Modules/Core/Sources/Models/Generated; + +openapi-generator generate -i swagger.yml \ + -g swift5 \ + -o ../Modules/Core/Sources/Models/Generated \ + -c generator-config.json \ + --global-property models,modelDocs=false,modelTests=false \ + --ignore-file-override=./.openapi-generator-ignore \ + --type-mappings uuid4=UUID; + +mv ../Modules/Core/Sources/Models/Generated/Models/* ../Modules/Core/Sources/Models/Generated/; +rm -rf ../Modules/Core/Sources/Models/Generated/Models; \ No newline at end of file diff --git a/{{cookiecutter.projectDirectory}}/Modules/Core/Package.swift b/{{cookiecutter.projectDirectory}}/Modules/Core/Package.swift index e6f1323..c970203 100644 --- a/{{cookiecutter.projectDirectory}}/Modules/Core/Package.swift +++ b/{{cookiecutter.projectDirectory}}/Modules/Core/Package.swift @@ -19,30 +19,59 @@ let package = Package( .package(url: "https://github.com/allaboutapps/Toolbox.git", from: "5.0.0"), .package(url: "https://github.com/kishikawakatsumi/KeychainAccess.git", from: "4.2.2"), .package(url: "https://github.com/Alamofire/AlamofireImage.git", from: "4.2.0"), + .package(url: "https://github.com/Flight-School/AnyCodable.git", from: "0.6.7"), ], targets: [ .target( name: "Assets", - dependencies: ["Logbook", "Toolbox", "KeychainAccess"] + dependencies: [ + "Logbook", + "Toolbox", + "KeychainAccess", + ] ), .target( name: "CommonUI", - dependencies: ["Assets", "Models", "Utilities", "Logbook", "Toolbox", "AlamofireImage"] + dependencies: [ + "Assets", + "Models", + "Utilities", + "Logbook", + "Toolbox", + "AlamofireImage", + ] ), .target( name: "Models", - dependencies: ["Logbook", "Toolbox", "KeychainAccess"] + dependencies: [ + "Logbook", + "Toolbox", + "KeychainAccess", + "AnyCodable", + ] ), .target( name: "Networking", - dependencies: ["Models", "Utilities", "Fetch", "Logbook", "Toolbox", "KeychainAccess"], + dependencies: [ + "Models", + "Utilities", + "Fetch", + "Logbook", + "Toolbox", + "KeychainAccess", + ], resources: [ .process("Stubs"), ] ), .target( name: "Utilities", - dependencies: ["Fetch", "Logbook", "Toolbox", "KeychainAccess"] + dependencies: [ + "Fetch", + "Logbook", + "Toolbox", + "KeychainAccess", + ] ), ] ) diff --git a/{{cookiecutter.projectDirectory}}/generateModels b/{{cookiecutter.projectDirectory}}/generateModels new file mode 100755 index 0000000..769ec35 --- /dev/null +++ b/{{cookiecutter.projectDirectory}}/generateModels @@ -0,0 +1,4 @@ +#!/bin/bash +cd $(dirname $0) + +./APIGeneration/make \ No newline at end of file From 1e3e131ee0c2551324d0942f78623ec779b575f7 Mon Sep 17 00:00:00 2001 From: Mathias Poimer Date: Tue, 9 Apr 2024 11:56:29 +0200 Subject: [PATCH 2/2] pr feedback --- README.md | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 08e8e1e..31a7a0c 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,15 @@ Install [OpenAPI Generator](https://github.com/OpenAPITools/openapi-generator) brew install openapi-generator ``` -Configuration can be edited in `APIGeneration/generator-config.json`, `APIGeneration/make` and `APIGeneration/.openapi-generator-ignore` +Configuration can be edited in `APIGeneration/generator-config.json`, `APIGeneration/make` and `APIGeneration/.openapi-generator-ignore`. + +The models can be generated by running either the `generateModels` script inside the root folder or the `make` script inside the `APIGeneration` folder. +The swagger URL can be edited in `APIGeneration/make`. +If you want to directly supply a swagger.yml, create one in the `APIGeneration` folder and remove the following lines +``` +rm -rf swagger.yml; +curl -o swagger.yml swaggerURL; +``` ## Steps