This repository was archived by the owner on Feb 7, 2025. It is now read-only.
generated from CDCgov/template
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1182 from CDCgov/chores/additional-code-coverage-…
…cont Additional code coverage and code reuse refactoring
Showing
8 changed files
with
89 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
...in/java/gov/hhs/cdc/trustedintermediary/external/openapi/OpenApiReaderImplementation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package gov.hhs.cdc.trustedintermediary.external.openapi; | ||
|
||
import gov.hhs.cdc.trustedintermediary.domainconnector.UnableToReadOpenApiSpecificationException; | ||
import gov.hhs.cdc.trustedintermediary.wrappers.OpenApiReader; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.nio.charset.StandardCharsets; | ||
import java.util.Objects; | ||
|
||
/** | ||
* Basic implementation of a Reader for OpenApi to promote code reuse. If additional functionality | ||
* is needed, consider implementing a library and wrapping it. | ||
*/ | ||
public class OpenApiReaderImplementation implements OpenApiReader { | ||
private static final OpenApiReaderImplementation INSTANCE = new OpenApiReaderImplementation(); | ||
|
||
public static OpenApiReaderImplementation getInstance() { | ||
return INSTANCE; | ||
} | ||
|
||
/** | ||
* Loads the stream of an OpenApi file and returns the output as a string. | ||
* | ||
* @param fileName Name of the file to load | ||
* @return File contents as string | ||
* @throws UnableToReadOpenApiSpecificationException If there is an issue loading the Api file | ||
*/ | ||
@Override | ||
public String openAsString(String fileName) throws UnableToReadOpenApiSpecificationException { | ||
InputStream stream = getClass().getClassLoader().getResourceAsStream(fileName); | ||
try { | ||
return new String( | ||
Objects.requireNonNull(stream).readAllBytes(), StandardCharsets.UTF_8); | ||
} catch (IOException | NullPointerException e) { | ||
throw new UnableToReadOpenApiSpecificationException( | ||
"Failed to open OpenAPI specification for " + fileName, e); | ||
} | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
shared/src/main/java/gov/hhs/cdc/trustedintermediary/wrappers/OpenApiReader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package gov.hhs.cdc.trustedintermediary.wrappers; | ||
|
||
import gov.hhs.cdc.trustedintermediary.domainconnector.UnableToReadOpenApiSpecificationException; | ||
|
||
/** Wrapper for classes that load OpenApi documentation. */ | ||
public interface OpenApiReader { | ||
String openAsString(String fileName) throws UnableToReadOpenApiSpecificationException; | ||
} |