001// Generated by delombok at Mon Oct 12 22:51:05 BST 2020
002/*
003 *  Licensed to the Apache Software Foundation (ASF) under one
004 *  or more contributor license agreements.  See the NOTICE file
005 *  distributed with this work for additional information
006 *  regarding copyright ownership.  The ASF licenses this file
007 *  to you under the Apache License, Version 2.0 (the
008 *  "License"); you may not use this file except in compliance
009 *  with the License.  You may obtain a copy of the License at
010 *
011 *        http://www.apache.org/licenses/LICENSE-2.0
012 *
013 *  Unless required by applicable law or agreed to in writing,
014 *  software distributed under the License is distributed on an
015 *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
016 *  KIND, either express or implied.  See the License for the
017 *  specific language governing permissions and limitations
018 *  under the License.
019 */
020package org.apache.isis.viewer.restfulobjects.rendering.service.swagger;
021
022import javax.inject.Inject;
023import javax.inject.Named;
024import org.springframework.beans.factory.annotation.Qualifier;
025import org.springframework.context.annotation.Primary;
026import org.springframework.core.annotation.Order;
027import org.springframework.stereotype.Service;
028import org.apache.isis.applib.annotation.OrderPrecedence;
029import org.apache.isis.applib.services.swagger.SwaggerService;
030import org.apache.isis.commons.internal.base._Strings;
031import org.apache.isis.core.config.RestEasyConfiguration;
032import org.apache.isis.core.config.viewer.wicket.WebAppContextPath;
033import org.apache.isis.viewer.restfulobjects.rendering.service.swagger.internal.SwaggerSpecGenerator;
034
035@Service
036@Named("isisMetaModel.swaggerServiceDefault")
037@Order(OrderPrecedence.MIDPOINT)
038@Primary
039@Qualifier("Default")
040public class SwaggerServiceDefault implements SwaggerService {
041    private final SwaggerSpecGenerator swaggerSpecGenerator;
042    private final String basePath;
043
044    @Inject
045    public SwaggerServiceDefault(final SwaggerSpecGenerator swaggerSpecGenerator, final RestEasyConfiguration restEasyConfiguration, final WebAppContextPath webAppContextPath) {
046        this.swaggerSpecGenerator = swaggerSpecGenerator;
047        final java.lang.String restfulPath = restEasyConfiguration.getJaxrs().getDefaultPath();
048        final java.lang.String restfulBase = webAppContextPath.prependContextPath(restfulPath);
049        this.basePath = _Strings.suffix(restfulBase, "/");
050    }
051
052    @Override
053    public String generateSwaggerSpec(final Visibility visibility, final Format format) {
054        return swaggerSpecGenerator.generate(basePath, visibility, format);
055    }
056}