From f4a68be212fe5696bcca5fb901c0a1ea9c2ca263 Mon Sep 17 00:00:00 2001 From: Andrew Rouse Date: Fri, 8 Nov 2024 13:11:25 +0000 Subject: [PATCH] JSON static file test Test we correctly load a JSON static file. This test will fail if we try to parse the JSON as YAML. --- .../api/SmallRyeOpenAPIBuilderTest.java | 25 +++++++++++++++++++ .../classloaderjson/META-INF/openapi.json | 9 +++++++ 2 files changed, 34 insertions(+) create mode 100644 core/src/test/resources/classloaderjson/META-INF/openapi.json diff --git a/core/src/test/java/io/smallrye/openapi/api/SmallRyeOpenAPIBuilderTest.java b/core/src/test/java/io/smallrye/openapi/api/SmallRyeOpenAPIBuilderTest.java index 9baee01dc..7b21b1f1b 100644 --- a/core/src/test/java/io/smallrye/openapi/api/SmallRyeOpenAPIBuilderTest.java +++ b/core/src/test/java/io/smallrye/openapi/api/SmallRyeOpenAPIBuilderTest.java @@ -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() { diff --git a/core/src/test/resources/classloaderjson/META-INF/openapi.json b/core/src/test/resources/classloaderjson/META-INF/openapi.json new file mode 100644 index 000000000..c04963841 --- /dev/null +++ b/core/src/test/resources/classloaderjson/META-INF/openapi.json @@ -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": {} +}