Skip to content

Commit cc43297

Browse files
authored
SWIFT-1113 Include BSON symbols in driver docs (#607)
1 parent 03f9d0b commit cc43297

File tree

4 files changed

+37
-3
lines changed

4 files changed

+37
-3
lines changed

.jazzy.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ custom_categories:
1616
- name: Core Types
1717
children:
1818
- MongoClient
19+
- EventLoopBoundMongoClient
1920
- MongoClientOptions
2021
- MongoDatabase
2122
- MongoDatabaseOptions
@@ -139,6 +140,7 @@ custom_categories:
139140
- CollectionType
140141
- CreateCollectionOptions
141142
- DropCollectionOptions
143+
- RenameCollectionOptions
142144

143145
- name: Sessions & Transactions
144146
children:

etc/docs-main.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ The MongoDB Swift driver contains two modules:
77

88
See [here](https://mongodb.github.io/mongo-swift-driver/docs) for documentation of other versions of the driver.
99

10-
The driver relies on our [official Swift BSON library](https://github.com/mongodb/swift-bson), with API documentation available [here](https://mongodb.github.io/swift-bson).
10+
The driver relies on our [official Swift BSON library](https://github.com/mongodb/swift-bson). For convenience, we have merged the BSON documentation in with the driver documentation on this website, but you can also view it separately [here](https://mongodb.github.io/swift-bson).

etc/generate-docs.sh

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,26 @@ version=${1}
1818
# Ensure version is non-empty
1919
[ ! -z "${version}" ] || { echo "ERROR: Missing version string"; exit 1; }
2020

21+
# ensure we have fresh build data for the docs generation process
22+
rm -rf .build
23+
24+
# obtain BSON version from Package.resolved
25+
bson_version="$(python3 etc/get_bson_version.py)"
26+
27+
git clone --depth 1 --branch "v${bson_version}" https://github.com/mongodb/swift-bson
28+
working_dir=${PWD}
29+
cd swift-bson
30+
sourcekitten doc --spm --module-name SwiftBSON > ${working_dir}/bson-docs.json
31+
cd $working_dir
32+
2133
jazzy_args=(--clean
2234
--github-file-prefix https://github.com/mongodb/mongo-swift-driver/tree/v${version}
2335
--module-version "${version}")
2436

2537
# Generate MongoSwift docs
2638
sourcekitten doc --spm --module-name MongoSwift > mongoswift-docs.json
2739
args=("${jazzy_args[@]}" --output "docs-temp/MongoSwift" --module "MongoSwift" --config ".jazzy.yml"
28-
--sourcekitten-sourcefile mongoswift-docs.json
40+
--sourcekitten-sourcefile mongoswift-docs.json,bson-docs.json
2941
--root-url "https://mongodb.github.io/mongo-swift-driver/docs/MongoSwift/")
3042
jazzy "${args[@]}"
3143

@@ -37,12 +49,26 @@ python3 etc/filter_sourcekitten_output.py
3749
sourcekitten doc --spm --module-name MongoSwiftSync > mongoswiftsync-docs.json
3850

3951
args=("${jazzy_args[@]}" --output "docs-temp/MongoSwiftSync" --module "MongoSwiftSync" --config ".jazzy.yml"
40-
--sourcekitten-sourcefile mongoswift-filtered.json,mongoswiftsync-docs.json
52+
--sourcekitten-sourcefile mongoswift-filtered.json,mongoswiftsync-docs.json,bson-docs.json
4153
--root-url "https://mongodb.github.io/mongo-swift-driver/docs/MongoSwiftSync/")
4254
jazzy "${args[@]}"
4355

56+
rm -rf swift-bson
4457
rm mongoswift-docs.json
4558
rm mongoswift-filtered.json
4659
rm mongoswiftsync-docs.json
60+
rm bson-docs.json
4761

4862
echo '<html><head><meta http-equiv="refresh" content="0; url=MongoSwift/index.html" /></head></html>' > docs-temp/index.html
63+
64+
# we can only pass a single GitHub file prefix above, so we need to correct the BSON file paths throughout the docs.
65+
66+
# Jazzy generates the links for each file by taking the base path we provide above as --github-file-prefix and tacking on
67+
# the path of each file relative to the project's root directory. since we check out swift-bson from the root of the driver,
68+
# all of the generated URLs for BSON symbols are of the form
69+
# ....mongo-swift-driver/tree/v[driver version]/swift-bson/...
70+
# Here we replace all occurrences of this with the correct GitHub root URL, swift-bson/tree/v[bson version].
71+
# note: we have to pass -print0 to `find` and pass -0 to `xargs` because some of the file names have spaces in them, which by
72+
# default xargs will treat as a delimiter.
73+
find docs-temp -name "*.html" -print0 | \
74+
xargs -0 etc/sed.sh -i "s/mongo-swift-driver\/tree\/v${version}\/swift-bson/swift-bson\/tree\/v${bson_version}/"

etc/get_bson_version.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import json
2+
3+
with open('Package.resolved', 'r') as f:
4+
data = json.load(f)
5+
bson_data = next(d for d in data['object']['pins'] if d['package'] == 'swift-bson')
6+
print(bson_data['state']['version'])

0 commit comments

Comments
 (0)