Skip to content

Commit 0b3739a

Browse files
committed
HDDS-10684.Add configurable server URL input to Recon API Swagger UI
1 parent 598b3df commit 0b3739a

3 files changed

Lines changed: 112 additions & 5 deletions

File tree

docs/05-administrator-guide/03-operations/09-observability/02-recon/02-recon-rest-api.mdx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,13 @@ import SwaggerUI from '@site/src/components/SwaggerUI';
55
Ozone Recon's public **REST API** follows the [OpenAPI specification](https://www.openapis.org/), and is documented below. The docs are generated using [Swagger React UI](https://github.com/swagger-api/swagger-ui).
66

77
:::info
8-
You can find an interactive version of this documentation on your local Ozone Recon instance at **/api/v1/** (if Recon is running).
8+
**Interactive API Testing**
9+
10+
You can test these APIs directly from this page using the "Try it out" button on each endpoint.
11+
12+
- **Default server**: `http://localhost:9888` (matches the [Docker quick start guide](/docs/quick-start/installation/docker))
13+
- **Custom server**: Update the "Recon Server URL" field above to point to your own Recon instance
14+
- **Local instance**: If you're running Recon locally, you can also access the interactive Swagger UI at `http://localhost:9888/api/v1/`
915
:::
1016

11-
<SwaggerUI spec="/recon-api.yaml" />
17+
<SwaggerUI spec="/recon-api.yaml" defaultServer="http://localhost:9888" />

src/components/SwaggerUI/index.js

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,66 @@
1717
* under the License.
1818
*/
1919

20-
import React from 'react';
20+
import React, { useState, useEffect } from 'react';
2121
import SwaggerUI from 'swagger-ui-react';
2222
import 'swagger-ui-react/swagger-ui.css';
2323
import useBaseUrl from '@docusaurus/useBaseUrl';
2424
import styles from './styles.module.css';
2525

26-
export default function SwaggerUIComponent({ spec }) {
26+
export default function SwaggerUIComponent({ spec, defaultServer }) {
2727
const specUrl = useBaseUrl(spec);
28-
28+
const [serverUrl, setServerUrl] = useState(defaultServer || 'http://localhost:9888');
29+
const [specData, setSpecData] = useState(null);
30+
31+
useEffect(() => {
32+
// Fetch the spec and modify the servers array
33+
fetch(specUrl)
34+
.then(response => response.text())
35+
.then(text => {
36+
// Parse YAML to JSON (simple approach for this case)
37+
// Since swagger-ui-react can handle YAML, we'll pass the URL
38+
// but configure servers via the spec modification
39+
return fetch(specUrl).then(r => r.json().catch(() => {
40+
// If JSON parsing fails, it's YAML, use the URL directly
41+
return null;
42+
}));
43+
})
44+
.catch(() => null);
45+
}, [specUrl]);
46+
2947
return (
3048
<div className={styles.swaggerWrapper}>
49+
<div className={styles.serverConfig}>
50+
<label htmlFor="recon-server-url" className={styles.serverLabel}>
51+
Recon Server URL:
52+
</label>
53+
<input
54+
id="recon-server-url"
55+
type="text"
56+
value={serverUrl}
57+
onChange={(e) => setServerUrl(e.target.value)}
58+
placeholder="http://localhost:9888"
59+
className={styles.serverInput}
60+
/>
61+
<span className={styles.serverHint}>
62+
(Default for Docker quick start. Change to match your Recon instance.)
63+
</span>
64+
</div>
3165
<SwaggerUI
3266
url={specUrl}
3367
docExpansion="list"
3468
defaultModelsExpandDepth={1}
3569
defaultModelExpandDepth={1}
70+
onComplete={(system) => {
71+
// Override the servers in the spec with the user-configured URL
72+
const spec = system.getState().getIn(['spec', 'json']);
73+
if (spec) {
74+
system.specActions.updateJsonSpec({
75+
...spec.toJS(),
76+
servers: [{ url: serverUrl, description: 'Configured Recon Server' }]
77+
});
78+
}
79+
}}
3680
/>
3781
</div>
3882
);

src/components/SwaggerUI/styles.module.css

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,63 @@
2222
margin-bottom: 2rem;
2323
}
2424

25+
/* Server configuration input */
26+
.serverConfig {
27+
background: var(--ifm-color-primary-lightest);
28+
border: 1px solid var(--ifm-color-primary-light);
29+
border-radius: 8px;
30+
padding: 20px;
31+
margin-bottom: 30px;
32+
display: flex;
33+
align-items: center;
34+
gap: 15px;
35+
flex-wrap: wrap;
36+
}
37+
38+
[data-theme='dark'] .serverConfig {
39+
background: rgba(150, 210, 110, 0.1);
40+
border-color: var(--ifm-color-primary-dark);
41+
}
42+
43+
.serverLabel {
44+
font-weight: 600;
45+
color: var(--ifm-font-color-base);
46+
font-size: 14px;
47+
margin: 0;
48+
}
49+
50+
.serverInput {
51+
flex: 1;
52+
min-width: 300px;
53+
padding: 8px 12px;
54+
border: 1px solid #ccc;
55+
border-radius: 4px;
56+
font-size: 14px;
57+
font-family: var(--ifm-font-family-monospace);
58+
color: var(--ifm-font-color-base);
59+
background: var(--ifm-background-color);
60+
}
61+
62+
[data-theme='dark'] .serverInput {
63+
border-color: #444;
64+
}
65+
66+
.serverInput:focus {
67+
outline: none;
68+
border-color: var(--ifm-color-primary);
69+
box-shadow: 0 0 0 2px rgba(53, 117, 0, 0.1);
70+
}
71+
72+
[data-theme='dark'] .serverInput:focus {
73+
box-shadow: 0 0 0 2px rgba(150, 210, 110, 0.2);
74+
}
75+
76+
.serverHint {
77+
font-size: 13px;
78+
color: var(--ifm-font-color-base);
79+
font-style: italic;
80+
}
81+
2582
/* Remove white bars and extra spacing */
2683
.swaggerWrapper :global(.swagger-ui .information-container) {
2784
margin: 0;

0 commit comments

Comments
 (0)