-
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
Open
chiraggoyal19
wants to merge
16
commits into
apache:master
Choose a base branch
from
chiraggoyal19:HDDS-10684
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
7431595
HDDS-10684:Add Swagger API for Recon as a Docusaurus page.
chiraggoyal19 1f212da
HDDS-10684:Add Swagger UI component for Recon REST API documentation …
chiraggoyal19 c9ce49f
HDDS-10684:Added recon-api.yaml to resolve linting errors.
chiraggoyal19 af86d71
Apply suggestion from @errose28
chiraggoyal19 4ffc3e6
HDDS-10684:resolved Swagger UI header color coding for api headers
chiraggoyal19 513a3e1
HDDS-10684.Add configurable server URL input to Recon API Swagger UI
chiraggoyal19 10b46ea
HDDS-10684.Added a rule in .yamllint.yml to ignore static/recon-api.y…
chiraggoyal19 85bbd6b
HDDS-10684.Fix configurable server URL, remove unused code, update br…
chiraggoyal19 530e74b
HDDS-10684.added API version input in the Recon rest API
chiraggoyal19 10d0e2e
HDDS-10684.added API version input apply buuton in the Recon rest API
chiraggoyal19 973653f
HDDS-10684.Fixed the styling issues
chiraggoyal19 c8353c0
Update yamllint
jojochuang 17790a4
fix link
jojochuang 5ef8038
HDDS-10684.Removed the swagger ui functionality to configure server
chiraggoyal19 f59efdb
HDDS-10684.Resolved merge conflict
chiraggoyal19 c2ee738
HDDS-10684.Resolved merge conflict
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
3 changes: 0 additions & 3 deletions
3
...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.
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.