Skip to content

Commit

Permalink
JSON static file test
Browse files Browse the repository at this point in the history
Test we correctly load a JSON static file. This test will fail if we try
to parse the JSON as YAML.
  • Loading branch information
Azquelt committed Nov 8, 2024
1 parent 538f6ce commit f4a68be
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,31 @@ void testStaticFileLoadedFromClasspath() throws Exception {
OpenAPI model = result.model();
assertEquals("Loaded from the class path", model.getInfo().getTitle());
}

@Test
void testStaticJsonFileLoadedFromClasspath() throws Exception {
URL loaderRoot = getClass()
.getClassLoader()
.getResource("classloaderjson/META-INF/openapi.json")
.toURI()
.resolve("..")
.toURL();

ClassLoader custom = new URLClassLoader(
new URL[] { loaderRoot },
Thread.currentThread().getContextClassLoader());

SmallRyeOpenAPI result = SmallRyeOpenAPI.builder()
.withApplicationClassLoader(custom)
.enableModelReader(false)
.enableStandardFilter(false)
.enableAnnotationScan(false)
.enableStandardStaticFiles(true)
.build();

OpenAPI model = result.model();
assertEquals("Loaded from the class path", model.getInfo().getTitle());
}

@Test
void testInvalidTypesInStaticFileDropped() {
Expand Down
9 changes: 9 additions & 0 deletions core/src/test/resources/classloaderjson/META-INF/openapi.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"openapi": "3.1.0",
"info": {
"title": "Loaded from the class path",
"description": "This document uses tabs so that it doesn't parse as YAML",
"version": "1.0.0"
},
"paths": {}
}

0 comments on commit f4a68be

Please sign in to comment.