Skip to content
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

Remove redundant authorization button #6446

Merged
merged 1 commit into from
Jun 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"react-router-dom": "^4.4.0-alpha.1",
"react-tap-event-plugin": "^2.0.1",
"swagger-client": "3.4.8",
"swagger-ui-react": "^3.22.2"
"swagger-ui": "^3.22.2"
},
"devDependencies": {
"babel-core": "^6.24.1",
Expand Down Expand Up @@ -76,9 +76,10 @@
"mock-local-storage": "^1.0.5",
"react-test-renderer": "^16.7.0",
"sinon": "^7.2.2",
"source-map-loader": "^0.2.4",
"style-loader": "^0.18.1",
"webpack": "v4.28.4",
"webpack-cli": "^3.3.2",
"webpack-bundle-analyzer": "^3.2.0"
"webpack-bundle-analyzer": "^3.2.0",
"webpack-cli": "^3.3.2"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import React from 'react';
import Grid from '@material-ui/core/Grid';
import Typography from '@material-ui/core/Typography';
import PropTypes from 'prop-types';
import 'swagger-ui-react/swagger-ui.css';
import TextField from '@material-ui/core/TextField';
import { withStyles } from '@material-ui/core/styles';
import IconButton from '@material-ui/core/IconButton';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
import React from 'react';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

License header is missing

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure whether we could add this with our lisence header , Because I have took this from
swagger-ui-react repo.
@TanyaM WDYT ?

import PropTypes from 'prop-types';
import swaggerUIConstructor, { presets } from 'swagger-ui';

/**
*
*
* @export
* @class SwaggerUI
* @extends {React.Component}
*/
export default class SwaggerUI extends React.Component {
constructor(props) {
super(props);
this.SwaggerUIComponent = null;
this.system = null;
}

/**
*
*
* @memberof SwaggerUI
*/
componentDidMount() {
const ui = swaggerUIConstructor({
spec: this.props.spec,
url: this.props.url,
defaultModelsExpandDepth: this.props.defaultModelsExpandDepth,
presets: [presets.apis, ...this.props.presets],
requestInterceptor: this.requestInterceptor,
responseInterceptor: this.responseInterceptor,
onComplete: this.onComplete,
docExpansion: this.props.docExpansion,
});

this.system = ui;
this.SwaggerUIComponent = ui.getComponent('App', 'root');

this.forceUpdate();
}

/**
*
*
* @param {*} prevProps
* @memberof SwaggerUI
*/
componentDidUpdate(prevProps) {
if (this.props.url !== prevProps.url) {
// flush current content
this.system.specActions.updateSpec('');

if (this.props.url) {
// update the internal URL
this.system.specActions.updateUrl(this.props.url);
// trigger remote definition fetch
this.system.specActions.download(this.props.url);
}
}

if (this.props.spec !== prevProps.spec && this.props.spec) {
if (typeof this.props.spec === 'object') {
this.system.specActions.updateSpec(JSON.stringify(this.props.spec));
} else {
this.system.specActions.updateSpec(this.props.spec);
}
}
}

requestInterceptor = (req) => {
if (typeof this.props.requestInterceptor === 'function') {
return this.props.requestInterceptor(req);
}
return req;
};

responseInterceptor = (res) => {
if (typeof this.props.responseInterceptor === 'function') {
return this.props.responseInterceptor(res);
}
return res;
};

onComplete = () => {
if (typeof this.props.onComplete === 'function') {
return this.props.onComplete(this.system);
}
};

render() {
return this.SwaggerUIComponent ? <this.SwaggerUIComponent /> : null;
}
}
SwaggerUI.defaultProps = {
docExpansion: 'list',
defaultModelsExpandDepth: 1,
presets: [],
};

SwaggerUI.propTypes = {
spec: PropTypes.oneOf([PropTypes.string, PropTypes.object]),
url: PropTypes.string,
defaultModelsExpandDepth: PropTypes.number,
requestInterceptor: PropTypes.func,
responseInterceptor: PropTypes.func,
onComplete: PropTypes.func,
docExpansion: PropTypes.oneOf(['list', 'full', 'none']),
presets: PropTypes.arrayOf(PropTypes.func),
};
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';
import PropTypes from 'prop-types';
import SwaggerUILib from 'swagger-ui-react';
import 'swagger-ui/dist/swagger-ui.css';
import SwaggerUILib from './PatchedSwaggerUIReact';

const disableAuthorizeAndInfoPlugin = function () {
return {
Expand All @@ -11,7 +12,6 @@ const disableAuthorizeAndInfoPlugin = function () {
};
};
/**
*
*
* @class SwaggerUI
* @extends {Component}
Expand All @@ -22,11 +22,15 @@ const SwaggerUI = (props) => {
const componentProps = {
spec,
validatorUrl: null,
docExpansion: 'list',
defaultModelsExpandDepth: 0,
requestInterceptor: (req) => {
req.headers.Authorization = 'Bearer ' + accessTokenProvider();
return req;
},

presets: [disableAuthorizeAndInfoPlugin],
plugins: null,
};
return <SwaggerUILib {...componentProps} />;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ const config = {
},
module: {
rules: [
{
test: /\.js$/,
use: ['source-map-loader'],
enforce: 'pre',
},
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
Expand Down