You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tapestry.apache.org by th...@apache.org on 2021/10/14 13:26:58 UTC

[tapestry-5] branch rest updated: TAP5-2696: OpenAPI viewer, OpenAPI definition dispatcher

This is an automated email from the ASF dual-hosted git repository.

thiagohp pushed a commit to branch rest
in repository https://gitbox.apache.org/repos/asf/tapestry-5.git


The following commit(s) were added to refs/heads/rest by this push:
     new 6b75e73  TAP5-2696: OpenAPI viewer, OpenAPI definition dispatcher
6b75e73 is described below

commit 6b75e7384ad9b546b3ebb40cf592e8907aa177bb
Author: Thiago H. de Paula Figueiredo <th...@arsmachina.com.br>
AuthorDate: Thu Oct 14 10:26:32 2021 -0300

    TAP5-2696: OpenAPI viewer, OpenAPI definition dispatcher
    
    plus a few JavaDoc fixes
---
 settings.gradle                                    |   2 +-
 .../java/org/apache/tapestry5/SymbolConstants.java |  22 ++-
 .../services/OpenApiDescriptionDispatcher.java     |  62 +++++++
 .../apache/tapestry5/modules/TapestryModule.java   |  11 +-
 .../resources/org/apache/tapestry5/core.properties |   4 +-
 .../http/services/HttpRequestBodyConverter.java    |   2 +-
 tapestry-openapi-viewer/LICENSE.txt                | 202 +++++++++++++++++++++
 tapestry-openapi-viewer/NOTICE.txt                 |   5 +
 tapestry-openapi-viewer/build.gradle               |  12 ++
 .../modules/TapestryOpenApiViewerModule.java       |  29 +++
 .../tapestryopenapiviewer/pages/Index.java         |  47 +++++
 .../assets/openapiviewer/swagger-ui-bundle.js      |   3 +
 .../assets/openapiviewer/swagger-ui-bundle.js.map  |   1 +
 .../openapiviewer/swagger-ui-es-bundle-core.js     |   3 +
 .../openapiviewer/swagger-ui-es-bundle-core.js.map |   1 +
 .../assets/openapiviewer/swagger-ui-es-bundle.js   |   3 +
 .../openapiviewer/swagger-ui-es-bundle.js.map      |   1 +
 .../openapiviewer/swagger-ui-standalone-preset.js  |   3 +
 .../swagger-ui-standalone-preset.js.map            |   1 +
 .../META-INF/assets/openapiviewer/swagger-ui.css   |   4 +
 .../assets/openapiviewer/swagger-ui.css.map        |   1 +
 .../META-INF/assets/openapiviewer/swagger-ui.js    |   3 +
 .../assets/openapiviewer/swagger-ui.js.map         |   1 +
 .../tapestryopenapiviewer/pages/Index.tml          |  92 ++++++++++
 .../src/test/java/org/apache/tapestry5/.gitignore  |   1 +
 .../test/services/AppModule.java                   |  23 +++
 .../src/test/webapp/WEB-INF/web.xml                |  35 ++++
 27 files changed, 569 insertions(+), 5 deletions(-)

diff --git a/settings.gradle b/settings.gradle
index 7663ffc..2884936 100644
--- a/settings.gradle
+++ b/settings.gradle
@@ -9,4 +9,4 @@ include "tapestry-test-data", 'tapestry-internal-test', "tapestry-ioc-junit"
 include "tapestry-webresources", "tapestry-runner", "tapestry-test-constants"
 include "tapestry-ioc-jcache", "beanmodel", "commons", "genericsresolver-guava", "tapestry-version-migrator"
 // include "tapestry-cdi"
-include "tapestry-spock"
+include "tapestry-spock", "tapestry-openapi-viewer"
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/SymbolConstants.java b/tapestry-core/src/main/java/org/apache/tapestry5/SymbolConstants.java
index a8c37b4..5caa9a4 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/SymbolConstants.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/SymbolConstants.java
@@ -648,7 +648,7 @@ public class SymbolConstants
     
     /**
      * Defines the OpenAPI version to be used in the generated OpenAPI description.
-     * Default value is <code>3.0.0<code>.
+     * Default value is <code>3.0.0</code>.
      * @see DefaultOpenApiDescriptionGenerator
      * @see OpenApiDescriptionGenerator
      * @since 5.8.0
@@ -681,4 +681,24 @@ public class SymbolConstants
      */
     public static final String OPENAPI_APPLICATION_VERSION = "tapestry.openapi-application-version";
 
+    /**
+     * Defines whether the OpenAPI description file of this application's REST endpoints should be 
+     * published or not. The default value is <code>false</code>.
+     * @see OpenApiDescriptionGenerator
+     * @see #OPENAPI_DESCRIPTION_PATH
+     * @since 5.8.0
+     */
+    public static final String PUBLISH_OPENAPI_DEFINITON = "tapestry.publish-openapi-description";
+
+    /**
+     * Defines the path the OpenAPI description file of this application's REST endpoints will be
+     * published. It should start with a slash. The default value is <code>openapi.json</code>.
+     * Default value is <code>/openapi.json</code>.
+     * The description will only be published if {{@link #PUBLISH_OPENAPI_DEFINITON} is set to
+     * <code>true</code>.
+     * @see OpenApiDescriptionGenerator
+     * @since 5.8.0
+     */
+    public static final String OPENAPI_DESCRIPTION_PATH = "tapestry.openapi-description-path";
+
 }
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/OpenApiDescriptionDispatcher.java b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/OpenApiDescriptionDispatcher.java
new file mode 100644
index 0000000..a3e42de
--- /dev/null
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/OpenApiDescriptionDispatcher.java
@@ -0,0 +1,62 @@
+// Copyright 2021 The Apache Software Foundation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package org.apache.tapestry5.internal.services;
+
+import java.io.IOException;
+import java.nio.charset.Charset;
+
+import org.apache.tapestry5.SymbolConstants;
+import org.apache.tapestry5.http.services.Dispatcher;
+import org.apache.tapestry5.http.services.Request;
+import org.apache.tapestry5.http.services.Response;
+import org.apache.tapestry5.ioc.annotations.Symbol;
+import org.apache.tapestry5.json.JSONObject;
+import org.apache.tapestry5.services.OpenApiDescriptionGenerator;
+
+/**
+ * Recognizes requests where the path matches the value of {@link SymbolConstants#OPENAPI_DESCRIPTION_PATH}
+ * (<code>/openapi.json</code> by default). Only used if {@link SymbolConstants#PUBLISH_OPENAPI_DEFINITON}
+ * is set to <code>true</code> (which isn't by default).
+ * @see OpenApiDescriptionGenerator
+ */
+public class OpenApiDescriptionDispatcher implements Dispatcher
+{
+    
+    private final String path;
+    private final OpenApiDescriptionGenerator openApiDescriptionGenerator;
+    
+    public OpenApiDescriptionDispatcher(@Symbol(SymbolConstants.OPENAPI_DESCRIPTION_PATH) final String path,
+            final OpenApiDescriptionGenerator openApiDescriptionGenerator)
+    {
+        this.path = path;
+        this.openApiDescriptionGenerator = openApiDescriptionGenerator;
+    }
+    
+    public boolean dispatch(Request request, Response response) throws IOException
+    {
+        boolean dispatched = false;
+        if (path.equals(request.getPath()))
+        {
+            final byte[] definition = openApiDescriptionGenerator
+                    .generate(new JSONObject())
+                    .toCompactString()
+                    .getBytes(Charset.forName("UTF-8"));
+            response.setContentLength(definition.length);
+            response.getOutputStream("application/json").write(definition);
+            dispatched = true;
+        }
+        return dispatched;
+    }
+}
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/modules/TapestryModule.java b/tapestry-core/src/main/java/org/apache/tapestry5/modules/TapestryModule.java
index cdcf2fb..1597c2c 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/modules/TapestryModule.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/modules/TapestryModule.java
@@ -1677,8 +1677,15 @@ public final class TapestryModule
      * {@link ComponentEventRequestHandler}</dd>
      * </dl>
      */
-    public static void contributeMasterDispatcher(OrderedConfiguration<Dispatcher> configuration)
+    public static void contributeMasterDispatcher(OrderedConfiguration<Dispatcher> configuration,
+            @Symbol(SymbolConstants.PUBLISH_OPENAPI_DEFINITON) final boolean publishOpenApiDefinition)
     {
+        
+        if (publishOpenApiDefinition)
+        {
+            configuration.addInstance("OpenAPI", OpenApiDescriptionDispatcher.class, "before:PageRender", "before:ComponentEvent");
+        }
+        
         // Looks for the root path and renders the start page. This is
         // maintained for compatibility
         // with earlier versions of Tapestry 5, it is recommended that an Index
@@ -2174,6 +2181,8 @@ public final class TapestryModule
         configuration.add(SymbolConstants.PRELOADER_MODE, PreloaderMode.PRODUCTION);
         
         configuration.add(SymbolConstants.OPENAPI_VERSION, "3.0.0");
+        configuration.add(SymbolConstants.PUBLISH_OPENAPI_DEFINITON, "false");
+        configuration.add(SymbolConstants.OPENAPI_DESCRIPTION_PATH, "/openapi.json");
     }
 
     /**
diff --git a/tapestry-core/src/main/resources/org/apache/tapestry5/core.properties b/tapestry-core/src/main/resources/org/apache/tapestry5/core.properties
index 3c04f2c..7f99509 100644
--- a/tapestry-core/src/main/resources/org/apache/tapestry5/core.properties
+++ b/tapestry-core/src/main/resources/org/apache/tapestry5/core.properties
@@ -1,4 +1,4 @@
-# Copyright 2013-2014 The Apache Software Foundation
+# Copyright 2013-2021 The Apache Software Foundation
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
@@ -139,3 +139,5 @@ private-default-localdate-format=lll
 
 # see ComponentLibraries page
 not-informed=Not informed
+
+openapi.viewer-title=OpenAPI definition viewer
\ No newline at end of file
diff --git a/tapestry-http/src/main/java/org/apache/tapestry5/http/services/HttpRequestBodyConverter.java b/tapestry-http/src/main/java/org/apache/tapestry5/http/services/HttpRequestBodyConverter.java
index 0765e84..9eb037a 100644
--- a/tapestry-http/src/main/java/org/apache/tapestry5/http/services/HttpRequestBodyConverter.java
+++ b/tapestry-http/src/main/java/org/apache/tapestry5/http/services/HttpRequestBodyConverter.java
@@ -31,7 +31,7 @@ public interface HttpRequestBodyConverter
      * Converts the body of this request. If this implementation cannot handle this request,
      * probably by not handling its content type, it should return <code>null</code>.
      * In addition, if the request body is empty, this method should also return
-     * <code>null<code>.
+     * <code>null</code>.
      * @param request an {@linkplain HttpServletRequest}.
      * @param type the target type.
      * @return an object of the target type or <code>null</code>.
diff --git a/tapestry-openapi-viewer/LICENSE.txt b/tapestry-openapi-viewer/LICENSE.txt
new file mode 100644
index 0000000..d645695
--- /dev/null
+++ b/tapestry-openapi-viewer/LICENSE.txt
@@ -0,0 +1,202 @@
+
+                                 Apache License
+                           Version 2.0, January 2004
+                        http://www.apache.org/licenses/
+
+   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+   1. Definitions.
+
+      "License" shall mean the terms and conditions for use, reproduction,
+      and distribution as defined by Sections 1 through 9 of this document.
+
+      "Licensor" shall mean the copyright owner or entity authorized by
+      the copyright owner that is granting the License.
+
+      "Legal Entity" shall mean the union of the acting entity and all
+      other entities that control, are controlled by, or are under common
+      control with that entity. For the purposes of this definition,
+      "control" means (i) the power, direct or indirect, to cause the
+      direction or management of such entity, whether by contract or
+      otherwise, or (ii) ownership of fifty percent (50%) or more of the
+      outstanding shares, or (iii) beneficial ownership of such entity.
+
+      "You" (or "Your") shall mean an individual or Legal Entity
+      exercising permissions granted by this License.
+
+      "Source" form shall mean the preferred form for making modifications,
+      including but not limited to software source code, documentation
+      source, and configuration files.
+
+      "Object" form shall mean any form resulting from mechanical
+      transformation or translation of a Source form, including but
+      not limited to compiled object code, generated documentation,
+      and conversions to other media types.
+
+      "Work" shall mean the work of authorship, whether in Source or
+      Object form, made available under the License, as indicated by a
+      copyright notice that is included in or attached to the work
+      (an example is provided in the Appendix below).
+
+      "Derivative Works" shall mean any work, whether in Source or Object
+      form, that is based on (or derived from) the Work and for which the
+      editorial revisions, annotations, elaborations, or other modifications
+      represent, as a whole, an original work of authorship. For the purposes
+      of this License, Derivative Works shall not include works that remain
+      separable from, or merely link (or bind by name) to the interfaces of,
+      the Work and Derivative Works thereof.
+
+      "Contribution" shall mean any work of authorship, including
+      the original version of the Work and any modifications or additions
+      to that Work or Derivative Works thereof, that is intentionally
+      submitted to Licensor for inclusion in the Work by the copyright owner
+      or by an individual or Legal Entity authorized to submit on behalf of
+      the copyright owner. For the purposes of this definition, "submitted"
+      means any form of electronic, verbal, or written communication sent
+      to the Licensor or its representatives, including but not limited to
+      communication on electronic mailing lists, source code control systems,
+      and issue tracking systems that are managed by, or on behalf of, the
+      Licensor for the purpose of discussing and improving the Work, but
+      excluding communication that is conspicuously marked or otherwise
+      designated in writing by the copyright owner as "Not a Contribution."
+
+      "Contributor" shall mean Licensor and any individual or Legal Entity
+      on behalf of whom a Contribution has been received by Licensor and
+      subsequently incorporated within the Work.
+
+   2. Grant of Copyright License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      copyright license to reproduce, prepare Derivative Works of,
+      publicly display, publicly perform, sublicense, and distribute the
+      Work and such Derivative Works in Source or Object form.
+
+   3. Grant of Patent License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      (except as stated in this section) patent license to make, have made,
+      use, offer to sell, sell, import, and otherwise transfer the Work,
+      where such license applies only to those patent claims licensable
+      by such Contributor that are necessarily infringed by their
+      Contribution(s) alone or by combination of their Contribution(s)
+      with the Work to which such Contribution(s) was submitted. If You
+      institute patent litigation against any entity (including a
+      cross-claim or counterclaim in a lawsuit) alleging that the Work
+      or a Contribution incorporated within the Work constitutes direct
+      or contributory patent infringement, then any patent licenses
+      granted to You under this License for that Work shall terminate
+      as of the date such litigation is filed.
+
+   4. Redistribution. You may reproduce and distribute copies of the
+      Work or Derivative Works thereof in any medium, with or without
+      modifications, and in Source or Object form, provided that You
+      meet the following conditions:
+
+      (a) You must give any other recipients of the Work or
+          Derivative Works a copy of this License; and
+
+      (b) You must cause any modified files to carry prominent notices
+          stating that You changed the files; and
+
+      (c) You must retain, in the Source form of any Derivative Works
+          that You distribute, all copyright, patent, trademark, and
+          attribution notices from the Source form of the Work,
+          excluding those notices that do not pertain to any part of
+          the Derivative Works; and
+
+      (d) If the Work includes a "NOTICE" text file as part of its
+          distribution, then any Derivative Works that You distribute must
+          include a readable copy of the attribution notices contained
+          within such NOTICE file, excluding those notices that do not
+          pertain to any part of the Derivative Works, in at least one
+          of the following places: within a NOTICE text file distributed
+          as part of the Derivative Works; within the Source form or
+          documentation, if provided along with the Derivative Works; or,
+          within a display generated by the Derivative Works, if and
+          wherever such third-party notices normally appear. The contents
+          of the NOTICE file are for informational purposes only and
+          do not modify the License. You may add Your own attribution
+          notices within Derivative Works that You distribute, alongside
+          or as an addendum to the NOTICE text from the Work, provided
+          that such additional attribution notices cannot be construed
+          as modifying the License.
+
+      You may add Your own copyright statement to Your modifications and
+      may provide additional or different license terms and conditions
+      for use, reproduction, or distribution of Your modifications, or
+      for any such Derivative Works as a whole, provided Your use,
+      reproduction, and distribution of the Work otherwise complies with
+      the conditions stated in this License.
+
+   5. Submission of Contributions. Unless You explicitly state otherwise,
+      any Contribution intentionally submitted for inclusion in the Work
+      by You to the Licensor shall be under the terms and conditions of
+      this License, without any additional terms or conditions.
+      Notwithstanding the above, nothing herein shall supersede or modify
+      the terms of any separate license agreement you may have executed
+      with Licensor regarding such Contributions.
+
+   6. Trademarks. This License does not grant permission to use the trade
+      names, trademarks, service marks, or product names of the Licensor,
+      except as required for reasonable and customary use in describing the
+      origin of the Work and reproducing the content of the NOTICE file.
+
+   7. Disclaimer of Warranty. Unless required by applicable law or
+      agreed to in writing, Licensor provides the Work (and each
+      Contributor provides its Contributions) on an "AS IS" BASIS,
+      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+      implied, including, without limitation, any warranties or conditions
+      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+      PARTICULAR PURPOSE. You are solely responsible for determining the
+      appropriateness of using or redistributing the Work and assume any
+      risks associated with Your exercise of permissions under this License.
+
+   8. Limitation of Liability. In no event and under no legal theory,
+      whether in tort (including negligence), contract, or otherwise,
+      unless required by applicable law (such as deliberate and grossly
+      negligent acts) or agreed to in writing, shall any Contributor be
+      liable to You for damages, including any direct, indirect, special,
+      incidental, or consequential damages of any character arising as a
+      result of this License or out of the use or inability to use the
+      Work (including but not limited to damages for loss of goodwill,
+      work stoppage, computer failure or malfunction, or any and all
+      other commercial damages or losses), even if such Contributor
+      has been advised of the possibility of such damages.
+
+   9. Accepting Warranty or Additional Liability. While redistributing
+      the Work or Derivative Works thereof, You may choose to offer,
+      and charge a fee for, acceptance of support, warranty, indemnity,
+      or other liability obligations and/or rights consistent with this
+      License. However, in accepting such obligations, You may act only
+      on Your own behalf and on Your sole responsibility, not on behalf
+      of any other Contributor, and only if You agree to indemnify,
+      defend, and hold each Contributor harmless for any liability
+      incurred by, or claims asserted against, such Contributor by reason
+      of your accepting any such warranty or additional liability.
+
+   END OF TERMS AND CONDITIONS
+
+   APPENDIX: How to apply the Apache License to your work.
+
+      To apply the Apache License to your work, attach the following
+      boilerplate notice, with the fields enclosed by brackets "[]"
+      replaced with your own identifying information. (Don't include
+      the brackets!)  The text should be enclosed in the appropriate
+      comment syntax for the file format. We also recommend that a
+      file or class name and description of purpose be included on the
+      same "printed page" as the copyright notice for easier
+      identification within third-party archives.
+
+   Copyright [yyyy] [name of copyright owner]
+
+   Licensed under the Apache License, Version 2.0 (the "License");
+   you may not use this file except in compliance with the License.
+   You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
diff --git a/tapestry-openapi-viewer/NOTICE.txt b/tapestry-openapi-viewer/NOTICE.txt
new file mode 100644
index 0000000..789c880
--- /dev/null
+++ b/tapestry-openapi-viewer/NOTICE.txt
@@ -0,0 +1,5 @@
+This product includes software developed by
+The Apache Software Foundation (http://www.apache.org/).
+
+This software depends on the Swagger UI licensed
+under the Apache License Version 2.0, January 2014
diff --git a/tapestry-openapi-viewer/build.gradle b/tapestry-openapi-viewer/build.gradle
new file mode 100644
index 0000000..845f96f
--- /dev/null
+++ b/tapestry-openapi-viewer/build.gradle
@@ -0,0 +1,12 @@
+description = "Embedded OpenAPI (Swagger) viewer for Tapestry, based on Swagger UI"
+
+dependencies {
+    compile project(':tapestry-core')
+    testCompile "javax.servlet:javax.servlet-api:${versions.servletapi}"
+}
+
+jar {
+    manifest {
+        attributes 'Tapestry-Module-Classes': 'org.apache.tapestry5.tapestryopenapiviewer.modules.TapestryOpenApiViewerModule'
+    }
+}
diff --git a/tapestry-openapi-viewer/src/main/java/org/apache/tapestry5/tapestryopenapiviewer/modules/TapestryOpenApiViewerModule.java b/tapestry-openapi-viewer/src/main/java/org/apache/tapestry5/tapestryopenapiviewer/modules/TapestryOpenApiViewerModule.java
new file mode 100644
index 0000000..dddb421
--- /dev/null
+++ b/tapestry-openapi-viewer/src/main/java/org/apache/tapestry5/tapestryopenapiviewer/modules/TapestryOpenApiViewerModule.java
@@ -0,0 +1,29 @@
+// Copyright 2021 The Apache Software Foundation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package org.apache.tapestry5.tapestryopenapiviewer.modules;
+
+import org.apache.tapestry5.commons.Configuration;
+import org.apache.tapestry5.services.LibraryMapping;
+
+/**
+ * Defines services and definitions for the Tapestry OpenAPI viewer.
+ */
+public class TapestryOpenApiViewerModule
+{
+    public static void contributeComponentClassResolver(Configuration<LibraryMapping> configuration)
+    {
+        configuration.add(new LibraryMapping("openapiviewer", "org.apache.tapestry5.tapestryopenapiviewer"));
+    }
+}
diff --git a/tapestry-openapi-viewer/src/main/java/org/apache/tapestry5/tapestryopenapiviewer/pages/Index.java b/tapestry-openapi-viewer/src/main/java/org/apache/tapestry5/tapestryopenapiviewer/pages/Index.java
new file mode 100644
index 0000000..d7eec90
--- /dev/null
+++ b/tapestry-openapi-viewer/src/main/java/org/apache/tapestry5/tapestryopenapiviewer/pages/Index.java
@@ -0,0 +1,47 @@
+// Copyright 2021 The Apache Software Foundation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+package org.apache.tapestry5.tapestryopenapiviewer.pages;
+
+import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
+
+import org.apache.tapestry5.SymbolConstants;
+import org.apache.tapestry5.annotations.Cached;
+import org.apache.tapestry5.http.services.BaseURLSource;
+import org.apache.tapestry5.http.services.Request;
+import org.apache.tapestry5.ioc.annotations.Inject;
+import org.apache.tapestry5.ioc.annotations.Symbol;
+
+/**
+ * Shows an OpenAPI definition viewer based on Swagger UI.
+ */
+public class Index {
+
+    @Inject
+    private BaseURLSource baseURLSource;
+    
+    @Inject
+    @Symbol(SymbolConstants.OPENAPI_DESCRIPTION_PATH) 
+    private String descriptionPath;
+    
+    @Inject
+    private Request request;
+    
+    @Cached
+    public String getEscapedDefinitionUrl() throws UnsupportedEncodingException
+    {
+        return URLEncoder.encode(baseURLSource.getBaseURL(request.isSecure()) + descriptionPath, "UTF-8");
+    }
+    
+}
diff --git a/tapestry-openapi-viewer/src/main/resources/META-INF/assets/openapiviewer/swagger-ui-bundle.js b/tapestry-openapi-viewer/src/main/resources/META-INF/assets/openapiviewer/swagger-ui-bundle.js
new file mode 100644
index 0000000..e257e95
--- /dev/null
+++ b/tapestry-openapi-viewer/src/main/resources/META-INF/assets/openapiviewer/swagger-ui-bundle.js
@@ -0,0 +1,3 @@
+/*! For license information please see swagger-ui-bundle.js.LICENSE.txt */
+!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.SwaggerUIBundle=t():e.SwaggerUIBundle=t()}(this,(function(){return function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r [...]
+//# sourceMappingURL=swagger-ui-bundle.js.map
\ No newline at end of file
diff --git a/tapestry-openapi-viewer/src/main/resources/META-INF/assets/openapiviewer/swagger-ui-bundle.js.map b/tapestry-openapi-viewer/src/main/resources/META-INF/assets/openapiviewer/swagger-ui-bundle.js.map
new file mode 100644
index 0000000..9916f7f
--- /dev/null
+++ b/tapestry-openapi-viewer/src/main/resources/META-INF/assets/openapiviewer/swagger-ui-bundle.js.map
@@ -0,0 +1 @@
+{"version":3,"sources":["webpack://SwaggerUIBundle/webpack/universalModuleDefinition","webpack://SwaggerUIBundle/webpack/bootstrap","webpack://SwaggerUIBundle/./node_modules/react/index.js","webpack://SwaggerUIBundle/./node_modules/immutable/dist/immutable.js","webpack://SwaggerUIBundle/./node_modules/@babel/runtime-corejs3/core-js-stable/instance/concat.js","webpack://SwaggerUIBundle/./node_modules/@babel/runtime-corejs3/helpers/defineProperty.js","webpack://SwaggerUIBundle/./node_modul [...]
\ No newline at end of file
diff --git a/tapestry-openapi-viewer/src/main/resources/META-INF/assets/openapiviewer/swagger-ui-es-bundle-core.js b/tapestry-openapi-viewer/src/main/resources/META-INF/assets/openapiviewer/swagger-ui-es-bundle-core.js
new file mode 100644
index 0000000..a6d6930
--- /dev/null
+++ b/tapestry-openapi-viewer/src/main/resources/META-INF/assets/openapiviewer/swagger-ui-es-bundle-core.js
@@ -0,0 +1,3 @@
+/*! For license information please see swagger-ui-es-bundle-core.js.LICENSE.txt */
+module.exports=function(e){var t={};function n(r){if(t[r])return t[r].exports;var a=t[r]={i:r,l:!1,exports:{}};return e[r].call(a.exports,a,a.exports,n),a.l=!0,a.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e; [...]
+//# sourceMappingURL=swagger-ui-es-bundle-core.js.map
\ No newline at end of file
diff --git a/tapestry-openapi-viewer/src/main/resources/META-INF/assets/openapiviewer/swagger-ui-es-bundle-core.js.map b/tapestry-openapi-viewer/src/main/resources/META-INF/assets/openapiviewer/swagger-ui-es-bundle-core.js.map
new file mode 100644
index 0000000..5185cdc
--- /dev/null
+++ b/tapestry-openapi-viewer/src/main/resources/META-INF/assets/openapiviewer/swagger-ui-es-bundle-core.js.map
@@ -0,0 +1 @@
+{"version":3,"sources":["webpack://SwaggerUIBundle/webpack/bootstrap","webpack://SwaggerUIBundle/external \"react\"","webpack://SwaggerUIBundle/external \"immutable\"","webpack://SwaggerUIBundle/./node_modules/@babel/runtime-corejs3/core-js-stable/instance/concat.js","webpack://SwaggerUIBundle/./node_modules/@babel/runtime-corejs3/helpers/defineProperty.js","webpack://SwaggerUIBundle/./node_modules/@babel/runtime-corejs3/core-js-stable/instance/map.js","webpack://SwaggerUIBundle/./src/co [...]
\ No newline at end of file
diff --git a/tapestry-openapi-viewer/src/main/resources/META-INF/assets/openapiviewer/swagger-ui-es-bundle.js b/tapestry-openapi-viewer/src/main/resources/META-INF/assets/openapiviewer/swagger-ui-es-bundle.js
new file mode 100644
index 0000000..464a745
--- /dev/null
+++ b/tapestry-openapi-viewer/src/main/resources/META-INF/assets/openapiviewer/swagger-ui-es-bundle.js
@@ -0,0 +1,3 @@
+/*! For license information please see swagger-ui-es-bundle.js.LICENSE.txt */
+module.exports=function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e; [...]
+//# sourceMappingURL=swagger-ui-es-bundle.js.map
\ No newline at end of file
diff --git a/tapestry-openapi-viewer/src/main/resources/META-INF/assets/openapiviewer/swagger-ui-es-bundle.js.map b/tapestry-openapi-viewer/src/main/resources/META-INF/assets/openapiviewer/swagger-ui-es-bundle.js.map
new file mode 100644
index 0000000..2edc6fa
--- /dev/null
+++ b/tapestry-openapi-viewer/src/main/resources/META-INF/assets/openapiviewer/swagger-ui-es-bundle.js.map
@@ -0,0 +1 @@
+{"version":3,"sources":["webpack://SwaggerUIBundle/webpack/bootstrap","webpack://SwaggerUIBundle/./node_modules/react/index.js","webpack://SwaggerUIBundle/./node_modules/immutable/dist/immutable.js","webpack://SwaggerUIBundle/./node_modules/@babel/runtime-corejs3/core-js-stable/instance/concat.js","webpack://SwaggerUIBundle/./node_modules/@babel/runtime-corejs3/helpers/defineProperty.js","webpack://SwaggerUIBundle/./node_modules/@babel/runtime-corejs3/core-js-stable/instance/map.js","web [...]
\ No newline at end of file
diff --git a/tapestry-openapi-viewer/src/main/resources/META-INF/assets/openapiviewer/swagger-ui-standalone-preset.js b/tapestry-openapi-viewer/src/main/resources/META-INF/assets/openapiviewer/swagger-ui-standalone-preset.js
new file mode 100644
index 0000000..fcf8126
--- /dev/null
+++ b/tapestry-openapi-viewer/src/main/resources/META-INF/assets/openapiviewer/swagger-ui-standalone-preset.js
@@ -0,0 +1,3 @@
+/*! For license information please see swagger-ui-standalone-preset.js.LICENSE.txt */
+!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.SwaggerUIStandalonePreset=e():t.SwaggerUIStandalonePreset=e()}(this,(function(){return function(t){var e={};function n(r){if(e[r])return e[r].exports;var i=e[r]={i:r,l:!1,exports:{}};return t[r].call(i.exports,i,i.exports,n),i.l=!0,i.exports}return n.m=t,n.c=e,n.d=function(t,e,r){n.o(t,e)||Object.defineProperty(t,e,{enumer [...]
+//# sourceMappingURL=swagger-ui-standalone-preset.js.map
\ No newline at end of file
diff --git a/tapestry-openapi-viewer/src/main/resources/META-INF/assets/openapiviewer/swagger-ui-standalone-preset.js.map b/tapestry-openapi-viewer/src/main/resources/META-INF/assets/openapiviewer/swagger-ui-standalone-preset.js.map
new file mode 100644
index 0000000..436d4cf
--- /dev/null
+++ b/tapestry-openapi-viewer/src/main/resources/META-INF/assets/openapiviewer/swagger-ui-standalone-preset.js.map
@@ -0,0 +1 @@
+{"version":3,"sources":["webpack://SwaggerUIStandalonePreset/webpack/universalModuleDefinition","webpack://SwaggerUIStandalonePreset/webpack/bootstrap","webpack://SwaggerUIStandalonePreset/./node_modules/immutable/dist/immutable.js","webpack://SwaggerUIStandalonePreset/./node_modules/core-js-pure/internals/export.js","webpack://SwaggerUIStandalonePreset/./node_modules/react/index.js","webpack://SwaggerUIStandalonePreset/./node_modules/@babel/runtime-corejs3/core-js-stable/instance/concat [...]
\ No newline at end of file
diff --git a/tapestry-openapi-viewer/src/main/resources/META-INF/assets/openapiviewer/swagger-ui.css b/tapestry-openapi-viewer/src/main/resources/META-INF/assets/openapiviewer/swagger-ui.css
new file mode 100644
index 0000000..7dd51d4
--- /dev/null
+++ b/tapestry-openapi-viewer/src/main/resources/META-INF/assets/openapiviewer/swagger-ui.css
@@ -0,0 +1,4 @@
+.swagger-ui{color:#3b4151;
+  /*! normalize.css v7.0.0 | MIT License | github.com/necolas/normalize.css */font-family:sans-serif}.swagger-ui html{-ms-text-size-adjust:100%;-webkit-text-size-adjust:100%;line-height:1.15}.swagger-ui body{margin:0}.swagger-ui article,.swagger-ui aside,.swagger-ui footer,.swagger-ui header,.swagger-ui nav,.swagger-ui section{display:block}.swagger-ui h1{font-size:2em;margin:.67em 0}.swagger-ui figcaption,.swagger-ui figure,.swagger-ui main{display:block}.swagger-ui figure{margin:1em 40 [...]
+
+/*# sourceMappingURL=swagger-ui.css.map*/
\ No newline at end of file
diff --git a/tapestry-openapi-viewer/src/main/resources/META-INF/assets/openapiviewer/swagger-ui.css.map b/tapestry-openapi-viewer/src/main/resources/META-INF/assets/openapiviewer/swagger-ui.css.map
new file mode 100644
index 0000000..a94bd7c
--- /dev/null
+++ b/tapestry-openapi-viewer/src/main/resources/META-INF/assets/openapiviewer/swagger-ui.css.map
@@ -0,0 +1 @@
+{"version":3,"sources":["webpack:///./src/style/main.scss","webpack:///./src/style/_type.scss","webpack:///./src/style/_variables.scss","webpack:///./node_modules/tachyons-sass/scss/_normalize.scss","webpack:///./node_modules/tachyons-sass/scss/_debug-children.scss","webpack:///./node_modules/tachyons-sass/scss/_debug-grid.scss","webpack:///./node_modules/tachyons-sass/scss/_box-sizing.scss","webpack:///./node_modules/tachyons-sass/scss/_aspect-ratios.scss","webpack:///./node_modules/tac [...]
\ No newline at end of file
diff --git a/tapestry-openapi-viewer/src/main/resources/META-INF/assets/openapiviewer/swagger-ui.js b/tapestry-openapi-viewer/src/main/resources/META-INF/assets/openapiviewer/swagger-ui.js
new file mode 100644
index 0000000..89a6694
--- /dev/null
+++ b/tapestry-openapi-viewer/src/main/resources/META-INF/assets/openapiviewer/swagger-ui.js
@@ -0,0 +1,3 @@
+/*! For license information please see swagger-ui.js.LICENSE.txt */
+!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.SwaggerUICore=t():e.SwaggerUICore=t()}(this,(function(){return function(e){var t={};function n(r){if(t[r])return t[r].exports;var a=t[r]={i:r,l:!1,exports:{}};return e[r].call(a.exports,a,a.exports,n),a.l=!0,a.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=fun [...]
+//# sourceMappingURL=swagger-ui.js.map
\ No newline at end of file
diff --git a/tapestry-openapi-viewer/src/main/resources/META-INF/assets/openapiviewer/swagger-ui.js.map b/tapestry-openapi-viewer/src/main/resources/META-INF/assets/openapiviewer/swagger-ui.js.map
new file mode 100644
index 0000000..6cf25dd
--- /dev/null
+++ b/tapestry-openapi-viewer/src/main/resources/META-INF/assets/openapiviewer/swagger-ui.js.map
@@ -0,0 +1 @@
+{"version":3,"sources":["webpack://SwaggerUICore/webpack/universalModuleDefinition","webpack://SwaggerUICore/webpack/bootstrap","webpack://SwaggerUICore/external \"react\"","webpack://SwaggerUICore/external \"immutable\"","webpack://SwaggerUICore/./node_modules/@babel/runtime-corejs3/core-js-stable/instance/concat.js","webpack://SwaggerUICore/./node_modules/@babel/runtime-corejs3/helpers/defineProperty.js","webpack://SwaggerUICore/./node_modules/@babel/runtime-corejs3/core-js-stable/inst [...]
\ No newline at end of file
diff --git a/tapestry-openapi-viewer/src/main/resources/org/apache/tapestry5/tapestryopenapiviewer/pages/Index.tml b/tapestry-openapi-viewer/src/main/resources/org/apache/tapestry5/tapestryopenapiviewer/pages/Index.tml
new file mode 100644
index 0000000..d9e5704
--- /dev/null
+++ b/tapestry-openapi-viewer/src/main/resources/org/apache/tapestry5/tapestryopenapiviewer/pages/Index.tml
@@ -0,0 +1,92 @@
+<html xmlns:t="http://tapestry.apache.org/schema/tapestry_5_3.xsd" lang="en">
+  <head>
+    <meta charset="UTF-8"/>
+    <title>${message:openapi.viewer-title}</title>
+    <link rel="stylesheet" type="text/css" href="${asset:classpath:/META-INF/assets/openapiviewer/swagger-ui.css}" />
+<!--     <link rel="icon" type="image/png" href="./favicon-32x32.png" sizes="32x32" /> -->
+<!--     <link rel="icon" type="image/png" href="./favicon-16x16.png" sizes="16x16" /> -->
+    <style>
+      html
+      {
+        box-sizing: border-box;
+        overflow: -moz-scrollbars-vertical;
+        overflow-y: scroll;
+      }
+
+      *,
+      *:before,
+      *:after
+      {
+        box-sizing: inherit;
+      }
+
+      body
+      {
+        margin:0;
+        background: #fafafa;
+      }
+      /* This is Tapestry-specific */
+      .swagger-container .topbar
+      {
+        display: none !important;
+      }
+      pre.version
+      {
+        color: black !important;
+      }
+      .swagger-ui-attribution
+      {
+        margin-top: 3em;
+      }
+      .float-left
+      {
+        float: left;
+      }
+    </style>
+  </head>
+
+  <body>
+    <div id="swagger-ui"></div>
+
+    <script src="${asset:classpath:/META-INF/assets/openapiviewer/swagger-ui-bundle.js}" charset="UTF-8"/>
+    <script src="${asset:classpath:/META-INF/assets/openapiviewer/swagger-ui-standalone-preset.js}" charset="UTF-8"/>
+    <script>
+    window.onload = function() {
+      // Begin Swagger UI call region
+      const ui = SwaggerUIBundle({
+        url: "${symbol:tapestry.openapi-description-path}",
+        dom_id: '#swagger-ui',
+        deepLinking: true,
+        presets: [
+          SwaggerUIBundle.presets.apis,
+          SwaggerUIStandalonePreset
+        ],
+        plugins: [
+          SwaggerUIBundle.plugins.DownloadUrl
+        ],
+        layout: "StandaloneLayout"
+      });
+      // End Swagger UI call region
+
+      window.ui = ui;
+    };
+  </script>
+    <div class="swagger-ui">
+		<div class="wrapper">
+			<section class="">
+				<span class="float-right">
+					<a target="_blank" rel="noopener noreferrer"
+						href="https://validator.swagger.io/validator/debug?url=${escapedDefinitionUrl}">
+						<img
+							src="https://validator.swagger.io/validator?url=${escapedDefinitionUrl}"
+							alt="Online validator badge"/>
+					</a>
+				</span>
+			</section>
+		</div>
+	</div>
+  <p class="swagger-ui-attribution">
+    This OpenAPI definition viewer is based on <a href="https://swagger.io/tools/swagger-ui/">Swagger UI</a>.
+  </p>
+  </body>
+</html>
\ No newline at end of file
diff --git a/tapestry-openapi-viewer/src/test/java/org/apache/tapestry5/.gitignore b/tapestry-openapi-viewer/src/test/java/org/apache/tapestry5/.gitignore
new file mode 100644
index 0000000..c80fc55
--- /dev/null
+++ b/tapestry-openapi-viewer/src/test/java/org/apache/tapestry5/.gitignore
@@ -0,0 +1 @@
+/TapestryFilter.java
diff --git a/tapestry-openapi-viewer/src/test/java/org/apache/tapestry5/tapestryopenapiviewer/test/services/AppModule.java b/tapestry-openapi-viewer/src/test/java/org/apache/tapestry5/tapestryopenapiviewer/test/services/AppModule.java
new file mode 100644
index 0000000..9a050d3
--- /dev/null
+++ b/tapestry-openapi-viewer/src/test/java/org/apache/tapestry5/tapestryopenapiviewer/test/services/AppModule.java
@@ -0,0 +1,23 @@
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+package org.apache.tapestry5.tapestryopenapiviewer.test.services;
+
+import org.apache.tapestry5.commons.Configuration;
+import org.apache.tapestry5.services.LibraryMapping;
+
+public class AppModule
+{
+    public static void contributeComponentClassResolver(Configuration<LibraryMapping> configuration)
+    {
+        configuration.add(new LibraryMapping("app1", "org.apache.tapestry5.integration.app1"));
+    }
+}
diff --git a/tapestry-openapi-viewer/src/test/webapp/WEB-INF/web.xml b/tapestry-openapi-viewer/src/test/webapp/WEB-INF/web.xml
new file mode 100644
index 0000000..2aad22b
--- /dev/null
+++ b/tapestry-openapi-viewer/src/test/webapp/WEB-INF/web.xml
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- 
+   Copyright 2021 The Apache Software Foundation
+
+   Licensed under the Apache License, Version 2.0 (the "License");
+   you may not use this file except in compliance with the License.
+   You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+-->
+
+<!DOCTYPE web-app
+        PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
+        "http://java.sun.com/dtd/web-app_2_3.dtd">
+<web-app>
+    <display-name>Integration Test App 1</display-name>
+    <context-param>
+        <param-name>tapestry.app-package</param-name>
+        <param-value>org.apache.tapestry5.tapestryopenapiviewer.test</param-value>
+    </context-param>
+    <filter>
+        <filter-name>app</filter-name>
+        <filter-class>org.apache.tapestry5.TapestryFilter</filter-class>
+    </filter>
+    <filter-mapping>
+        <filter-name>app</filter-name>
+        <url-pattern>/*</url-pattern>
+    </filter-mapping>
+</web-app>