Skip to content
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

feat(swift): guide gen #3875

Closed
wants to merge 1 commit into from
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,14 @@ public void addSupportingFiles(List<SupportingFile> supportingFiles, String outp

File templates = new File("templates/" + language + "/guides/" + client);
for (File f : templates.listFiles()) {
String fileName = f.getName().replace(".mustache", "");

if (language.equals("swift")) {
fileName = Helpers.capitalize(fileName) + "/main";
}

supportingFiles.add(
new SupportingFile(
"guides/" + client + "/" + f.getName(),
"guides/" + language + outputFolder + f.getName().replace(".mustache", "") + extension
)
new SupportingFile("guides/" + client + "/" + f.getName(), "guides/" + language + outputFolder + fileName + extension)
);
}
}
Expand All @@ -54,6 +57,14 @@ public void run(Map<String, CodegenModel> models, Map<String, CodegenOperation>
bundle.put("isSearchClient", true);
}
bundle.put("isSyncClient", true);
// nothing to do here, the mustache uses dynamicSnippets lambda

if (language.equals("swift")) {
File templates = new File("templates/" + language + "/guides/" + client);
bundle.put(
"guides",
Arrays.stream(templates.listFiles()).map(File::getName).map(name -> Helpers.capitalize(name.replace(".mustache", ""))).toArray()
);
}
// no data to add to the bundle, the mustache uses dynamicSnippets lambda
}
}
23 changes: 14 additions & 9 deletions templates/swift/guides/Package.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@

import PackageDescription

let dependencies: [Target.Dependency] = [{{#packageList}}
.product(
name: "{{{.}}}",
package: "algoliasearch-client-swift"
),{{/packageList}}
]

let package = Package(
name: "AlgoliaSearchClientGuides",
platforms: [
Expand All @@ -15,14 +22,12 @@ let package = Package(
.package(path: "../../clients/algoliasearch-client-swift")
],
targets: [
.executableTarget(
name: "AlgoliaSearchClientGuides",
dependencies: [{{#packageList}}
.product(
name: "{{{.}}}",
package: "algoliasearch-client-swift"
),{{/packageList}}
]
)
{{#guides}}
.executableTarget(
name: "{{{.}}}",
dependencies: dependencies,
path: "Sources/{{{.}}}"
),
{{/guides}}
]
)
8 changes: 6 additions & 2 deletions templates/swift/guides/search/saveObjectsMovies.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Foundation
import Core
{{> snippets/import}}

func saveObjectsMovies() async throws {
Task {
let url = URL(string: "https://dashboard.algolia.com/sample_datasets/movie.json")!
var data: Data? = nil
#if os(Linux) // For linux interop
Expand All @@ -22,7 +22,11 @@ func saveObjectsMovies() async throws {
do {
// Save records in Algolia index
{{#dynamicSnippet}}saveObjectsMovies{{/dynamicSnippet}}
exit(EXIT_SUCCESS)
} catch {
print(error.localizedDescription)
exit(EXIT_FAILURE)
}
}
}

RunLoop.current.run()
Loading