From 4b2cb42996b93a8a39111256729c58d417249da8 Mon Sep 17 00:00:00 2001 From: Damian Courtil Date: Wed, 19 Feb 2020 17:01:10 -0300 Subject: [PATCH] APIKIT-2575: Console not rendering when exchange modules are used --- .../org/mule/module/apikit/ConsoleHandler.java | 5 +++++ .../module/apikit/ExchangeModulesTestCase.java | 4 +++- .../shared-types/library-shared.raml | 9 +++++++++ .../datatype-standard-error-message.raml | 18 ++++++++++++++++++ .../standard-types/library-standard.raml | 17 +++++++++++++++++ .../examples/error/error-400-example.json | 7 +++++++ .../exchange_modules/traits/trait-has400.raml | 14 ++++++++++++++ .../org/mule/module/apikit/exchange/api.raml | 4 ++++ 8 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 mule-module-apikit/src/test/resources/exchange_modules/shared-types/library-shared.raml create mode 100644 mule-module-apikit/src/test/resources/exchange_modules/standard-datatype/datatype-standard-error-message.raml create mode 100644 mule-module-apikit/src/test/resources/exchange_modules/standard-types/library-standard.raml create mode 100644 mule-module-apikit/src/test/resources/exchange_modules/traits/examples/error/error-400-example.json create mode 100644 mule-module-apikit/src/test/resources/exchange_modules/traits/trait-has400.raml diff --git a/mule-module-apikit/src/main/java/org/mule/module/apikit/ConsoleHandler.java b/mule-module-apikit/src/main/java/org/mule/module/apikit/ConsoleHandler.java index 1bd948075..96751754d 100644 --- a/mule-module-apikit/src/main/java/org/mule/module/apikit/ConsoleHandler.java +++ b/mule-module-apikit/src/main/java/org/mule/module/apikit/ConsoleHandler.java @@ -60,6 +60,7 @@ public class ConsoleHandler implements MessageProcessor private static final String DEFAULT_API_RESOURCES_PATH = DEFAULT_API_FOLDER + "/"; private static final String FILE_SEPARATOR_REGEX = File.separator.equals("\\") ? "\\\\" : "/"; private static final String RAML_QUERY_STRING = "raml"; + private static final String EXCHANGE_MODULES = "exchange_modules"; private List acceptedClasspathResources; private String cachedIndexHtml; private String embeddedConsolePath; @@ -376,6 +377,10 @@ private URL readFromRamlRef(String ref) { } private URL readFromPath(String resourcePath) { + int lastIndexOfExchangeModules = resourcePath.lastIndexOf(EXCHANGE_MODULES); + if (lastIndexOfExchangeModules > 0) { + return Thread.currentThread().getContextClassLoader().getResource(resourcePath.substring(lastIndexOfExchangeModules)); + } Path root = Paths.get("/"); Path relativePath = Paths.get(embeddedConsolePath, "/" + DEFAULT_API_FOLDER); Path path = Paths.get(resourcePath); diff --git a/mule-module-apikit/src/test/java/org/mule/module/apikit/ExchangeModulesTestCase.java b/mule-module-apikit/src/test/java/org/mule/module/apikit/ExchangeModulesTestCase.java index 1d517dd03..42ee90b9d 100644 --- a/mule-module-apikit/src/test/java/org/mule/module/apikit/ExchangeModulesTestCase.java +++ b/mule-module-apikit/src/test/java/org/mule/module/apikit/ExchangeModulesTestCase.java @@ -84,7 +84,9 @@ public void getResource3() throws Exception @Test public void apiResources() { - String[] apiResources = new String[]{"exchange_modules/library1.raml","exchange_modules/library2.raml","/exchange_modules/library3.raml"}; + String[] apiResources = new String[]{"exchange_modules/library1.raml","exchange_modules/library2.raml","/exchange_modules/library3.raml", + "/exchange_modules/standard-types/exchange_modules/shared-types/library-shared.raml", + "/exchange_modules/standard-types/exchange_modules/shared-types/exchange_modules/traits/examples/error/error-400-example.json"}; for (String resource: apiResources){ given().header("Accept", "*/*") diff --git a/mule-module-apikit/src/test/resources/exchange_modules/shared-types/library-shared.raml b/mule-module-apikit/src/test/resources/exchange_modules/shared-types/library-shared.raml new file mode 100644 index 000000000..f044ab4a2 --- /dev/null +++ b/mule-module-apikit/src/test/resources/exchange_modules/shared-types/library-shared.raml @@ -0,0 +1,9 @@ +#%RAML 1.0 Library + +usage: Shared Library 1 + +types: + Standard-datetime: + type: datetime + format: rfc3339 + example: 2016-02-28T16:41:41.0+01:00 \ No newline at end of file diff --git a/mule-module-apikit/src/test/resources/exchange_modules/standard-datatype/datatype-standard-error-message.raml b/mule-module-apikit/src/test/resources/exchange_modules/standard-datatype/datatype-standard-error-message.raml new file mode 100644 index 000000000..d4f6e71c3 --- /dev/null +++ b/mule-module-apikit/src/test/resources/exchange_modules/standard-datatype/datatype-standard-error-message.raml @@ -0,0 +1,18 @@ +#%RAML 1.0 DataType + +usage: Standard error message + +type: object +displayName: Standard Error Message +properties: + code: + type: number + format: int32 + name: + type: string + reason: + type: string + message: + type: string + trace_id: + type: string diff --git a/mule-module-apikit/src/test/resources/exchange_modules/standard-types/library-standard.raml b/mule-module-apikit/src/test/resources/exchange_modules/standard-types/library-standard.raml new file mode 100644 index 000000000..8b570adf6 --- /dev/null +++ b/mule-module-apikit/src/test/resources/exchange_modules/standard-types/library-standard.raml @@ -0,0 +1,17 @@ +#%RAML 1.0 Library + +usage: Standard Library 1 + +uses: + SharedTypes: exchange_modules/shared-types/library-shared.raml + +annotationTypes: + deprecated: + allowedTargets: [API, Resource, Method] + properties: + description: + type: string + required: false + endOfService: + type: SharedTypes.Standard-datetime + required: true diff --git a/mule-module-apikit/src/test/resources/exchange_modules/traits/examples/error/error-400-example.json b/mule-module-apikit/src/test/resources/exchange_modules/traits/examples/error/error-400-example.json new file mode 100644 index 000000000..a4b23c6a8 --- /dev/null +++ b/mule-module-apikit/src/test/resources/exchange_modules/traits/examples/error/error-400-example.json @@ -0,0 +1,7 @@ +{ + "code" : 123, + "name" : "APIKIT_ERROR", + "reason" : "None", + "message" : "Bad Request", + "trace_id" : "548512ABC" +} diff --git a/mule-module-apikit/src/test/resources/exchange_modules/traits/trait-has400.raml b/mule-module-apikit/src/test/resources/exchange_modules/traits/trait-has400.raml new file mode 100644 index 000000000..543cda68b --- /dev/null +++ b/mule-module-apikit/src/test/resources/exchange_modules/traits/trait-has400.raml @@ -0,0 +1,14 @@ +#%RAML 1.0 Trait + +usage: Trait 400 error + +uses: + SharedTypes: exchange_modules/shared-types/library-shared.raml + +responses: + 400: + description: Bad Request + body: + application/json: + type: !include exchange_modules/standard-datatype/datatype-standard-error-message.raml + example: !include examples/error/error-400-example.json diff --git a/mule-module-apikit/src/test/resources/org/mule/module/apikit/exchange/api.raml b/mule-module-apikit/src/test/resources/org/mule/module/apikit/exchange/api.raml index 7d48c6509..5e6098c42 100644 --- a/mule-module-apikit/src/test/resources/org/mule/module/apikit/exchange/api.raml +++ b/mule-module-apikit/src/test/resources/org/mule/module/apikit/exchange/api.raml @@ -5,6 +5,10 @@ uses: library1: exchange_modules/library1.raml library2: exchange_modules/library2.raml library3: /exchange_modules/library3.raml + standardLibrary: exchange_modules/standard-types/library-standard.raml + +traits: + has400: !include exchange_modules/traits/trait-has400.raml /resource1: get: