question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

@CookieValue is not parsed correctly

See original GitHub issue

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

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

4reactions
mwinteringhamcommented, 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);
    }

}
2reactions
mmsoarescommented, 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);
    }
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Developers - @CookieValue is not parsed correctly - - Bountysource
CookieValue is not parsed correctly. ... I used @CookieValue but the argument is parsed as body parameter instead. Could you help fix this...
Read more >
Safari not saving cookie value correctly - Stack Overflow
Cookie values can't contain spaces, which your JSON does have. Try to properly encode it using encodeURIComponent() . – Ivar. 8 mins ago....
Read more >
If Cookie value is JSON string, then it is not - JBoss.org
When the cookie with JSON object is sent to wildfly 8.1 container, then it is not getting parsed correctly. If that JSON string...
Read more >
setcookie - Manual - PHP
But why do you make it so complicated and risk it not working, when the client's time ... setcookie('TestCookie', 'The Cookie Value', $arr_cookie_options);...
Read more >
Set Cookies with Google Tag Manager (also read and delete ...
Unfortunately, I still see many marketers (working with GTM) suffering over not being able to fire Tags for returning visitors, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found