    001// Copyright 2021 The Apache Software Foundation
    002//
    003// Licensed under the Apache License, Version 2.0 (the "License");
    004// you may not use this file except in compliance with the License.
    005// You may obtain a copy of the License at
    006//
    007// http://www.apache.org/licenses/LICENSE-2.0
    008//
    009// Unless required by applicable law or agreed to in writing, software
    010// distributed under the License is distributed on an "AS IS" BASIS,
    011// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    012// See the License for the specific language governing permissions and
    013// limitations under the License.
    014package org.apache.tapestry5.openapiviewer.pages;
    015
    016import java.io.UnsupportedEncodingException;
    017import java.net.URLEncoder;
    018
    019import org.apache.tapestry5.SymbolConstants;
    020import org.apache.tapestry5.annotations.Cached;
    021import org.apache.tapestry5.http.services.BaseURLSource;
    022import org.apache.tapestry5.http.services.Request;
    023import org.apache.tapestry5.ioc.annotations.Inject;
    024import org.apache.tapestry5.ioc.annotations.Symbol;
    025
    026/**
    027 * Shows an OpenAPI definition viewer based on Swagger UI.
    028 */
    029public class Index {
    030
    031    @Inject
    032    private BaseURLSource baseURLSource;
    033
    034    @Inject
    035    @Symbol(SymbolConstants.OPENAPI_DESCRIPTION_PATH)
    036    private String descriptionPath;
    037
    038    @Inject
    039    private Request request;
    040
    041    @Cached
    042    public String getEscapedDefinitionUrl() throws UnsupportedEncodingException
    043    {
    044        return URLEncoder.encode(baseURLSource.getBaseURL(request.isSecure()) + descriptionPath, "UTF-8");
    045    }
    046
    047}