Skip to content

Commit 9c0c2be

Browse files
authored
Merge pull request #62 from dseevr/split_docs
Split RAML into netmaster and auth_proxy routes and combine the HTML output after generation
2 parents 95a136f + 59103c2 commit 9c0c2be

22 files changed

+689
-468
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# data is extracted from this file and merged into spec/docs/contiv.html as part of the build process
2+
# but we don't actually need to keep it around.
3+
spec/docs/auth_proxy.html

scripts/build.sh

+1-26
Original file line numberDiff line numberDiff line change
@@ -6,32 +6,7 @@ set -euo pipefail
66
bash generate.sh
77
go install ./ ./client/
88

9-
# regenerate netmaster.raml
10-
docker run --rm \
11-
-u $(id -u):$(id -g) \
12-
-v $(pwd):/files \
13-
-w /files/spec \
14-
ruby:2.4.0-slim /usr/local/bin/ruby contivModel2raml.rb
15-
mv spec/netmaster.raml ./spec/contiv/libraries/netmaster.raml
16-
17-
# run the raml2html tool to generate docs under spec/docs
9+
# update the docs based on the latest code
1810
pushd spec
1911
make docs
20-
mkdir -p docs
21-
mv contiv.html docs/
2212
popd
23-
24-
# because we have to do some tidying up of the output HTML and it requires some
25-
# external dependencies, we use a small Docker image to do it.
26-
# this image uses the same ruby:2.4.0-slim base as above.
27-
IMAGE_NAME="contiv_api_documentation_cleanup"
28-
29-
if [[ "$(docker images -q $IMAGE_NAME:latest 2>/dev/null)" == "" ]]; then
30-
docker build -t $IMAGE_NAME -f spec/Dockerfile.cleanup .
31-
fi
32-
33-
docker run --rm \
34-
-u $(id -u):$(id -g) \
35-
-v $(pwd):/files \
36-
-w /files/spec \
37-
$IMAGE_NAME /usr/local/bin/ruby cleanup.rb

spec/Dockerfile

+2-4
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@ FROM node:alpine
22

33
RUN npm install -g raml2html
44

5-
COPY . /contiv
5+
RUN mkdir /contiv
66

77
WORKDIR /contiv
88

9-
RUN raml2html -i contiv.raml -o contiv.html
10-
11-
ENTRYPOINT ["/bin/sh"]
9+
ENTRYPOINT ["raml2html"]

spec/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
all: docs
22

33
docs:
4-
@./build.sh
4+
@bash ./build.sh
55

66
.PHONY: docs

spec/auth_proxy.raml

+97
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
#%RAML 1.0
2+
title: Contiv
3+
description: Contiv API Specification
4+
version: v1
5+
baseUri:
6+
value: https://{serverfqdn}:10000/api/{version}
7+
(rediractable): true
8+
baseUriParameters:
9+
serverfqdn:
10+
type: string
11+
protocols: [ HTTPS ]
12+
mediaType: [ application/json ]
13+
14+
resourceTypes:
15+
collection: !include auth_proxy/schemas/collection.raml
16+
non-upd-collection-item: !include auth_proxy/schemas/non-upd-collection-item.raml
17+
collection-item: !include auth_proxy/schemas/collection-item.raml
18+
ro-collection-item: !include auth_proxy/schemas/ro-collection-item.raml
19+
20+
annotationTypes:
21+
info:
22+
properties:
23+
license:
24+
type: string
25+
enum: [ "Apache 2.0" ]
26+
allowedTargets: API
27+
rediractable: boolean
28+
29+
securitySchemes:
30+
custom_scheme: !include auth_proxy/schemas/custom-scheme.raml
31+
32+
# Resource templates
33+
uses:
34+
auth_proxy: auth_proxy/libraries/auth_proxy.raml
35+
36+
securedBy: custom_scheme
37+
38+
# auth_proxy endpoints
39+
/auth_proxy:
40+
displayName: Auth API
41+
description: Authentication/Authorization related API
42+
43+
/health:
44+
get:
45+
securedBy: [ null ]
46+
responses:
47+
200:
48+
body:
49+
application/json:
50+
type: auth_proxy.health
51+
52+
/login:
53+
post:
54+
description: Login to Contiv API server
55+
securedBy: [ null ]
56+
body:
57+
application/json:
58+
type: auth_proxy.login
59+
responses:
60+
200:
61+
body:
62+
application/json:
63+
type: auth_proxy.login_response
64+
400:
65+
401:
66+
67+
/version:
68+
get:
69+
securedBy: [ null ]
70+
responses:
71+
200:
72+
body:
73+
application/json: |
74+
{ "version": "1.0.0-beta" }
75+
76+
/authorizations:
77+
type: {collection: {provider: auth_proxy}}
78+
displayName: Authorizations
79+
80+
/{authzUUID}:
81+
type: {non-upd-collection-item: {provider: auth_proxy}}
82+
displayName: Authorization
83+
84+
/local_users:
85+
type: {collection: {provider: auth_proxy}}
86+
displayName: Local Users
87+
88+
/{username}:
89+
type: {collection-item: {provider: auth_proxy}}
90+
displayName: Local User
91+
patch:
92+
93+
/ldap_configuration:
94+
type: {collection-item: {provider: auth_proxy}}
95+
displayName: LDAP Configuration
96+
put:
97+
patch:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#%RAML 1.0 ResourceType
2+
description: Entity representing <<resourcePathName|!singularize>>
3+
get:
4+
description: returns <<resourcePathName|!singularize>>.
5+
responses:
6+
200:
7+
body:
8+
application/json:
9+
type: <<provider>>.<<resourcePathName|!singularize>>
10+
404:
11+
body:
12+
application/json: |
13+
{"message": "<<resourcePathName|!singularize>> not found" }
14+
delete:
15+
description: deletes <<resourcePathName|!singularize>>.
16+
responses:
17+
204:
18+
put?:
19+
description: updates/creates <<resourcePathName|!singularize>>
20+
body:
21+
application/json:
22+
type: <<provider>>.upd_<<resourcePathName|!singularize>>
23+
responses:
24+
200:
25+
body:
26+
application/json:
27+
type: <<provider>>.<<resourcePathName|!singularize>>
28+
404:
29+
body:
30+
application/json: |
31+
{"message": "<<resourcePathName|!singularize>> not found" }
32+
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#%RAML 1.0 ResourceType
2+
description: A collection of <<resourcePathName>>
3+
get:
4+
description: returns a list of <<resourcePathName|!singularize>>.
5+
responses:
6+
200:
7+
body:
8+
application/json:
9+
type: <<provider>>.<<resourcePathName>>
10+
post:
11+
description: Add a new <<resourcePathName|!singularize>>.
12+
body:
13+
application/json:
14+
type: <<provider>>.<<resourcePathName|!singularize>>
15+
responses:
16+
201:
17+
404:

spec/build.sh

+49-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,52 @@
22

33
set -euo pipefail
44

5-
docker build -t contiv/spec .
6-
cid=$(docker run -itd contiv/spec)
7-
docker cp ${cid}:/contiv/contiv.html .
8-
docker rm -fv ${cid}
5+
mkdir -p docs
6+
7+
#
8+
# regenerate libraries/netmaster.raml which holds the type netmaster type data
9+
#
10+
docker run --rm \
11+
-u $(id -u):$(id -g) \
12+
-v $(pwd)/../:/files \
13+
-w /files/spec \
14+
ruby:2.4.0-slim /usr/local/bin/ruby generate_raml.rb ./netmaster/libraries/netmaster.raml
15+
16+
#
17+
# convert the raml into HTML output
18+
#
19+
RAML_IMAGE_NAME="contiv/raml2html"
20+
21+
if [[ "$(docker images -q $RAML_IMAGE_NAME:latest 2>/dev/null)" == "" ]]; then
22+
docker build -t $RAML_IMAGE_NAME .
23+
fi
24+
25+
echo "generating netmaster docs"
26+
docker run --rm \
27+
-u $(id -u):$(id -g) \
28+
-v $(pwd):/contiv \
29+
$RAML_IMAGE_NAME -i netmaster.raml -o docs/contiv.html
30+
31+
echo "generating auth_proxy docs"
32+
docker run --rm \
33+
-u $(id -u):$(id -g) \
34+
-v $(pwd):/contiv \
35+
$RAML_IMAGE_NAME -i auth_proxy.raml -o docs/auth_proxy.html
36+
37+
#
38+
# because we have to do some tidying up of the output HTML and it requires some
39+
# external dependencies, we use a small Docker image to do it.
40+
# this image uses the same ruby:2.4.0-slim base as above.
41+
#
42+
CLEANUP_IMAGE_NAME="contiv/api_documentation_cleanup"
43+
44+
if [[ "$(docker images -q $CLEANUP_IMAGE_NAME:latest 2>/dev/null)" == "" ]]; then
45+
docker build -t $CLEANUP_IMAGE_NAME -f Dockerfile.cleanup .
46+
fi
47+
48+
echo "Cleaning up HTML output"
49+
docker run --rm \
50+
-u $(id -u):$(id -g) \
51+
-v $(pwd):/files \
52+
-w /files \
53+
$CLEANUP_IMAGE_NAME /usr/local/bin/ruby cleanup.rb

spec/cleanup.rb

+18-4
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,23 @@
77

88
doc = Nokogiri::HTML(File.read(FILENAME))
99

10-
# add trailing slashes to all paths
10+
# ----- IMPORT AUTH_PROXY DATA ----------------------------------------------------------------------
11+
12+
auth_doc = Nokogiri::HTML(File.read("docs/auth_proxy.html"))
13+
14+
# extract the main panel and sidebar link nodes
15+
auth_panel = auth_doc.css(".panel-default").first
16+
sidebar_link = auth_doc.css("#sidebar ul li").first
17+
18+
# add auth_proxy api panel under the header
19+
doc.at(".page-header").after(auth_panel)
20+
21+
# add auth_proxy link to the top of the sidebar
22+
doc.at("#sidebar ul").prepend_child(sidebar_link)
23+
24+
# ----- TIDY OUTPUT FILE ----------------------------------------------------------------------------
1125

26+
# add trailing slashes to all paths
1227
node_groups = [
1328
doc.css(".panel-title a").select { |n| n.text.start_with?("/") },
1429
doc.css(".modal-title"),
@@ -19,13 +34,12 @@
1934
end
2035

2136
# insert additional <head> tag requirements for the contiv header
22-
2337
doc.at("head") << Nokogiri::HTML::DocumentFragment.parse(File.read("docs/head.html"))
2438

2539
# insert the contiv header html into the top of the <body>
26-
2740
doc.at("body").prepend_child(Nokogiri::HTML::DocumentFragment.parse(File.read("docs/body.html")))
2841

29-
# overwrite the original HTML file
42+
# ----- OUTPUT --------------------------------------------------------------------------------------
3043

44+
# overwrite the original HTML file
3145
File.write(FILENAME, doc.to_html)

0 commit comments

Comments
 (0)