Skip to content

Commit b37c699

Browse files
authored
Merge pull request #50 from mservicetech/issue49
fixes #49 add status and config depedencies from light-4j
2 parents 90d25ba + 1e67c9b commit b37c699

File tree

7 files changed

+42
-1360
lines changed

7 files changed

+42
-1360
lines changed

pom.xml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
<java.version>11</java.version>
5858
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
5959
<version.json-schema-validator>1.3.3</version.json-schema-validator>
60-
<version.light-4j>2.1.32</version.light-4j>
60+
<version.light-4j>2.1.33-SNAPSHOT</version.light-4j>
6161
<version.jackson>2.16.1</version.jackson>
6262
<version.snakeyaml>2.2</version.snakeyaml>
6363
<version.slf4j>2.0.12</version.slf4j>
@@ -79,6 +79,16 @@
7979
<artifactId>openapi-parser</artifactId>
8080
<version>${version.light-4j}</version>
8181
</dependency>
82+
<dependency>
83+
<groupId>com.networknt</groupId>
84+
<artifactId>config</artifactId>
85+
<version>${version.light-4j}</version>
86+
</dependency>
87+
<dependency>
88+
<groupId>com.networknt</groupId>
89+
<artifactId>status</artifactId>
90+
<version>${version.light-4j}</version>
91+
</dependency>
8292
<dependency>
8393
<groupId>com.fasterxml.jackson.core</groupId>
8494
<artifactId>jackson-databind</artifactId>

src/main/java/com/mservicetech/openapi/common/Status.java

Lines changed: 0 additions & 173 deletions
This file was deleted.

src/main/java/com/mservicetech/openapi/validation/OpenApiValidator.java

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import com.mservicetech.openapi.common.ParameterType;
77
import com.mservicetech.openapi.common.RequestEntity;
88
import com.mservicetech.openapi.common.ResponseEntity;
9-
import com.mservicetech.openapi.common.Status;
9+
import com.networknt.config.Config;
1010
import com.networknt.jsonoverlay.Overlay;
1111
import com.networknt.oas.model.Header;
1212
import com.networknt.oas.model.MediaType;
@@ -25,6 +25,7 @@
2525
import com.networknt.schema.JsonNodePath;
2626
import com.networknt.schema.SchemaValidatorsConfig;
2727

28+
import com.networknt.status.Status;
2829
import com.networknt.utility.StringUtils;
2930
import org.slf4j.Logger;
3031
import org.slf4j.LoggerFactory;
@@ -70,12 +71,19 @@ public class OpenApiValidator {
7071
* The default construct will try to load openapi.yml file from classpath
7172
*/
7273
public OpenApiValidator() {
73-
InputStream in = this.getClass().getClassLoader().getResourceAsStream(OPENAPI_YAML_CONFIG);;
74+
InputStream in = null;
7475
try {
76+
in = this.getClass().getClassLoader().getResourceAsStream(OPENAPI_YAML_CONFIG);;
7577
if (in == null) {
7678
in = this.getClass().getClassLoader().getResourceAsStream(OPENAPI_YML_CONFIG);
7779
if (in==null) {
78-
throw new IOException("Cannot load openapi spec file");
80+
in = Config.getInstance().getInputStreamFromFile(OPENAPI_YAML_CONFIG);
81+
if(in == null) {
82+
in = Config.getInstance().getInputStreamFromFile(OPENAPI_YML_CONFIG);
83+
if(in == null) {
84+
throw new IOException("Cannot load openapi spec file");
85+
}
86+
}
7987
}
8088
}
8189
spec = new BufferedReader(new InputStreamReader(in, StandardCharsets.UTF_8)).lines().collect(Collectors.joining("\n"));
@@ -101,13 +109,29 @@ public OpenApiValidator() {
101109
* @param openapiPath The schema file name and path to use when validating request bodies
102110
*/
103111
public OpenApiValidator(String openapiPath) {
104-
try (InputStream in = this.getClass().getClassLoader().getResourceAsStream(openapiPath);
105-
BufferedReader reader = new BufferedReader(new InputStreamReader(in, StandardCharsets.UTF_8))) {
112+
InputStream in = null;
113+
try {
114+
in = this.getClass().getClassLoader().getResourceAsStream(openapiPath);
115+
if (in == null) {
116+
in = Config.getInstance().getInputStreamFromFile(openapiPath);
117+
if(in == null) {
118+
throw new IOException("Cannot load openapi spec file");
119+
}
120+
}
121+
BufferedReader reader = new BufferedReader(new InputStreamReader(in, StandardCharsets.UTF_8));
106122
spec = reader.lines().collect(Collectors.joining("\n"));
107123
openApiHelper = new OpenApiHelper(spec);
108124
schemaValidator = new SchemaValidator(openApiHelper.openApi3);
109125
} catch (IOException e) {
110126
logger.error("initial failed:" + e);
127+
} finally {
128+
try {
129+
if( in!=null ) {
130+
in.close();
131+
}
132+
} catch(IOException e) {
133+
logger.error(" Failed to close input stream:" + e);
134+
}
111135
}
112136
}
113137

src/main/java/com/mservicetech/openapi/validation/SchemaValidator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
import com.networknt.schema.SchemaValidatorsConfig;
2929
import com.networknt.schema.ValidationMessage;
3030
import com.networknt.schema.SpecVersion.VersionFlag;
31-
import com.mservicetech.openapi.common.Status;
31+
import com.networknt.status.Status;
3232

3333
import java.util.Set;
3434

0 commit comments

Comments
 (0)