mirror of
				https://github.com/Frooodle/Stirling-PDF.git
				synced 2025-11-01 01:21:18 +01:00 
			
		
		
		
	api changes to get metrics working
This commit is contained in:
		
							parent
							
								
									1b2df20fdd
								
							
						
					
					
						commit
						a497ad8c41
					
				@ -30,10 +30,14 @@ public class MetricsFilter extends OncePerRequestFilter {
 | 
			
		||||
 | 
			
		||||
		// System.out.println("uri="+uri + ", method=" + request.getMethod() );
 | 
			
		||||
		// Ignore static resources
 | 
			
		||||
        if (!(uri.startsWith("/js") || uri.startsWith("api-docs") || uri.endsWith("robots.txt") || uri.startsWith("/images") || uri.endsWith(".png") || uri.endsWith(".ico") || uri.endsWith(".css") || uri.endsWith(".svg")|| uri.endsWith(".js") || uri.contains("swagger") || uri.startsWith("/api"))) {
 | 
			
		||||
            Counter counter = Counter.builder("http.requests")
 | 
			
		||||
                    .tag("uri", uri)
 | 
			
		||||
                    .tag("method", request.getMethod())
 | 
			
		||||
		if (!(uri.startsWith("/js") || uri.startsWith("/v1/api-docs") || uri.endsWith("robots.txt")
 | 
			
		||||
				|| uri.startsWith("/images")  || uri.startsWith("/images")|| uri.endsWith(".png") || uri.endsWith(".ico") || uri.endsWith(".css") || uri.endsWith(".map")
 | 
			
		||||
				|| uri.endsWith(".svg") || uri.endsWith(".js") || uri.contains("swagger")
 | 
			
		||||
				|| uri.startsWith("/api/v1/info") || uri.startsWith("/site.webmanifest")  || uri.startsWith("/fonts") || uri.startsWith("/pdfjs") )) {
 | 
			
		||||
			
 | 
			
		||||
			
 | 
			
		||||
			
 | 
			
		||||
			Counter counter = Counter.builder("http.requests").tag("uri", uri).tag("method", request.getMethod())
 | 
			
		||||
					.register(meterRegistry);
 | 
			
		||||
 | 
			
		||||
			counter.increment();
 | 
			
		||||
@ -43,6 +47,4 @@ public class MetricsFilter extends OncePerRequestFilter {
 | 
			
		||||
		filterChain.doFilter(request, response);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
    
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -1,27 +1,42 @@
 | 
			
		||||
package stirling.software.SPDF.config;
 | 
			
		||||
 | 
			
		||||
import org.springframework.beans.factory.annotation.Autowired;
 | 
			
		||||
import org.springframework.context.annotation.Bean;
 | 
			
		||||
import org.springframework.context.annotation.Configuration;
 | 
			
		||||
 | 
			
		||||
import io.swagger.v3.oas.models.Components;
 | 
			
		||||
import io.swagger.v3.oas.models.OpenAPI;
 | 
			
		||||
import io.swagger.v3.oas.models.info.Info;
 | 
			
		||||
import io.swagger.v3.oas.models.security.SecurityRequirement;
 | 
			
		||||
import io.swagger.v3.oas.models.security.SecurityScheme;
 | 
			
		||||
import stirling.software.SPDF.model.ApplicationProperties;
 | 
			
		||||
 | 
			
		||||
@Configuration
 | 
			
		||||
public class OpenApiConfig {
 | 
			
		||||
 | 
			
		||||
	@Autowired
 | 
			
		||||
	ApplicationProperties applicationProperties;
 | 
			
		||||
 | 
			
		||||
	@Bean
 | 
			
		||||
	public OpenAPI customOpenAPI() {
 | 
			
		||||
		String version = getClass().getPackage().getImplementationVersion();
 | 
			
		||||
		if (version == null) {
 | 
			
		||||
	        
 | 
			
		||||
			version = "1.0.0"; // default version if all else fails
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		SecurityScheme apiKeyScheme = new SecurityScheme().type(SecurityScheme.Type.APIKEY).in(SecurityScheme.In.HEADER)
 | 
			
		||||
				.name("X-API-KEY");
 | 
			
		||||
		if (!applicationProperties.getSecurity().getEnableLogin()) {
 | 
			
		||||
			return new OpenAPI().components(new Components())
 | 
			
		||||
					.info(new Info().title("Stirling PDF API").version(version).description(
 | 
			
		||||
							"API documentation for all Server-Side processing.\nPlease note some functionality might be UI only and missing from here."));
 | 
			
		||||
		} else {
 | 
			
		||||
			return new OpenAPI().components(new Components().addSecuritySchemes("apiKey", apiKeyScheme))
 | 
			
		||||
					.info(new Info().title("Stirling PDF API").version(version).description(
 | 
			
		||||
							"API documentation for all Server-Side processing.\nPlease note some functionality might be UI only and missing from here."))
 | 
			
		||||
					.addSecurityItem(new SecurityRequirement().addList("apiKey"));
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	    return new OpenAPI().components(new Components()).info(
 | 
			
		||||
	            new Info().title("Stirling PDF API").version(version).description("API documentation for all Server-Side processing.\nPlease note some functionality might be UI only and missing from here."));
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@ -27,8 +27,8 @@ import stirling.software.SPDF.config.StartupApplicationListener;
 | 
			
		||||
import stirling.software.SPDF.model.ApplicationProperties;
 | 
			
		||||
 | 
			
		||||
@RestController
 | 
			
		||||
@RequestMapping("/api/v1")
 | 
			
		||||
@Tag(name = "API", description = "Info APIs")
 | 
			
		||||
@RequestMapping("/api/v1/info")
 | 
			
		||||
@Tag(name = "Info", description = "Info APIs")
 | 
			
		||||
public class MetricsController {
 | 
			
		||||
 | 
			
		||||
	
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user