Skip to content

Commit dd8073c

Browse files
add support for optional swagger ui (#1005)
* add support for optional swagger ui [ci] Signed-off-by: Peter Kvokacka <peter.kvokacka@digitalasset.com> * [ci] Signed-off-by: Peter Kvokacka <peter.kvokacka@digitalasset.com> * [ci] Signed-off-by: Peter Kvokacka <peter.kvokacka@digitalasset.com> --------- Signed-off-by: Peter Kvokacka <peter.kvokacka@digitalasset.com>
1 parent 7244461 commit dd8073c

File tree

9 files changed

+103
-9
lines changed

9 files changed

+103
-9
lines changed

cluster/compose/localnet/README.md

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,18 @@ The `*.localhost` domains will resolve to your local host IP `127.0.0.1`.
8686
- **App Provider**: app-provider
8787
- **SV**: sv
8888

89+
## Swagger UI
90+
91+
When the `swagger-ui` profile is enabled, the Swagger UI for the `JSON Ledger API HTTP Endpoints` across all running participants is available at [http://localhost:9090](http://localhost:9090).
92+
Note: Some endpoints require a JWT token when using the **Try it out** feature. One method to obtain this token is via the Canton Console. Start the Canton Console and execute the following command:
93+
```
94+
app-provider.adminToken
95+
```
96+
97+
For proper functionality, Swagger UI relies on a localhost nginx proxy for `canton.localhost` configured for each participant. For example, the `JSON Ledger API HTTP Endpoints` for the app-provider
98+
can be accessed at the nginx proxy URL `http://canton.localhost:${APP_PROVIDER_UI_PORT}` via Swagger UI, which corresponds to accessing `localhost:3${PARTICIPANT_JSON_API_PORT}` directly.
99+
The nginx proxy only adds additional headers to resolve CORS issues within Swagger UI.
100+
89101

90102
## Run in localnet
91103
### start
@@ -110,7 +122,30 @@ docker compose --env-file $LOCALNET_DIR/compose.env \
110122
--profile app-provider \
111123
--profile app-user down -v
112124
```
113-
125+
### start with swagger-ui
126+
```
127+
docker compose --env-file $LOCALNET_DIR/compose.env \
128+
--env-file $LOCALNET_DIR/env/common.env \
129+
--env-file $LOCALNET_DIR/env/local.env \
130+
-f $LOCALNET_DIR/compose.yaml \
131+
-f $LOCALNET_DIR/resource-constraints.yaml \
132+
--profile sv \
133+
--profile app-provider \
134+
--profile app-user \
135+
--profile swagger-ui up -d
136+
```
137+
### stop with swagger-ui
138+
```
139+
docker compose --env-file $LOCALNET_DIR/compose.env \
140+
--env-file $LOCALNET_DIR/env/common.env \
141+
--env-file $LOCALNET_DIR/env/local.env \
142+
-f $LOCALNET_DIR/compose.yaml \
143+
-f $LOCALNET_DIR/resource-constraints.yaml \
144+
--profile sv \
145+
--profile app-provider \
146+
--profile app-user \
147+
--profile swagger-ui down -v
148+
```
114149
### console
115150
```
116151
docker compose --env-file $LOCALNET_DIR/compose.env \

cluster/compose/localnet/compose.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ services:
6868
- ${LOCALNET_DIR}/conf/nginx/app-provider.conf:/etc/nginx/templates/app-provider.c${APP_PROVIDER_PROFILE}f.template
6969
- ${LOCALNET_DIR}/conf/nginx/app-user.conf:/etc/nginx/templates/app-user.c${APP_USER_PROFILE}f.template
7070
- ${LOCALNET_DIR}/conf/nginx/sv.conf:/etc/nginx/templates/sv.c${SV_PROFILE}f.template
71+
- ${LOCALNET_DIR}/conf/nginx/swagger-ui:/etc/nginx/includes
7172
ports:
7273
- "${SV_UI_PORT}:${SV_UI_PORT}"
7374
- "${APP_PROVIDER_UI_PORT}:${APP_PROVIDER_UI_PORT}"
@@ -192,6 +193,20 @@ services:
192193
profiles:
193194
- console
194195

196+
swagger-ui:
197+
image: swaggerapi/swagger-ui
198+
container_name: swagger-ui
199+
volumes:
200+
- ${LOCALNET_DIR}/docker/swagger-ui/entrypoint.sh:/entrypoint.sh
201+
environment:
202+
URLS: '[{"url": "http://canton.localhost:${APP_PROVIDER_UI_PORT}/docs/openapi", "name": "app-provider"},
203+
{"url": "http://canton.localhost:${APP_USER_UI_PORT}/docs/openapi", "name": "app-user"},
204+
{"url": "http://canton.localhost:${SV_UI_PORT}/docs/openapi", "name": "sv"}]'
205+
ports:
206+
- "${SWAGGER_UI_PORT}:8080"
207+
profiles:
208+
- swagger-ui
209+
195210
###############################################################################################################
196211
### Application User
197212
###############################################################################################################

cluster/compose/localnet/conf/nginx/app-provider.conf

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,15 @@ server {
1616

1717
server {
1818
listen ${APP_PROVIDER_UI_PORT};
19-
server_name swagger.localhost;
19+
server_name canton.localhost;
2020
location /docs/openapi {
21-
proxy_pass http://canton:3${PARTICIPANT_JSON_API_PORT}/docs/openapi;
21+
proxy_pass http://canton:3${PARTICIPANT_JSON_API_PORT}/docs/openapi;
22+
include /etc/nginx/includes/cors-headers.conf;
23+
}
24+
25+
location /v2 {
26+
include /etc/nginx/includes/cors-options-headers.conf;
27+
proxy_pass http://canton:3${PARTICIPANT_JSON_API_PORT}/v2;
28+
include /etc/nginx/includes/cors-headers.conf;
2229
}
2330
}

cluster/compose/localnet/conf/nginx/app-user.conf

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,16 @@ server {
1515
}
1616

1717
server {
18-
listen ${APP_USER_UI_PORT};
19-
server_name swagger.localhost;
20-
location /docs/openapi {
21-
proxy_pass http://canton:2${PARTICIPANT_JSON_API_PORT}/docs/openapi;
22-
}
18+
listen ${APP_USER_UI_PORT};
19+
server_name canton.localhost;
20+
location /docs/openapi {
21+
proxy_pass http://canton:2${PARTICIPANT_JSON_API_PORT}/docs/openapi;
22+
include /etc/nginx/includes/cors-headers.conf;
23+
}
24+
25+
location /v2 {
26+
include /etc/nginx/includes/cors-options-headers.conf;
27+
proxy_pass http://canton:2${PARTICIPANT_JSON_API_PORT}/v2;
28+
include /etc/nginx/includes/cors-headers.conf;
29+
}
2330
}

cluster/compose/localnet/conf/nginx/sv.conf

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,18 @@ server {
5757
proxy_pass http://wallet-web-ui-sv:8080/;
5858
}
5959
}
60+
61+
server {
62+
listen ${SV_UI_PORT};
63+
server_name canton.localhost;
64+
location /docs/openapi {
65+
proxy_pass http://canton:4${PARTICIPANT_JSON_API_PORT}/docs/openapi;
66+
include /etc/nginx/includes/cors-headers.conf;
67+
}
68+
69+
location /v2 {
70+
include /etc/nginx/includes/cors-options-headers.conf;
71+
proxy_pass http://canton:4${PARTICIPANT_JSON_API_PORT}/v2;
72+
include /etc/nginx/includes/cors-headers.conf;
73+
}
74+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
add_header Access-Control-Allow-Origin *;
2+
add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS';
3+
add_header Access-Control-Allow-Headers 'Origin, Content-Type, Accept';
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
if ($request_method = OPTIONS) {
2+
add_header 'Access-Control-Allow-Origin' "$http_origin" always;
3+
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS, PUT, DELETE' always;
4+
add_header 'Access-Control-Allow-Headers' '*' always;
5+
add_header 'Access-Control-Max-Age' 1728000;
6+
add_header 'Content-Type' 'text/plain charset=UTF-8';
7+
add_header 'Content-Length' 0;
8+
return 204;
9+
}

cluster/compose/localnet/env/common.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ CANTON_GRPC_HEALTHCHECK_PORT=${CANTON_GRPC_HEALTHCHECK_PORT:-5061}
2929
APP_USER_UI_PORT=${APP_USER_UI_PORT:-2000}
3030
APP_PROVIDER_UI_PORT=${APP_PROVIDER_UI_PORT:-3000}
3131
SV_UI_PORT=${SV_UI_PORT:-4000}
32+
SWAGGER_UI_PORT=${SWAGGER_UI_PORT:-9090}
3233

3334
SPLICE_SV_IS_DEVNET=${SPLICE_SV_IS_DEVNET:-true}
3435
SPLICE_APP_VALIDATOR_AUTH_AUDIENCE=${SPLICE_APP_VALIDATOR_AUTH_AUDIENCE:-https://sv.example.com}

cluster/compose/localnet/resource-constraints.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ services:
1515
environment:
1616
_JAVA_OPTIONS: "-XX:-UseCompressedOops -Xms512m -Xmx2560m"
1717
console:
18-
mem_limit: 1g
18+
mem_limit: 2g
1919
environment:
2020
_JAVA_OPTIONS: "-XX:+UseContainerSupport -XX:-UseCompressedOops"
2121
scan-web-ui:
@@ -28,3 +28,5 @@ services:
2828
mem_limit: 256mb
2929
wallet-web-ui-sv:
3030
mem_limit: 256mb
31+
swagger-ui:
32+
mem_limit: 128mb

0 commit comments

Comments
 (0)