Comments (29)
Maybe it's like using a dom-based third-party library in react
.
from redoc-try.
is it possible or not ? If yes please can you provide some example where i can directly use try it out option with redoc. i feel it will be useful for everyone.
from redoc-try.
Sorry, this may not be a good solution.
This is a sample code: <RedocTry tryText="try out" />
.
react/16.13.1
react-dom/16.13.1
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>Hello World</title>
</head>
<body>
<div id="root"></div>
<script src="//cdnjs.cloudflare.com/ajax/libs/react/16.13.1/umd/react.development.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/react-dom/16.13.1/umd/react-dom.development.js"></script>
<script src="//unpkg.com/@babel/[email protected]/babel.js"></script>
<script type="text/babel">
function RedocTry(userCfg) {
const {
useEffect
} = React
function loadJs(url, callback) {
var script = document.createElement(`script`)
script.type = `text/javascript`
if (typeof callback !== `undefined`) {
if (script.readyState) {
script.onreadystatechange = function () {
if (script.readyState === `loaded` || script.readyState === `complete`) {
script.onreadystatechange = null
callback()
}
}
} else {
script.onload = function () {
callback()
}
}
}
script.src = url
document.body.appendChild(script)
}
useEffect(() => {
Promise.all([
`https://cdn.jsdelivr.net/npm/[email protected]/bundles/redoc.standalone.min.js`,
`https://cdn.jsdelivr.net/gh/wll8/[email protected]/dist/try.js`
].map(item => {
return new Promise(resolve => {
loadJs(item, () => resolve(item))
})
})).then(() => {
window.initTry(Object.keys(userCfg).length ? userCfg : `https://petstore.swagger.io/v2/swagger.json`)
})
})
return <div id="redoc-container"></div>
}
ReactDOM.render(
<div>
<RedocTry tryText="try out" />
</div>,
document.getElementById('root')
);
</script>
</body>
</html>
from redoc-try.
Yes. it adding multiple times try-out and it shows blank screen on try-out. I'm trying to pass { redocOptions: { hideLoading: true }
its not working and break in middle.
Below are my some redoc options:
const redocOptions = {
hideLoading: true,
hideDownloadButton: true,
scrollYOffset: 56,
theme: {
typography: {
fontFamily: '"Metric", sans-serif',
headings: {
fontFamily: '"Metric", Arial, sans-serif'
},
optimizeSpeed: true
},
spacing: {
sectionVertical: 10
}
}
};
from redoc-try.
Please can you modify that code sample because it adding multiple times try-out . It would be a great help.
from redoc-try.
What does it mean to add multiple try-out?
Does it mean that there are multiple try-out buttons on the same interface?
If you mean this, then my test did not find this problem. Please provide an example of the smallest reproducible problem, thank you.
from redoc-try.
T_T...
Maybe I have found the problem and it is being solved...
from redoc-try.
I am very sorry for the problems I have brought before. I will definitely go through a complete test in the future.
ReactDOM.render(
<div>
<RedocTry tryText="try out" redocOptions={{
hideLoading: true,
hideDownloadButton: true,
scrollYOffset: 56,
theme: {
typography: {
fontFamily: '"Metric", sans-serif',
headings: {
fontFamily: '"Metric", Arial, sans-serif'
},
optimizeSpeed: true
},
spacing: {
sectionVertical: 10
}
}
}}
/>
</div>,
document.getElementById('root')
);
Reference modification record: fix: redocOptions
is not recognized correctly
from redoc-try.
Yes it adds try-out button twice.
i also see a error in console.
from redoc-try.
it rendering multiple times and sometime it just show blank with one try-out.
from redoc-try.
Please try this react sample code.
I want to know the system you are using and the browser version.
- operating system:
- browser and version:
- react version:
- redoc version:
- redoc-try version:
- Itβs better to have code that can cause problems:
The following is the result of my operation, which can work normally.
- operating system: win10 x64
- browser and version: chrome 80.0.3987.149 x86
- react version: 16.13.1 umd
- redoc version: [email protected]
- redoc-try version: [email protected]
- Itβs better to have code that can cause problems:
from redoc-try.
Please try this code
To reproduce issue: refresh page multiple times
you would see similar in the above image.
i feel it rendering multiple times. Please do the needful.
from redoc-try.
Issue two
open same sandbox in the new page with full screen .i.e https://s3n8l.csb.app/
Redoc is Responsive three-panel design with menu/scrolling synchronization.
Please notice that right panel couldn't able to show entire information. it cut off and doesn't have scrollbar feature to see Entire information. I'm attaching image.
from redoc-try.
Multiple try buttons
Thank you for the online code.
Sorry, through your online code, after performing multiple refresh operations, I still haven't seen multiple times of try.
However, I think that the initTry method is executed multiple times due to react
rendering multiple times.
You can try to judge that there is already a try button on the page and then no longer run the initTry method.
swagger Small resolution display is truncated
Although this is due to the swagger-ui itself, the container margin of redoc has taken up a part of the space, but I also hope to optimize it.
from redoc-try.
Thanks man. I'm able to resolve rendering issue. Now looking forward for the truncated one.
from redoc-try.
<RedocStandalone
specUrl={`/entities/api/v1/spec/?productionServer=${browserLocationOrigin}`}
options={redocOptions}
onLoaded={() => {
setLoading(false);
}}
If you see the above code you have given example how to pass the specurl, options in redoc-try. Do you have any idea for onLoaded ? is there any way to pass redoc onLoaded property also ?
from redoc-try.
If you want to use every parameter, you can set redocOptions to an array, corresponding to:
[specOrSpecUrl?, options?, element?, callback?]
react example:
<div>
<RedocTry tryText="try out" redocOptions={[
`https://petstore.swagger.io/v2/swagger.json`, // specOrSpecUrl
{}, // options
undefined, // element
error => console.log(`onLoaded`, error) // callback
]}
/>
</div>
from redoc-try.
How can i override or change swagger ui styling changes ? is there an option to pass in swaggeroptions and override a classname?
from redoc-try.
If you want to use every parameter, you can set redocOptions to an array, corresponding to:
[specOrSpecUrl?, options?, element?, callback?]
react example:
<div> <RedocTry tryText="try out" redocOptions={[ `https://petstore.swagger.io/v2/swagger.json`, // specOrSpecUrl {}, // options undefined, // element error => console.log(`onLoaded`, error) // callback ]} /> </div>
if i pass in array it doesn't add try-out button
from redoc-try.
The only way is to directly override the css style within the scope of #swagger-ui
directly.
Reference code and picture:
body .swagger-ui .wrapper {
padding: 0;
}
Welcome to contribute optimized css.
from redoc-try.
How can i use try.js file from local instead of cdn ? what are files required if i do from local ?
useEffect(() => {
Promise.all([
`https://cdn.jsdelivr.net/npm/[email protected]/bundles/redoc.standalone.min.js`,
`https://cdn.jsdelivr.net/gh/wll8/[email protected]/try.js`
].map(item => {
return new Promise(resolve => {
loadJs(item, () => resolve(item))
})
})).then(() => {
window.initTry(Object.keys(userCfg).length ? userCfg : `https://petstore.swagger.io/v2/swagger.json`)
})
})
return <div id="redoc-container"></div>
}
from redoc-try.
Okay. i'm ready to contribute and before that i want to tell the reason behind my css change. Redoc already provides Responses feature and which again duplicating by swagger ui. i want to hide responses-wrapper class in swagger-ui.
if this change looks fine to you , i can create a PR and do this change.
from redoc-try.
How can i use try.js file from local instead of cdn ? what are files required if i do from local ?
Download all the cdn files on the network to the local, and use the local path.
- https://cdn.jsdelivr.net/npm/[email protected]/bundles/redoc.standalone.min.js
- https://cdn.jsdelivr.net/gh/wll8/redoc-try/dist/try.js
- https://cdn.jsdelivr.net/npm/[email protected]/dist/jquery.min.js
- https://cdn.jsdelivr.net/npm/[email protected]/jquery.scrollTo.min.js
- https://unpkg.com/[email protected]/swagger-ui-bundle.js
- https://unpkg.com/[email protected]/swagger-ui.css
from redoc-try.
if i pass in array it doesn't add try-out button
This is caused by the callback function
in the array overwriting the callback function
in try.js, which, I think, means you want to override it.
The function of try.js to initialize swagger is done in the callback function.
Reference code:
try.js#L44
from redoc-try.
If i use try.js file and modify as per my needs in local. does it require license ?
from redoc-try.
from redoc-try.
This question was closed because no response was received. If there are other questions, welcome to open new issues
.
from redoc-try.
Hi, can Redoc's try it functionality be enabled somehow, since I'm using this as a component in react and need to make requests?
<RedocStandalone specUrl="http://petstore.swagger.io/v2/swagger.json" options={{ nativeScrollbars: true, theme: { colors: { primary: { main: '#dd5522' } } }, }} />
from redoc-try.
Is the entire feature enabled? Or trigger a test of a single API via an event?
Neither of the above two functions currently has a direct way.
from redoc-try.
Related Issues (20)
- FastApi integration HOT 3
- Something went wrong. HOT 1
- Examples not working HOT 6
- Error in the JS HOT 1
- How to use HOT 2
- FailureURL scheme must be "http" or "https" for CORS request HOT 1
- redoc-try causes wrong menu item highlighting when using anchor HOT 4
- use modal HOT 1
- reading json from static file
- problem in design HOT 2
- Support openAPI relative path HOT 10
- Try it option only works with spec url, it doesn't work when openApi spec is given as json object HOT 2
- overlapping other endpoints header HOT 7
- How to use redoc-try as react component? HOT 2
- Operation bloc not reset HOT 15
- Overlapping the try it window with the response details in Mobile view HOT 24
- OpenAPI 3.1 support HOT 2
- Authorization doesn't have the expand icon to show auth details HOT 1
- Height type error
- Not compatible with Redoc v 2.0-rc.33 or above HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from redoc-try.