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

A question about resource path processing #2348

Closed
superDao opened this issue Aug 17, 2023 · 2 comments
Closed

A question about resource path processing #2348

superDao opened this issue Aug 17, 2023 · 2 comments
Labels
bug Something isn't working

Comments

@superDao
Copy link

Describe the bug
webjars subdirectory resource 404 found after using springdoc

To Reproduce

spring-boot 3.1.2

springdoc-openapi-starter-webflux-ui 2.2.0

http://localhost:8087/webjars/swagger-ui/swagger-ui.css It is ok

springdoc The request path was changed to match the version number

org.springdoc.webflux.ui.SwaggerResourceResolver::resolveResource -> org.springdoc.ui.AbstractSwaggerResourceResolver::findWebJarResourcePath

swagger-ui/index.html -> swagger-ui\5.2.0\index.html

微信图片_20230817133716 微信截图_20230817134218

<img width="817" alt="微信截图_20230817134218" src="微信图片_20230817134258">

Other Jar resources
http://localhost:8087/webjars/aa/bb.html 404

aa/bb.html -> aa/5.2.0/bb.html

It is recommended that the path starting with swagger-ui be processed

@rainzhou2012
Copy link

From v2.1.0, webjars-locator-core was removed, WebJarsResourceResolver insteads by SwaggerResourceResolver. Looks like SwaggerResourceResolver isn't implemented right.

	@Override
	public Mono<Resource> resolveResource(ServerWebExchange exchange, String requestPath, List<? extends Resource> locations, ResourceResolverChain chain) {
		Mono<Resource> resolved = chain.resolveResource(exchange, requestPath, locations);
		if (!Mono.empty().equals(resolved)) {
			String webJarResourcePath = findWebJarResourcePath(requestPath);
			if (webJarResourcePath != null)
				return chain.resolveResource(exchange, webJarResourcePath, locations);
		}
		return resolved;
	}

it's wrong to compare resolved and mono.empty by equals, should same as WebJarsResourceResolver.

	@Override
	protected Mono<Resource> resolveResourceInternal(@Nullable ServerWebExchange exchange,
			String requestPath, List<? extends Resource> locations, ResourceResolverChain chain) {

		return chain.resolveResource(exchange, requestPath, locations)
				.switchIfEmpty(Mono.defer(() -> {
					String webJarsResourcePath = findWebJarResourcePath(requestPath);
					if (webJarsResourcePath != null) {
						return chain.resolveResource(exchange, webJarsResourcePath, locations);
					}
					else {
						return Mono.empty();
					}
				}));
	}

@bnasslahsen bnasslahsen added the bug Something isn't working label Dec 2, 2023
@bnasslahsen
Copy link
Contributor

@superDao,

Good finding!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants