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

Extend openapi with support for .json and .yaml extension besides the current content negotiation mechanism #21567

Closed
sjaakd opened this issue Nov 19, 2021 · 2 comments · Fixed by #22523
Assignees
Milestone

Comments

@sjaakd
Copy link

sjaakd commented Nov 19, 2021

Description

The swagger documentation refers to a mechanism were .json and .yaml is used as extension on the openapi / swagger URL .

Other standards like this one, seem to extend upon that.

See also discussion in: #21457

Implementation ideas

Currently, I have implemented this as a vertx.RouteFilter. That does the trick. I've found this solution on other places, like this one. So I guess there's more demand for this feature.

    @RouteFilter
    public void modifyAcceptHeader(RoutingContext rc) {
        String url = rc.normalizedPath();
        if ( url.endsWith( "openapi.json" ) ) {
            String acceptHeader = rc.request().headers().get( ACCEPT );
            if ( acceptHeader != null && !acceptHeader.contains( "yaml" ) ) {
                rc.request().headers().set( ACCEPT, "application/json" );
            }
            rc.reroute(  url.substring( 0, url.lastIndexOf( '.' ) ) );
            return;
        }
        else if ( url.endsWith( "openapi.yaml" ) ) {
            rc.reroute(  url.substring( 0, url.lastIndexOf( '.' ) ) );
            return;
        }
        rc.next();
    }
@quarkus-bot
Copy link

quarkus-bot bot commented Nov 19, 2021

@phillip-kruger phillip-kruger self-assigned this Nov 19, 2021
@phillip-kruger
Copy link
Member

Thanks :)

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

Successfully merging a pull request may close this issue.

3 participants