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

@CookieValue is not parsed correctly #2798

Open
jaydenlin opened this issue Nov 27, 2018 · 7 comments
Open

@CookieValue is not parsed correctly #2798

jaydenlin opened this issue Nov 27, 2018 · 7 comments

Comments

@jaydenlin
Copy link

@jaydenlin jaydenlin commented Nov 27, 2018

I used @CookieValue but the argument is parsed as body parameter instead.
Could you help fix this issue ?

@dilipkrish
Copy link
Member

@dilipkrish dilipkrish commented Nov 28, 2018

Cookies arent supported directly, you could write your own ParameterBuilderPlugin to support it, but I agree that it would be nice to have native support

@mmsoares
Copy link

@mmsoares mmsoares commented Jan 28, 2019

I second @jaydenlin. This feature would be really appreciated.
Until this feature is supported natively, I have written a custom ParameterBuilderPlugin as suggested by @dilipkrish. I am pasting it here so that other people reading this issue don't have to spend a couple of hours figuring out how to write it (as I had to) :)

Using Springfox 2.4.0:

@Component
@Order(SwaggerPluginSupport.SWAGGER_PLUGIN_ORDER + 1000)
public class SwaggerCustomParameterBuilderPlugin implements ParameterBuilderPlugin {

    @Override
    public void apply(ParameterContext context) {
        if (isCookieValue(context)) {
            context.parameterBuilder().parameterType("cookie");
        }
    }

    private boolean isCookieValue(ParameterContext context) {
        return Arrays.stream(context.methodParameter().getParameterAnnotations())
                .anyMatch(annotation -> annotation.annotationType() == CookieValue.class);
    }

    @Override
    public boolean supports(DocumentationType documentationType) {
        return pluginDoesApply(documentationType);
    }
}

@mwinteringham
Copy link

@mwinteringham mwinteringham commented Apr 10, 2019

+1 to @jaydenlin's request. It's a little frustrating to have to create so much extra config for one parameter. However, thanks to @mmsoares for the workaround config I have what I need. I had to update my isCookieValue slightly to allow for the deprecated methodParameter()

Using Springfox 2.9.2:

@Component
@Order(SwaggerPluginSupport.SWAGGER_PLUGIN_ORDER + 1000)
public class SwaggerCustomParameterBuilderPlugin implements ParameterBuilderPlugin {

    @Override
    public void apply(ParameterContext context) {
        if (isCookieValue(context)) {
            context.parameterBuilder().parameterType("cookie");
        }
    }

    private boolean isCookieValue(ParameterContext context) {
        List<Annotation> annotations = context.resolvedMethodParameter().getAnnotations();
        return annotations.stream().anyMatch(annotation -> annotation.annotationType() == CookieValue.class);
    }

    @Override
    public boolean supports(DocumentationType documentationType) {
        return pluginDoesApply(documentationType);
    }

}

@vlk32
Copy link

@vlk32 vlk32 commented Jun 24, 2020

+1

This makes me crazy.
I started without parameters, everything works.
I've added a @CookieValue, without swagger GUI-reload, everything still works.
I've added new methods, swagger reload, new method works.
So I've add next few methods, swagger reload, new method still works.
I've decided to move first method, swagger reload, and the first one method wasn't possible run thru swagger GUI :-(
I've spent a few hour of finding bug in my own code :-(

Many thanks for workaround. Because there is no imports, the last method should be :

    @Override
    public boolean supports(DocumentationType documentationType) {
        return SwaggerPluginSupport.pluginDoesApply(documentationType);
    }

@dilipkrish dilipkrish added this to the 3.0 milestone Jun 25, 2020
@dilipkrish
Copy link
Member

@dilipkrish dilipkrish commented Jun 25, 2020

I'll try to fix this if possible.

@mwinteringham
Copy link

@mwinteringham mwinteringham commented Sep 25, 2020

I've just bumped up to v3 and this issue has come back for me again (as in the solution above no longer works for me). I see parameterBuilder has been deprecated and assume it needs to be replaced with something else. Would you be able to share what that is @dilipkrish

@Kisamaksim
Copy link

@Kisamaksim Kisamaksim commented Nov 21, 2020

after added @CookieValue, example values for my request body are gone...it's really annoying

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

Successfully merging a pull request may close this issue.

None yet
6 participants