can t find swagger

trying to use swagger but it doesn t work
168 Replies
JavaBot
JavaBot4mo ago
This post has been reserved for your question.
Hey @Timo! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically marked as dormant after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
Timo
TimoOP4mo ago
No description
dan1st
dan1st4mo ago
Why do you expect it to work? How did you set it up? What is the exact response you are getting?
Timo
TimoOP4mo ago
i expect this path to work added the depency and this:
Timo
TimoOP4mo ago
No description
dan1st
dan1st4mo ago
Which dependency? and what is that?
Timo
TimoOP4mo ago
server.servlet.context-path=/api could this be the problem
dan1st
dan1st4mo ago
then I think the path would be /api/swagger-ui
Timo
TimoOP4mo ago
No description
Timo
TimoOP4mo ago
No description
Timo
TimoOP4mo ago
no still won t find it
ayylmao123xdd
ayylmao123xdd4mo ago
try swagger-ui.html maybe you are using some old version show the dependencies for swagger
Timo
TimoOP4mo ago
No description
Timo
TimoOP4mo ago
No description
ayylmao123xdd
ayylmao123xdd4mo ago
yea thats your address
Timo
TimoOP4mo ago
normally don t have this need to login to acces it but it is in a public path?
ayylmao123xdd
ayylmao123xdd4mo ago
maybe you need to add with the /api prefix
Timo
TimoOP4mo ago
added that
Timo
TimoOP4mo ago
No description
ayylmao123xdd
ayylmao123xdd4mo ago
then theres something wrong with your jwt config ig or security config can you disable it for a second
Timo
TimoOP4mo ago
@Component
public class JWTFilter extends OncePerRequestFilter {
private static final String BEARER_PREFIX = "Bearer ";


private static final List<RequestMatcher> PUBLIC_URLS =
Arrays.stream(SecurityConfig.PUBLIC_URL_PATTERNS)
.map(p -> (RequestMatcher) new AntPathRequestMatcher(p))
.toList();
@Autowired
public JWTFilter(
UserService userService,
JWTUtil jwtTokenUtil,
UserRepository userRepository
) {
this.userService = userService;
this.jwtTokenUtil = jwtTokenUtil;
this.userRepository = userRepository;
}

@Override
protected boolean shouldNotFilter(HttpServletRequest request) {
return PUBLIC_URLS.stream().anyMatch(m -> m.matches(request));
}
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
final Optional<String> authHeader = Optional.ofNullable(request.getHeader("Authorization"));

if(authHeader.isPresent()) {
authHeader
.map(header -> header.substring(BEARER_PREFIX.length()))
.map(jwtTokenUtil::validateTokenAndRetrieveSubject)
.map(email -> userRepository
.findByEmail(email)
.orElseThrow(() -> new IllegalArgumentException("Invalid bearer token")))
.ifPresent(user -> {
UserDetails userDetails = userService.loadUserByUsername(user.getEmail());
UsernamePasswordAuthenticationToken authToken = new UsernamePasswordAuthenticationToken(user, userDetails.getPassword(), userDetails.getAuthorities());
SecurityContextHolder.getContext().setAuthentication(authToken);
});
}
filterChain.doFilter(request, response);
}
}
@Component
public class JWTFilter extends OncePerRequestFilter {
private static final String BEARER_PREFIX = "Bearer ";


private static final List<RequestMatcher> PUBLIC_URLS =
Arrays.stream(SecurityConfig.PUBLIC_URL_PATTERNS)
.map(p -> (RequestMatcher) new AntPathRequestMatcher(p))
.toList();
@Autowired
public JWTFilter(
UserService userService,
JWTUtil jwtTokenUtil,
UserRepository userRepository
) {
this.userService = userService;
this.jwtTokenUtil = jwtTokenUtil;
this.userRepository = userRepository;
}

@Override
protected boolean shouldNotFilter(HttpServletRequest request) {
return PUBLIC_URLS.stream().anyMatch(m -> m.matches(request));
}
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
final Optional<String> authHeader = Optional.ofNullable(request.getHeader("Authorization"));

if(authHeader.isPresent()) {
authHeader
.map(header -> header.substring(BEARER_PREFIX.length()))
.map(jwtTokenUtil::validateTokenAndRetrieveSubject)
.map(email -> userRepository
.findByEmail(email)
.orElseThrow(() -> new IllegalArgumentException("Invalid bearer token")))
.ifPresent(user -> {
UserDetails userDetails = userService.loadUserByUsername(user.getEmail());
UsernamePasswordAuthenticationToken authToken = new UsernamePasswordAuthenticationToken(user, userDetails.getPassword(), userDetails.getAuthorities());
SecurityContextHolder.getContext().setAuthentication(authToken);
});
}
filterChain.doFilter(request, response);
}
}
Timo
TimoOP4mo ago
No description
Timo
TimoOP4mo ago
No description
Timo
TimoOP4mo ago
so yeah
dan1st
dan1st4mo ago
What happens with that?
ayylmao123xdd
ayylmao123xdd4mo ago
@Override
protected boolean shouldNotFilter(HttpServletRequest request) {
return PUBLIC_URLS.stream().anyMatch(m -> m.matches(request));
}
@Override
protected boolean shouldNotFilter(HttpServletRequest request) {
return PUBLIC_URLS.stream().anyMatch(m -> m.matches(request));
}
dont you need to like
Timo
TimoOP4mo ago
security for register and login
ayylmao123xdd
ayylmao123xdd4mo ago
compare the request url instead of the whole object try
@Override
protected boolean shouldNotFilter(HttpServletRequest request) {
return PUBLIC_URLS.stream().anyMatch(m -> m.matches(request.getServletPath()));
}
@Override
protected boolean shouldNotFilter(HttpServletRequest request) {
return PUBLIC_URLS.stream().anyMatch(m -> m.matches(request.getServletPath()));
}
Timo
TimoOP4mo ago
No description
ayylmao123xdd
ayylmao123xdd4mo ago
lol interesting
Timo
TimoOP4mo ago
daniel you know what would be handy?
dan1st
dan1st4mo ago
What exactly happens now when you access the URL?
ayylmao123xdd
ayylmao123xdd4mo ago
No description
ayylmao123xdd
ayylmao123xdd4mo ago
seems to be some problem with jwt setup doesnt ignore endpoints with permitall or something
dan1st
dan1st4mo ago
Can you show your JWTFilter? as text in a code block ideally
ayylmao123xdd
ayylmao123xdd4mo ago
for me the should not filter method is wrong
dan1st
dan1st4mo ago
ah you already did AntPathRequestMatcher#matches accepts the HttpServletRequest though AntPathRequestMatcher is deprecated for removal in favor of PathPatternRequestMatcher anyway
Timo
TimoOP4mo ago
so what should i do didn t think adding a depency would be this hard lol
ayylmao123xdd
ayylmao123xdd4mo ago
can you show the public urls
Timo
TimoOP4mo ago
this but with api in front of the last 4
ayylmao123xdd
ayylmao123xdd4mo ago
for testing purposes
@Override
protected boolean shouldNotFilter(HttpServletRequest request) {
return true;
}
@Override
protected boolean shouldNotFilter(HttpServletRequest request) {
return true;
}
try this and try to access that swagger endpoint what its just for testing ur gonna switch it back later
Timo
TimoOP4mo ago
No description
Timo
TimoOP4mo ago
No description
ayylmao123xdd
ayylmao123xdd4mo ago
ha i knew it i guess you need to add /api/api-docs to public urls too
Timo
TimoOP4mo ago
why ?
ayylmao123xdd
ayylmao123xdd4mo ago
because swagger cant access it
Timo
TimoOP4mo ago
but why api api where does the 2nd one come from?
Timo
TimoOP4mo ago
No description
Timo
TimoOP4mo ago
wrong
ayylmao123xdd
ayylmao123xdd4mo ago
wdym wrong did you add api docs to public url
Timo
TimoOP4mo ago
No description
Timo
TimoOP4mo ago
was alr in there\
ayylmao123xdd
ayylmao123xdd4mo ago
but it says v3 and it cant access /api/api-docs
Timo
TimoOP4mo ago
had api first but you said api api
ayylmao123xdd
ayylmao123xdd4mo ago
no i meant that you need to add api/api-docs to public urls
Timo
TimoOP4mo ago
so what should it be now then imconfused
ayylmao123xdd
ayylmao123xdd4mo ago
get rid of the second api and in public urls add
"api/api-docs"
"api/api-docs"
lol
Timo
TimoOP4mo ago
like this?
No description
ayylmao123xdd
ayylmao123xdd4mo ago
yes
Timo
TimoOP4mo ago
No description
ayylmao123xdd
ayylmao123xdd4mo ago
interesting show the console output in intellij
Timo
TimoOP4mo ago
No description
Timo
TimoOP4mo ago
🙃
ayylmao123xdd
ayylmao123xdd4mo ago
my honest reaction try to do mvn clean compile
Timo
TimoOP4mo ago
you don t know?
ayylmao123xdd
ayylmao123xdd4mo ago
see if that helps dont know what
Timo
TimoOP4mo ago
how to fix it :/
ayylmao123xdd
ayylmao123xdd4mo ago
try this never had that happen with swagger but lets see lmao
Timo
TimoOP4mo ago
compile java?
No description
ayylmao123xdd
ayylmao123xdd4mo ago
oh lmao gradle detected
Timo
TimoOP4mo ago
no shitt
ayylmao123xdd
ayylmao123xdd4mo ago
./gradlew clean buildJava
Timo
TimoOP4mo ago
No description
Timo
TimoOP4mo ago
can one of those work?
ayylmao123xdd
ayylmao123xdd4mo ago
if you want to do it in 2 requests then sure first do clean then compilejava
Timo
TimoOP4mo ago
don t think it is gonna help tho 11:02:21 pm: Execution finished 'compileJava'. done
ayylmao123xdd
ayylmao123xdd4mo ago
yea launch the app again and go to that swagger view
Timo
TimoOP4mo ago
No description
Timo
TimoOP4mo ago
yep nothing changed :thonk:
ayylmao123xdd
ayylmao123xdd4mo ago
:GnuTrolling: in app properties did u set anything like springdoc api docs path check in app logs if it says anything like starting openapi documentation
Timo
TimoOP4mo ago
Yep
ayylmao123xdd
ayylmao123xdd4mo ago
show and check what this log says
Timo
TimoOP4mo ago
springdoc.api-docs.path=/api-docs
ayylmao123xdd
ayylmao123xdd4mo ago
then you can remove the /v3/api-docs cuz u dont need it type in browser this url
localhost:8080/api/api-docs
localhost:8080/api/api-docs
Timo
TimoOP4mo ago
No description
ayylmao123xdd
ayylmao123xdd4mo ago
see what it shows
Timo
TimoOP4mo ago
No description
dan1st
dan1st4mo ago
I think probably without the /api there
Timo
TimoOP4mo ago
No description
ayylmao123xdd
ayylmao123xdd4mo ago
but it throws error 500
Timo
TimoOP4mo ago
404
ayylmao123xdd
ayylmao123xdd4mo ago
not 403 or 401 anyway type that in browser
dan1st
dan1st4mo ago
I think you have an @ControllerAdvice with weird constructors
ayylmao123xdd
ayylmao123xdd4mo ago
or is it this
Timo
TimoOP4mo ago
yep
ayylmao123xdd
ayylmao123xdd4mo ago
then the endpoint works but swagger is oging crazy
Timo
TimoOP4mo ago
2025-06-26T23:10:27.783+02:00 ERROR 32596 --- [Backend NTR-Website] [nio-8080-exec-1] c.e.b.exception.ForumExceptionHandler : Unexpected error: Handler dispatch failed: java.lang.NoSuchMethodError: 'void org.springframework.web.method.ControllerAdviceBean.<init>(java.lang.Object)'
ayylmao123xdd
ayylmao123xdd4mo ago
looks like version conflict tbh
dan1st
dan1st4mo ago
or that
Timo
TimoOP4mo ago
No description
dan1st
dan1st4mo ago
Can you show the whole class? but yes check your dependencies
Timo
TimoOP4mo ago
Pastebin
package com.example.backend.exception;import lombok.extern.slf4j.Sl...
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
ayylmao123xdd
ayylmao123xdd4mo ago
u know u can just paste it here as text lol
Timo
TimoOP4mo ago
No description
ayylmao123xdd
ayylmao123xdd4mo ago
whats the spring version spring boot
Timo
TimoOP4mo ago
No description
dan1st
dan1st4mo ago
What's your springdoc/swagger dependency?
Timo
TimoOP4mo ago
//swagger?
ayylmao123xdd
ayylmao123xdd4mo ago
idk how gradle exactly works but maybe clean and buildjava werent enough to rebuild target etc
dan1st
dan1st4mo ago
the dependency that should add the swagger ui and openapi spec
Timo
TimoOP4mo ago
this is not all?
dan1st
dan1st4mo ago
ah didn't see the last line on mobile
Timo
TimoOP4mo ago
so how can i fix this lmao
ayylmao123xdd
ayylmao123xdd4mo ago
uhhhhh whats the like gradle thing to clean target rebuild it and refresh dependencies
Timo
TimoOP4mo ago
alr did that :boohoo:
dan1st
dan1st4mo ago
try updating springdoc to 2.8.9
Timo
TimoOP4mo ago
wich one?
ayylmao123xdd
ayylmao123xdd4mo ago
the one u got at 2.5.0
Timo
TimoOP4mo ago
so swagger?
ayylmao123xdd
ayylmao123xdd4mo ago
yes
Timo
TimoOP4mo ago
done
Timo
TimoOP4mo ago
No description
Timo
TimoOP4mo ago
bruh it was retarted indeed
ayylmao123xdd
ayylmao123xdd4mo ago
now try the swagger ui endpoint
Timo
TimoOP4mo ago
that was XD i forgot
ayylmao123xdd
ayylmao123xdd4mo ago
gdhdlhkrjhelkg
Timo
TimoOP4mo ago
whut
Timo
TimoOP4mo ago
No description
Timo
TimoOP4mo ago
ok cool how can i nicely document it?
ayylmao123xdd
ayylmao123xdd4mo ago
wdym nicely document
Timo
TimoOP4mo ago
No description
Timo
TimoOP4mo ago
have it like this now lmaoi
ayylmao123xdd
ayylmao123xdd4mo ago
on your controller you can add stuff like
@Tag(name = "gkdsjgdfklgjeklrghjelhkjrehekl)
public class blablacontroller {}
@Tag(name = "gkdsjgdfklgjeklrghjelhkjrehekl)
public class blablacontroller {}
i mean the tag annotation
Timo
TimoOP4mo ago
don t understand
ayylmao123xdd
ayylmao123xdd4mo ago
what show one of your controllers show replies controller code
Timo
TimoOP4mo ago
No description
ayylmao123xdd
ayylmao123xdd4mo ago
no in code basically when you have a controller
Timo
TimoOP4mo ago
i can just take the path and the example data and show that?
ayylmao123xdd
ayylmao123xdd4mo ago
wdym it generates automatically
Timo
TimoOP4mo ago
to document it lol
Timo
TimoOP4mo ago
here
No description
ayylmao123xdd
ayylmao123xdd4mo ago
then show the code for the controller that you got for this cms thing
Timo
TimoOP4mo ago
Why do you need the controller code You wanna know the path and the expected data?
ayylmao123xdd
ayylmao123xdd4mo ago
to show you how to add the description lmao
Timo
TimoOP4mo ago
Ok lol
bokutoc
bokutoc4mo ago
public CMSController(CMSService cmsService) {
this.cmsService = cmsService;
}

@GetMapping("/test")
public String fetch() {
System.out.println("==> Controller /cms/test aangeroepen");
return cmsService.fetchHTTP();
}

@GetMapping("/route/{id}")
public Map<String, Object> getRoute(@PathVariable int id) {
System.out.println("==> Controller /cms/route/" + id + " aangeroepen");
return cmsService.getRoute(id);
}

@GetMapping("/routes")
public List<Map<String, Object>> getAllRoutes() {
System.out.println("==> Controller /cms/routes aangeroepen");
return cmsService.getAllRoutes();
}
public CMSController(CMSService cmsService) {
this.cmsService = cmsService;
}

@GetMapping("/test")
public String fetch() {
System.out.println("==> Controller /cms/test aangeroepen");
return cmsService.fetchHTTP();
}

@GetMapping("/route/{id}")
public Map<String, Object> getRoute(@PathVariable int id) {
System.out.println("==> Controller /cms/route/" + id + " aangeroepen");
return cmsService.getRoute(id);
}

@GetMapping("/routes")
public List<Map<String, Object>> getAllRoutes() {
System.out.println("==> Controller /cms/routes aangeroepen");
return cmsService.getAllRoutes();
}
This message has been formatted automatically. You can disable this using /preferences.
ayylmao123xdd
ayylmao123xdd4mo ago
ok try this wait the whole class smh
bokutoc
bokutoc4mo ago
package com.example.backend.controller; import com.example.backend.services.CMSService; import org.springframework.web.bind.annotation.*; import java.util.List; import java.util.Map; @RestController @RequestMapping("/cms")
public class CMSController {

private final CMSService cmsService;

public CMSController(CMSService cmsService) {
this.cmsService = cmsService;
}

@GetMapping("/test")
public String fetch() {
System.out.println("==> Controller /cms/test aangeroepen");
return cmsService.fetchHTTP();
}

@GetMapping("/route/{id}")
public Map<String, Object> getRoute(@PathVariable int id) {
System.out.println("==> Controller /cms/route/" + id + " aangeroepen");
return cmsService.getRoute(id);
}

@GetMapping("/routes")
public List<Map<String, Object>> getAllRoutes() {
System.out.println("==> Controller /cms/routes aangeroepen");
return cmsService.getAllRoutes();
}

}
public class CMSController {

private final CMSService cmsService;

public CMSController(CMSService cmsService) {
this.cmsService = cmsService;
}

@GetMapping("/test")
public String fetch() {
System.out.println("==> Controller /cms/test aangeroepen");
return cmsService.fetchHTTP();
}

@GetMapping("/route/{id}")
public Map<String, Object> getRoute(@PathVariable int id) {
System.out.println("==> Controller /cms/route/" + id + " aangeroepen");
return cmsService.getRoute(id);
}

@GetMapping("/routes")
public List<Map<String, Object>> getAllRoutes() {
System.out.println("==> Controller /cms/routes aangeroepen");
return cmsService.getAllRoutes();
}

}
ok pookie
This message has been formatted automatically. You can disable this using /preferences.
ayylmao123xdd
ayylmao123xdd4mo ago
@RestController
@RequestMapping("/cms")
@Tag(name = "CMS stuffffff")
public class CMSController {

private final CMSService cmsService;

public CMSController(CMSService cmsService) {
this.cmsService = cmsService;
}

@Operation(summary = "summary1lol", description = "description1ezezez")
@GetMapping("/test")
public String fetch() {
System.out.println("==> Controller /cms/test aangeroepen");
return cmsService.fetchHTTP();
}

@Operation(summary = "summary2lol", description = "description2ezezez")
@GetMapping("/route/{id}")
public Map<String, Object> getRoute(@PathVariable int id) {
System.out.println("==> Controller /cms/route/" + id + " aangeroepen");
return cmsService.getRoute(id);
}

@Operation(summary = "summary3lol", description = "description3ezezez")
@GetMapping("/routes")
public List<Map<String, Object>> getAllRoutes() {
System.out.println("==> Controller /cms/routes aangeroepen");
return cmsService.getAllRoutes();
}

}
@RestController
@RequestMapping("/cms")
@Tag(name = "CMS stuffffff")
public class CMSController {

private final CMSService cmsService;

public CMSController(CMSService cmsService) {
this.cmsService = cmsService;
}

@Operation(summary = "summary1lol", description = "description1ezezez")
@GetMapping("/test")
public String fetch() {
System.out.println("==> Controller /cms/test aangeroepen");
return cmsService.fetchHTTP();
}

@Operation(summary = "summary2lol", description = "description2ezezez")
@GetMapping("/route/{id}")
public Map<String, Object> getRoute(@PathVariable int id) {
System.out.println("==> Controller /cms/route/" + id + " aangeroepen");
return cmsService.getRoute(id);
}

@Operation(summary = "summary3lol", description = "description3ezezez")
@GetMapping("/routes")
public List<Map<String, Object>> getAllRoutes() {
System.out.println("==> Controller /cms/routes aangeroepen");
return cmsService.getAllRoutes();
}

}
try this
Timo
TimoOP4mo ago
why tf would i change my code
ayylmao123xdd
ayylmao123xdd4mo ago
to add description duh
Timo
TimoOP4mo ago
no need
ayylmao123xdd
ayylmao123xdd4mo ago
what
Timo
TimoOP4mo ago
daniel is asleep otherwise i would summon him and ask what tf you are talking about XD
ayylmao123xdd
ayylmao123xdd4mo ago
you add this stuff so on swagger it generates the description automatically thats the whole point of using swagger lmao you put the description in the code try it out u will see it update on the page
Timo
TimoOP4mo ago
No description
Timo
TimoOP4mo ago
yeah but that doesn t help much it is about the doc so only need the path and the input lol
ayylmao123xdd
ayylmao123xdd4mo ago
wdym you want the example request to be populated with real data or like whats ur goal
Timo
TimoOP4mo ago
to write the doc with paths and data that needs to be sent so it is done ig don t know what you are trying to add :thonk:
ayylmao123xdd
ayylmao123xdd4mo ago
so example parameters lmao when sending a request to backend yes like idk what u want to write when u mean paths and data
Timo
TimoOP4mo ago
No description
Timo
TimoOP4mo ago
just this but cleaner so future devs can easily dive into the project itself
ayylmao123xdd
ayylmao123xdd4mo ago
so just the description then you add it here in the operation annotation either to summary or description thing
Timo
TimoOP4mo ago
no need but whatever thank you for the help 😅
JavaBot
JavaBot4mo ago
If you are finished with your post, please close it. If you are not, please ignore this message. Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.
JavaBot
JavaBot4mo ago
Post Closed
This post has been closed by <@591288621345275915>.

Did you find this page helpful?