0

i would like to conditionally hide an endpoint i put in just for dev and test environments but i am having trouble...

@Value("${spring.profiles.active}")
String deployEnv;

@Profile("!prod")
@io.swagger.v3.oas.annotations.Operation(summary="this is just used in dev and test", hidden=#{deployEnv.toLowerCase().indexOf('prod')>=0})
...
public String generateToken() {
...
}

i've tried different variations of spel to make the hidden field work but to no avail. of course, if i just use true or false hard coded then it works fine but that's not what i want.

user2052618
  • 556
  • 2
  • 7
  • 20
  • What library/framework do you use - Springfox, Springdoc, ...? – Helen Dec 15 '21 at 18:34
  • i use springdoc-openapi-ui 1.4.3 – user2052618 Dec 15 '21 at 19:31
  • do you want to hide the endpoint or only the documentation? – xerx593 Dec 15 '21 at 21:58
  • "Any `@Component, @Configuration` or `@ConfigurationProperties` (...) can be marked with `@Profile`" ...[Spring Boot Doc:Core:Profiles](https://docs.spring.io/spring-boot/docs/current/reference/html/features.html#features.profiles) – xerx593 Dec 15 '21 at 22:10
  • yes, i had the @Profile in my post since the beginning. it works to stop the use of the endpoint but no one wants to see something they can't use. so i want to hide the endpoint from being displayed, in prod only, by the swagger ui. that's what my question is all about. – user2052618 Dec 17 '21 at 01:44
  • after reading the error i get: "element value must be a constant expression", and then reading this... https://riptutorial.com/java/example/26261/constant-expressions i have come to the conclusion that it is not possible. the value must be evaluated at compile time to a literal. – user2052618 Dec 17 '21 at 16:47
  • also, doesn't look like the @Profile("!prod") isn't working either. i changed it to @Profile("!local") and a ran the app on my local and deployEnv was "local" but it still went into the controller method. – user2052618 Dec 17 '21 at 19:30

0 Answers0