From e82adec2fd1f21282bcf8155eccf9d366ef16ddf Mon Sep 17 00:00:00 2001 From: Steve Hu Date: Fri, 24 Nov 2023 19:57:57 -0500 Subject: [PATCH] fixes #334 update config class to support conversion from string to integer and boolean (#335) --- .../main/java/com/networknt/openapi/OpenApiHandler.java | 7 +++---- .../main/java/com/networknt/openapi/JwtVerifyHandler.java | 5 +---- .../main/java/com/networknt/openapi/SwtVerifyHandler.java | 3 +-- 3 files changed, 5 insertions(+), 10 deletions(-) diff --git a/openapi-meta/src/main/java/com/networknt/openapi/OpenApiHandler.java b/openapi-meta/src/main/java/com/networknt/openapi/OpenApiHandler.java index 2400dd9..af46d2b 100644 --- a/openapi-meta/src/main/java/com/networknt/openapi/OpenApiHandler.java +++ b/openapi-meta/src/main/java/com/networknt/openapi/OpenApiHandler.java @@ -57,8 +57,6 @@ public class OpenApiHandler implements MiddlewareHandler { public static final String CONFIG_NAME = "openapi"; public static final String SPEC_INJECT = "openapi-inject"; - public static final String HANDLER_CONFIG = "handler"; - public static final AttachmentKey> DESERIALIZED_QUERY_PARAMETERS = AttachmentKey.create(Map.class); public static final AttachmentKey> DESERIALIZED_PATH_PARAMETERS = AttachmentKey.create(Map.class); public static final AttachmentKey> DESERIALIZED_HEADER_PARAMETERS = AttachmentKey.create(Map.class); @@ -112,7 +110,7 @@ public OpenApiHandler(OpenApiHandlerConfig cfg) { if(logger.isTraceEnabled()) logger.trace("multiple specifications loaded."); } else { Map openapi = Config.getInstance().getJsonMapConfigNoCache(CONFIG_NAME); - handlerConfig = (HandlerConfig) Config.getInstance().getJsonObjectConfig(HANDLER_CONFIG, HandlerConfig.class); + handlerConfig = HandlerConfig.load(); this.validateSpec(openapi, inject, "openapi.yml"); @@ -309,7 +307,8 @@ public void register() { @Override public void reload() { - handlerConfig = (HandlerConfig) Config.getInstance().getJsonObjectConfig(HANDLER_CONFIG, HandlerConfig.class); + config.reload(); + ModuleRegistry.registerModule(OpenApiHandlerConfig.CONFIG_NAME, OpenApiHandler.class.getName(), config.getMappedConfig(), null); } /** diff --git a/openapi-security/src/main/java/com/networknt/openapi/JwtVerifyHandler.java b/openapi-security/src/main/java/com/networknt/openapi/JwtVerifyHandler.java index 18ea0eb..9e26639 100644 --- a/openapi-security/src/main/java/com/networknt/openapi/JwtVerifyHandler.java +++ b/openapi-security/src/main/java/com/networknt/openapi/JwtVerifyHandler.java @@ -55,10 +55,7 @@ */ public class JwtVerifyHandler implements MiddlewareHandler, IJwtVerifyHandler { static final Logger logger = LoggerFactory.getLogger(JwtVerifyHandler.class); - - static final String HANDLER_CONFIG = "handler"; static final String OPENAPI_SECURITY_CONFIG = "openapi-security"; - static final String STATUS_INVALID_AUTH_TOKEN = "ERR10000"; static final String STATUS_AUTH_TOKEN_EXPIRED = "ERR10001"; static final String STATUS_MISSING_AUTH_TOKEN = "ERR10002"; @@ -84,7 +81,7 @@ public JwtVerifyHandler() { config = SecurityConfig.load(OPENAPI_SECURITY_CONFIG); jwtVerifier = new JwtVerifier(config); // in case that the specification doesn't exist, get the basePath from the handler.yml for endpoint lookup. - HandlerConfig handlerConfig = (HandlerConfig) Config.getInstance().getJsonObjectConfig(HANDLER_CONFIG, HandlerConfig.class); + HandlerConfig handlerConfig = HandlerConfig.load(); this.basePath = handlerConfig == null ? "/" : handlerConfig.getBasePath(); } diff --git a/openapi-security/src/main/java/com/networknt/openapi/SwtVerifyHandler.java b/openapi-security/src/main/java/com/networknt/openapi/SwtVerifyHandler.java index 6e93bc6..2cebb64 100644 --- a/openapi-security/src/main/java/com/networknt/openapi/SwtVerifyHandler.java +++ b/openapi-security/src/main/java/com/networknt/openapi/SwtVerifyHandler.java @@ -40,7 +40,6 @@ public class SwtVerifyHandler implements MiddlewareHandler { static final Logger logger = LoggerFactory.getLogger(SwtVerifyHandler.class); static final String OPENAPI_SECURITY_CONFIG = "openapi-security"; - static final String HANDLER_CONFIG = "handler"; static final String STATUS_INVALID_AUTH_TOKEN = "ERR10000"; static final String STATUS_AUTH_TOKEN_EXPIRED = "ERR10001"; static final String STATUS_MISSING_AUTH_TOKEN = "ERR10002"; @@ -429,7 +428,7 @@ public SwtVerifyHandler() { config = SecurityConfig.load(OPENAPI_SECURITY_CONFIG); swtVerifier = new SwtVerifier(config); // in case that the specification doesn't exist, get the basePath from the handler.yml for endpoint lookup. - HandlerConfig handlerConfig = (HandlerConfig) Config.getInstance().getJsonObjectConfig(HANDLER_CONFIG, HandlerConfig.class); + HandlerConfig handlerConfig = HandlerConfig.load(); this.basePath = handlerConfig == null ? "/" : handlerConfig.getBasePath(); }