-
-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathget-models.sh
More file actions
executable file
·48 lines (34 loc) · 2.41 KB
/
get-models.sh
File metadata and controls
executable file
·48 lines (34 loc) · 2.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/bin/bash
set -e
echo "Pulling openapi.yml"
curl https://raw.githubusercontent.com/typesense/typesense-api-spec/master/openapi.yml > openapi.yml
docker run --rm -v "$(pwd):/local" openapitools/openapi-generator-cli generate -i "/local/openapi.yml" -g swift5 -o "/local/output" --additional-properties useJsonEncodable=false --additional-properties hashableModels=false --additional-properties identifiableModels=false
rm -rf Models
cd output/OpenAPIClient/Classes/OpenAPIs
mv ./Models ../../../../
cd ../../../../
rm -rf output
cd Models
# Fix the maxHits type by defining it as a String Optional
find . -name "SearchParameters.swift" -exec sed -i '' 's/maxHits: OneOfSearchParametersMaxHits\?/maxHits: String\?/g' {} \;
find . -name "MultiSearchParameters.swift" -exec sed -i '' 's/maxHits: OneOfMultiSearchParametersMaxHits\?/maxHits: String\?/g' {} \;
find . -name "MultiSearchCollectionParameters.swift" -exec sed -i '' 's/maxHits: Any\?/maxHits: String\?/g' {} \;
# Add Generics to SearchResult
find . -name "SearchResult.swift" -exec sed -i '' 's/SearchResult:/SearchResult<T: Decodable>:/g' {} \;
find . -name "SearchResult.swift" -exec sed -i '' 's/groupedHits: \[SearchGroupedHit\]\?/groupedHits: \[SearchGroupedHit<T>\]\?/g' {} \;
find . -name "SearchResult.swift" -exec sed -i '' 's/hits: \[SearchResultHit\]\?/hits: \[SearchResultHit<T>\]\?/g' {} \;
# Add Generics to MultiSearchResult
find . -name "MultiSearchResult.swift" -exec sed -i '' 's/results: \[SearchResult\]/results: \[SearchResult<T>\]/g' {} \;
find . -name "MultiSearchResult.swift" -exec sed -i '' 's/MultiSearchResult:/MultiSearchResult<T: Decodable>:/g' {} \;
# Add Generics to SearchResultHit
find . -name "SearchResultHit.swift" -exec sed -i '' 's/SearchResultHit:/SearchResultHit<T: Decodable>:/g' {} \;
# Convert document parameter to a generic T
find . -name "SearchResultHit.swift" -exec sed -i '' 's/document: \[String:Any\]\?/document: T?/g' {} \;
# Add Generics to SearchGroupedHit
find . -name "SearchGroupedHit.swift" -exec sed -i '' 's/SearchGroupedHit:/SearchGroupedHit<T: Decodable>:/g' {} \;
find . -name "SearchGroupedHit.swift" -exec sed -i '' 's/hits: \[SearchResultHit\]/hits: \[SearchResultHit<T>\]/g' {} \;
# Convert matchedTokens to custom defined StringQuantum
find . -name "SearchHighlight.swift" -exec sed -i '' 's/matchedTokens: \[Any\]\?/matchedTokens: StringQuantum\?/g' {} \;
cd ..
rm -rf Sources/Typesense/Models
mv ./Models ./Sources/Typesense