-
Notifications
You must be signed in to change notification settings - Fork 65
HDDS-10684. Add Swagger API for Recon as a Docusaurus page. #264
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
bd2c53f
HDDS-10684:Add Swagger API for Recon as a Docusaurus page.
chiraggoyal19 da2e7c0
HDDS-10684:Add Swagger UI component for Recon REST API documentation …
chiraggoyal19 a95f637
Apply suggestion from @errose28
chiraggoyal19 4da5ea0
HDDS-10684:resolved Swagger UI header color coding for api headers
chiraggoyal19 079021d
HDDS-10684.Add configurable server URL input to Recon API Swagger UI
chiraggoyal19 2854742
HDDS-10684.Fix configurable server URL, remove unused code, update br…
chiraggoyal19 b8cf278
HDDS-10684.added API version input in the Recon rest API
chiraggoyal19 da6c949
HDDS-10684.added API version input apply buuton in the Recon rest API
chiraggoyal19 42507ac
HDDS-10684.Fixed the styling issues
chiraggoyal19 45d2dc7
fix link
jojochuang 22df370
HDDS-10684.Removed the swagger ui functionality to configure server
chiraggoyal19 53451dd
HDDS-10684.Resolved merge conflict
chiraggoyal19 81d197d
HDDS-10684.resolved merge conflicts
chiraggoyal19 717f78d
HDDS-10684.resolved redirection issue
chiraggoyal19 3309016
HDDS-10684.resolved lint issues
chiraggoyal19 88b2be1
HDDS-10684.resolved lint issues
chiraggoyal19 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 0 additions & 8 deletions
8
...dministrator-guide/03-operations/09-observability/02-recon/02-recon-rest-api.md
This file was deleted.
Oops, something went wrong.
9 changes: 9 additions & 0 deletions
9
...ministrator-guide/03-operations/09-observability/02-recon/02-recon-rest-api.mdx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| # Recon REST API | ||
|
|
||
| import SwaggerUI from '@site/src/components/SwaggerUI'; | ||
|
|
||
| Ozone Recon's public **REST API** follows the [OpenAPI specification](https://www.openapis.org/), and is documented below. | ||
|
|
||
| The API is defined in the [recon-api.yaml](/recon-api.yaml) OpenAPI specification file and is available under the [Apache 2.0 License](http://www.apache.org/licenses/LICENSE-2.0.html). | ||
|
|
||
| <SwaggerUI spec="/recon-api.yaml" defaultServer="http://localhost:9888" /> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| import React, { useState, useRef, useEffect } from 'react'; | ||
| import SwaggerUI from 'swagger-ui-react'; | ||
| import 'swagger-ui-react/swagger-ui.css'; | ||
| import useBaseUrl from '@docusaurus/useBaseUrl'; | ||
| import styles from './styles.module.css'; | ||
|
|
||
| export default function SwaggerUIComponent({ spec, defaultServer }) { | ||
| const specUrl = useBaseUrl(spec); | ||
| const [serverUrl, setServerUrl] = useState(defaultServer || 'http://localhost:9888'); | ||
| const [apiVersion, setApiVersion] = useState('v1'); | ||
| const [appliedServerUrl, setAppliedServerUrl] = useState(defaultServer || 'http://localhost:9888'); | ||
| const [appliedApiVersion, setAppliedApiVersion] = useState('v1'); | ||
| const swaggerSystemRef = useRef(null); | ||
|
|
||
| // Update the server URL in Swagger only when applied values change | ||
| useEffect(() => { | ||
| if (swaggerSystemRef.current) { | ||
| const spec = swaggerSystemRef.current.getState().getIn(['spec', 'json']); | ||
| if (spec) { | ||
| // Construct full URL: {serverUrl}/api/{version}/ | ||
| const baseUrl = appliedServerUrl.endsWith('/') ? appliedServerUrl.slice(0, -1) : appliedServerUrl; | ||
| const fullServerUrl = `${baseUrl}/api/${appliedApiVersion}/`; | ||
| swaggerSystemRef.current.specActions.updateJsonSpec({ | ||
| ...spec.toJS(), | ||
| servers: [{ url: fullServerUrl, description: 'Configured Recon Server' }] | ||
| }); | ||
| } | ||
| } | ||
| }, [appliedServerUrl, appliedApiVersion]); | ||
|
|
||
| const handleApply = () => { | ||
| setAppliedServerUrl(serverUrl); | ||
| setAppliedApiVersion(apiVersion); | ||
| }; | ||
|
|
||
| return ( | ||
| <div className={styles.swaggerWrapper}> | ||
| <div className={styles.serverConfig}> | ||
| <label htmlFor="recon-server-url" className={styles.serverLabel}> | ||
| Recon Server URL: | ||
| </label> | ||
| <input | ||
| id="recon-server-url" | ||
| type="text" | ||
| value={serverUrl} | ||
| onChange={(e) => setServerUrl(e.target.value)} | ||
| placeholder="http://localhost:9888" | ||
| className={styles.serverInput} | ||
| /> | ||
| <label htmlFor="recon-api-version" className={styles.serverLabel}> | ||
| API Version: | ||
| </label> | ||
| <input | ||
| id="recon-api-version" | ||
| type="text" | ||
| value={apiVersion} | ||
| onChange={(e) => setApiVersion(e.target.value)} | ||
| placeholder="v1" | ||
| className={styles.versionInput} | ||
| /> | ||
| <button | ||
| onClick={handleApply} | ||
| className={styles.applyButton} | ||
| type="button" | ||
| > | ||
| Apply | ||
| </button> | ||
| <span className={styles.serverHint}> | ||
| (Default for Docker quick start. Change server/version and click Apply.) | ||
| </span> | ||
| </div> | ||
| <SwaggerUI | ||
| url={specUrl} | ||
| docExpansion="list" | ||
| defaultModelsExpandDepth={1} | ||
| defaultModelExpandDepth={1} | ||
| onComplete={(system) => { | ||
| // Store the system reference for later updates | ||
| swaggerSystemRef.current = system; | ||
| // Set initial server URL with API version | ||
| const spec = system.getState().getIn(['spec', 'json']); | ||
| if (spec) { | ||
| const baseUrl = appliedServerUrl.endsWith('/') ? appliedServerUrl.slice(0, -1) : appliedServerUrl; | ||
| const fullServerUrl = `${baseUrl}/api/${appliedApiVersion}/`; | ||
| system.specActions.updateJsonSpec({ | ||
| ...spec.toJS(), | ||
| servers: [{ url: fullServerUrl, description: 'Configured Recon Server' }] | ||
| }); | ||
| } | ||
| }} | ||
| /> | ||
| </div> | ||
| ); | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.