Skip to content

Commit 8232d65

Browse files
authored
Merge pull request circleci#4669 from circleci/tjs/swap-redoc
API v2 Slate -> Redoc
2 parents 16517e7 + 4255f6a commit 8232d65

File tree

14 files changed

+2705
-166
lines changed

14 files changed

+2705
-166
lines changed

.circleci/config.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,12 +207,12 @@ jobs:
207207
- ruby-deps:
208208
dir: src-api
209209
- restore_cache:
210-
key: circleci-docs-v1-{{ .Branch }}-{{ checksum "src-api/package-lock.json"}}
210+
key: circleci-docs-v2-{{ .Branch }}-{{ checksum "src-api/package-lock.json"}}
211211
- run:
212212
name: Install Node dependencies
213213
command: cd src-api; npm install
214214
- save_cache:
215-
key: circleci-docs-v1-{{ .Branch }}-{{ checksum "src-api/package-lock.json"}}
215+
key: circleci-docs-v2-{{ .Branch }}-{{ checksum "src-api/package-lock.json"}}
216216
paths:
217217
- src-api/node_modules
218218
- run:
@@ -309,7 +309,7 @@ jobs:
309309
### NOTE: we are ignore some files in the HTML proofer as it fails on pending translated docs.
310310
- run:
311311
name: Test with HTMLproofer
312-
command: bundle exec htmlproofer jekyll/_site --allow-hash-href --check-favicon --check-html --disable-external --file-ignore "/docs/ja/2.0/security-server/,/docs/ja/2.0/v.2.19-overview/,/docs/ja/2.0/customizations/,/docs/ja/2.0/aws-prereq/,/docs/ja/2.0/ops/,/docs/ja/2.0/about-circleci/,/docs/ja/2.0/demo-apps/,/docs/ja/2.0/google-auth/,/docs/ja/2.0/orb-concepts/,/docs/ja/2.0/tutorials/,/docs/reference-2-1/" --empty-alt-ignore 2>&1 | nkf -w --url-input | tee $JOB_RESULTS_PATH/htmlproofer-results.txt
312+
command: bundle exec htmlproofer jekyll/_site --allow-hash-href --check-favicon --check-html --disable-external --file-ignore "jekyll/_site/docs/api/v2/index.html,docs/api/v2/,/docs/ja/2.0/security-server/,/docs/ja/2.0/v.2.19-overview/,/docs/ja/2.0/customizations/,/docs/ja/2.0/aws-prereq/,/docs/ja/2.0/ops/,/docs/ja/2.0/about-circleci/,/docs/ja/2.0/demo-apps/,/docs/ja/2.0/google-auth/,/docs/ja/2.0/orb-concepts/,/docs/ja/2.0/tutorials/,/docs/reference-2-1/" --empty-alt-ignore 2>&1 | nkf -w --url-input | tee $JOB_RESULTS_PATH/htmlproofer-results.txt
313313

314314
- store_artifacts: # stores the built files of the Jekyll site
315315
path: jekyll/_site/docs/

README.md

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,25 @@ this folder (in our build process) and integrated into the Jekyll Site. Follow
3636
the [local development guide](./docs/local-development.md) to get started with
3737
building the Jekyll site.
3838

39-
### `/src-api` - API V2 Build Tooling
39+
`/src-api` - API v1.1 and v2 Build Tooling
4040

41-
This is the build tooling we use for automatically generating documentation for
41+
Our API documentation source can be found in this folder.
42+
43+
**API v1** is written by hand, and compiled to work with
44+
[Slate](https://github.com/slatedocs/slate). The compilation and deployment of
45+
`v1` is handled by our `.circleci/config.yml`, which calls our `build_api_docs`
46+
script. If you need to make changes to our V1 documentation, go to
47+
`src-api/source/includes` and make changes as needed in the markdown files.
48+
49+
API v2 is compiled from an [OpenAPI
50+
spec](https://github.com/OAI/OpenAPI-Specification). We use
51+
[Redoc](https://github.com/Redocly/redoc) to compile our spec into a webpage. To
52+
see the compilation process, refer to `build_api_docs.sh` and our
53+
`.circleci/config.yml`. If you need to make changes to the output site, you will
54+
likely need to make source code changes to the API, where the docs are generated
55+
from.
56+
57+
This is the build folder we use for automatically generating documentation for
4258
the CircleCI API v2. This uses [Slate](https://github.com/slatedocs/slate) and
4359
[Widdershins](https://github.com/Mermade/widdershins) to create documentation
4460
with a spec (that follows the Open API Spec) generated from the CircleCI code

jekyll/_cci2/api-developers-guide.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,10 @@ The following section details the steps you would need, from start to finish, to
262262
}' https://circleci.com/api/v2/project/{project-slug}/pipeline
263263
```
264264

265-
This concludes the end-to-end example of using the V2 API. For more detailed information about other endpoints you may wish to call, please refer to the [CircleCI API v2 Documentation]({{site.baseurl}}/api/v2/#circleci-api) for an overview of all endpoints currently available.
265+
This concludes the end-to-end example of using the v2 API. For more detailed
266+
information about other endpoints you may wish to call, please refer to the
267+
[CircleCI API v2 Documentation]({{site.baseurl}}/api/v2) for an overview of all
268+
endpoints currently available.
266269

267270
## Additional API Use Cases
268271

jekyll/_cci2/api-intro.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ In the above example the `project_slug` would take the form `:vcs/:org/:project`
7373

7474
The CircleCI API v2 release includes several new endpoints, and deprecates some others. The sections below list the endpoints added for this release, in addition to the endpoints that have been removed.
7575

76-
For a complete list of all API v2 enpoints, please refer to the [API v2 Reference Guide](https://circleci.com/docs/api/v2/#circleci-api), which contains a detailed description of each individual endpoint, as well as information on required and optional parameters, HTTP status and error codes, and code samples you may use in your workflows.
76+
For a complete list of all API v2 endpoints, please refer to the [API v2 Reference Guide](https://circleci.com/docs/api/v2/), which contains a detailed description of each individual endpoint, as well as information on required and optional parameters, HTTP status and error codes, and code samples you may use in your workflows.
7777

7878
### New Endpoints
7979

jekyll/_cci2/api-job-trigger.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ This document describes how to trigger jobs using the CircleCI API.
1515

1616
<div class="alert alert-warning" role="alert">
1717
<p><span style="font-size: 115%; font-weight: bold;">⚠️ Heads up!</span></p>
18-
<span> This document refers to using the legacy CircleCI API 1.0, a service that will be eventually be deprecated in favour of the <a href="https://circleci.com/docs/api/v2/#circleci-api">V2 API</a>. Consider using the <a href="https://circleci.com/docs/api/v2/#trigger-a-new-pipeline">Pipelines</a> endpoints to trigger pipelines.</span>
18+
<span> This document refers to using the legacy CircleCI API 1.0, a service that will be eventually be deprecated in favor of the <a href="https://circleci.com/docs/api/v2/">V2 API</a>. Consider using the <a href="https://circleci.com/docs/api/v2/#trigger-a-new-pipeline">Pipelines</a> endpoints to trigger pipelines.</span>
1919
</div>
2020

2121

jekyll/_cci2/env-vars.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,9 @@ Not all command-line programs take credentials in the same way that `docker` doe
401401

402402
Pipeline parameters can be used to pass variables using the CircleCI API v2.
403403

404-
A pipeline can be triggered with specific `parameter` values using the API v2 endpoint to [trigger a pipeline]({{site.baseurl}}/api/v2/#trigger-a-new-pipeline). This can be done by passing a `parameters` key in the JSON packet of the `POST` body.
404+
A pipeline can be triggered with specific `parameter` values using the API v2
405+
endpoint to [trigger a pipeline]({{site.baseurl}}/api/v2/#operation/getPipelineConfigById).
406+
This can be done by passing a `parameters` key in the JSON packet of the `POST` body.
405407

406408
The example below triggers a pipeline with the parameters described in the above config example (NOTE: To pass a parameter when triggering a pipeline via the API the parameter must be declared in the configuration file.).
407409

jekyll/_cci2/insights.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ version:
1111

1212
<div class="alert alert-warning" role="alert">
1313
<p><span style="font-size: 115%; font-weight: bold;">⚠️ Heads up!</span></p>
14-
<span> This document refers to using the Insights page on the CircleCI <i>Server</i> product. If you are interested in accessing insights and analytics for your usage, please consider exploring the <a href="https://circleci.com/docs/api/v2/#circleci-api-insights">Insights endpoints</a> of the CircleCI V2 API.</span>
14+
<span> This document refers to using the Insights page on the CircleCI <i>Server</i> product. If you are interested in accessing insights and analytics for your usage, please consider exploring the <a href="https://circleci.com/docs/api/v2/#tag/Insights">Insights endpoints</a> of the CircleCI V2 API.</span>
1515
</div>
1616

1717

jekyll/_cci2_ja/api-intro.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ curl -u ${CIRCLECI_TOKEN}: -X POST --header "Content-Type: application/json" -d
7878

7979
CircleCI API v2 リリースで追加されたエンドポイントもあれば、サポートされなくなったエンドポイントもあります。 以降のセクションに、このリリースで追加されたエンドポイントとサポートされなくなったエンドポイントをまとめています。
8080

81-
API v2 のすべてのエンドポイントは、[API v2 リファレンス ガイド](https://circleci.com/docs/api/v2/#circleci-api)をご覧ください。このガイドには、各エンドポイントの詳細な説明、必須および任意のパラメーターの情報、HTTP ステータスとエラー コード、ワークフローで使用する場合のコード例が掲載されています。
81+
API v2 のすべてのエンドポイントは、[API v2 リファレンス ガイド](https://circleci.com/docs/api/v2/)をご覧ください。このガイドには、各エンドポイントの詳細な説明、必須および任意のパラメーターの情報、HTTP ステータスとエラー コード、ワークフローで使用する場合のコード例が掲載されています。
8282

8383
### 新しいエンドポイント
8484

jekyll/_includes/global-nav.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
<li class="subnav-item"><a href="{{ '/' | language_relative_url }}">Documentation</a></li>
3737
<li class="subnav-item"><a href="https://discuss.circleci.com/" target="_blank">Community Forum</a></li>
3838
<li class="subnav-item" ><a href="https://circleci.com/orbs/">Orbs</a></li>
39-
<li class="subnav-item"><a href="https://circleci.com/docs/api/v2/#circleci-api">API</a></li>
39+
<li class="subnav-item"><a href="https://circleci.com/docs/api/v2/">API</a></li>
4040
<li class="subnav-item"><a href="{{ '/open-source/' | outer_url }}">Open Source</a></li>
4141
</ul>
4242
</div>
@@ -128,7 +128,7 @@
128128
<li class="subnav-item"><a href="{{ '/' | language_relative_url }}">Documentation</a></li>
129129
<li class="subnav-item"><a href="https://discuss.circleci.com/" target="_blank">Community Forum</a></li>
130130
<li class="subnav-item"><a href="https://circleci.com/orbs/">Orbs</a></li>
131-
<li class="subnav-item"><a href="https://circleci.com/docs/api/v2/#circleci-api">API</a></li>
131+
<li class="subnav-item"><a href="https://circleci.com/docs/api/v2/">API</a></li>
132132
<li class="subnav-item"><a href="{{ '/open-source/' | outer_url }}">Open Source</a></li>
133133
</ul>
134134
</li>

scripts/build_api_docs.sh

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,25 @@ build_api_v1() {
1616
echo "Also - Move /tmp/workspace/api/v1 so default root (api/) displays api v1."
1717
}
1818

19-
# Fetches the latest api spec and runs widdershins with it.
19+
# We build our API v2 documentation from an openAPI spec. After fetching the spec we:
20+
# a) augment the spec using "snippet-enricher-cli" to add code-samples to the spec.
21+
# b) TODO: merge in any custom code samples we need to alter, using jq.
22+
# b) run the spec through redoc-cli, outputting a single html file.
23+
# c) move the file into our temporary workspace, created in .circleci/config.yml
2024
build_api_v2() {
21-
echo "Building API v2 documentation with Slate and Widdershins"
22-
cd src-api; rm -r build; rm source/index.html.md
25+
echo "Building API v2 documentation with Redoc"
26+
cd src-api;
27+
echo "Fetching OpenAPI spec."
2328
curl https://circleci.com/api/v2/openapi.json > openapi.json
24-
node node_modules/widdershins/widdershins.js --environment widdershins.apiv2.yml --summary openapi.json -o source/index.html.md
25-
bundle exec middleman build --clean --verbose
26-
cp -R build/* /tmp/workspace/api/v2
27-
echo "Output build moved to /tmp/workspace/api/v2"
29+
echo "Adding code samples to openapi.json spec."
30+
./node_modules/.bin/snippet-enricher-cli --targets="node_request,python_python3,go_native,shell_curl,ruby_native" --input=openapi.json > openapi-with-examples.json
31+
echo "Merging in JSON patches to correct and augment the OpenAPI spec."
32+
jq -s '.[0] * .[1]' openapi-with-examples.json openapi-patch.json > openapi-final.json
33+
echo "Bundling with redoc cli."
34+
./node_modules/.bin/redoc-cli bundle openapi-final.json
35+
echo "Moving build redoc file to api/v2"
36+
mv redoc-static.html index.html
37+
cp index.html /tmp/workspace/api/v2
2838
}
2939

3040
# build the Config Reference from slate.

src-api/openapi-patch.json

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"paths":{
3+
"/context":{
4+
"get":{
5+
"x-codeSamples": [
6+
{
7+
"lang": "Node + Request",
8+
"source": "const request = require('request');\n\nconst options = {\n method: 'GET',\n url: 'https://circleci.com/api/v2/context',\n qs: {\n 'owner-id': 'c65b68ef-e73b-4bf2-be9a-7a322a9df150',\n 'page-token': 'next_page_token'\n },\n headers: {authorization: 'Basic REPLACE_BASIC_AUTH'}\n};\n\nrequest(options, function (error, response, body) {\n if (error) throw new Error(error);\n\n console.log(body);\n});\n"
9+
},
10+
{
11+
"lang": "Python + Python3",
12+
"source": "import http.client\n\nconn = http.client.HTTPSConnection(\"circleci.com\")\n\nheaders = { 'authorization': \"Basic REPLACE_BASIC_AUTH\" }\n\nconn.request(\"GET\", \"/api/v2/context?owner-id=c65b68ef-e73b-4bf2-be9a-7a322a9df150&page-token=next_page_token\", headers=headers)\n\nres = conn.getresponse()\ndata = res.read()\n\nprint(data.decode(\"utf-8\"))"
13+
},
14+
{
15+
"lang": "Go + Native",
16+
"source": "package main\n\nimport (\n\t\"fmt\"\n\t\"net/http\"\n\t\"io/ioutil\"\n)\n\nfunc main() {\n\n\turl := \"https://circleci.com/api/v2/context?owner-id=c65b68ef-e73b-4bf2-be9a-7a322a9df150&page-token=next_page_token\"\n\n\treq, _ := http.NewRequest(\"GET\", url, nil)\n\n\treq.Header.Add(\"authorization\", \"Basic REPLACE_BASIC_AUTH\")\n\n\tres, _ := http.DefaultClient.Do(req)\n\n\tdefer res.Body.Close()\n\tbody, _ := ioutil.ReadAll(res.Body)\n\n\tfmt.Println(res)\n\tfmt.Println(string(body))\n\n}"
17+
},
18+
{
19+
"lang": "Shell + Curl",
20+
"source": "curl --request GET \\\n --url 'https://circleci.com/api/v2/context?owner-id=c65b68ef-e73b-4bf2-be9a-7a322a9df150&page-token=next_page_token' \\\n --header 'authorization: Basic REPLACE_BASIC_AUTH'"
21+
},
22+
{
23+
"lang": "Ruby + Native",
24+
"source": "require 'uri'\nrequire 'net/http'\nrequire 'openssl'\n\nurl = URI(\"https://circleci.com/api/v2/context?owner-id=c65b68ef-e73b-4bf2-be9a-7a322a9df150&page-token=next_page_token\")\n\nhttp = Net::HTTP.new(url.host, url.port)\nhttp.use_ssl = true\nhttp.verify_mode = OpenSSL::SSL::VERIFY_NONE\n\nrequest = Net::HTTP::Get.new(url)\nrequest[\"authorization\"] = 'Basic REPLACE_BASIC_AUTH'\n\nresponse = http.request(request)\nputs response.read_body"
25+
}
26+
]
27+
}
28+
}
29+
}
30+
}

0 commit comments

Comments
 (0)