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

Add possibility to enable 'execute' button after endpoint click. #4792

Open
crisperit opened this issue Aug 5, 2018 · 3 comments
Open

Add possibility to enable 'execute' button after endpoint click. #4792

crisperit opened this issue Aug 5, 2018 · 3 comments

Comments

@crisperit
Copy link

crisperit commented Aug 5, 2018

Hello, I find something in my opinion that could be parameterized.

Every time when I want to make request through swagger-ui I need to make 3 action.
Click on element -> click on try it out -> click on execute.

I want to have easy possibility to short that action path to:
Click on element -> click on execute

I think that even after click on specific element scroll of the site could move to that button to make it event faster for user - especially if this is simple get request :)

Below description of problem with support of screens:

After click on specific endpoint element
1

I want to not must click on "Try it out" button
2

But instead to have Execute button available to click - just after clicking on endpoint element
3

Is this possible?

@m-demydiuk
Copy link

I really need this feature as well, as it is very annoying to click Try it out button every time. I did not find any solution, so I wrote a hack using jQuery

jQuery.noConflict();
jQuery(window).on('load',
    function () {
        setTimeout(function () {
            jQuery('.opblock-summary').click(function () {
                var $opBlockSummary = jQuery(this);
                setTimeout(function () {
                    var $tryIt = $opBlockSummary.closest('.opblock').find('.try-out__btn');
                    if (!$tryIt.hasClass('cancel')) {
                        $tryIt.click();
                    }
                },
                    100);
            });
        },
            1500);
    });

@crisperit
Copy link
Author

I use only pure Java in my project (springfox swagger-ui) soo im my case I can't use that kind of hack. But thanks anyway - maybe other person'll find it useful :D

@ElkanRoelen
Copy link

Hi,

We also needed this functionality, but without jQuery.
We wrote a hack to bypass the try-it-out button in plain JS in swagger-ui-express

And implemented it in express route:

router.get("/swagger.js", (req: express.Request, res: express.Response) => {
    res.sendFile("src/swagger.js", {root: path.join(process.cwd())})
});

src/swagger.js

document.addEventListener("DOMContentLoaded", function(event) {
    setTimeout(function () {
        document.querySelectorAll(".opblock-summary").forEach(item => {
            if(item.parentElement.classList.contains("is-open")) {
                setTimeout(function () {
                    var buttons = item.parentElement.getElementsByClassName("try-out__btn");
                    if (buttons) {
                        if (!buttons[0].classList.contains("cancel")) {
                            buttons[0].click();
                        }
                    }
                },
                100);
            }

            item.addEventListener("click",() => {
                setTimeout(function () {
                    var buttons = item.parentElement.getElementsByClassName("try-out__btn");
                    if (buttons) {
                        if (!buttons[0].classList.contains("cancel")) {
                            buttons[0].click();
                        }
                    }
                },
                100);
            });
        });
    },
    1500);
});

the JS file (swagger.js) is loaded during the start with the swaggerOptions:
main

const swaggerOptions = {
    customCss: ".try-out { display: none; }",
    customJs: "/swagger.js",
    swaggerOptions: {
        persistAuthorization: true,
    }
};

app.use("/doc", swaggerUi.serve, swaggerUi.setup(swaggerSpec, swaggerOptions));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants