package org.dbflute.intro.app.web;

import java.util.Map;

import javax.annotation.Resource;

import org.dbflute.intro.app.web.base.IntroBaseAction;
import org.dbflute.intro.mylasta.direction.IntroConfig;
import org.lastaflute.doc.SwaggerGenerator;
import org.lastaflute.doc.agent.SwaggerAgent;
import org.lastaflute.doc.web.LaActionSwaggerable;
import org.lastaflute.web.Execute;
import org.lastaflute.web.login.AllowAnyoneAccess;
import org.lastaflute.web.response.HtmlResponse;
import org.lastaflute.web.response.JsonResponse;
import org.lastaflute.web.servlet.request.RequestManager;

/**
 * @author cabos
 */
@AllowAnyoneAccess
public class SwaggerAction extends IntroBaseAction implements LaActionSwaggerable {

    // ===================================================================================
    //                                                                           Attribute
    //                                                                           =========
    @Resource
    private RequestManager requestManager;
    @Resource
    private IntroConfig config;

    // ===================================================================================
    //                                                                             Execute
    //                                                                             =======
    @Execute
    public HtmlResponse index() {
        verifySwaggerAllowed();
        String swaggerJsonUrl = toActionUrl(SwaggerAction.class, moreUrl("json"));
        return new SwaggerAgent(requestManager).prepareSwaggerUiResponse(swaggerJsonUrl);
    }

    @Execute
    public JsonResponse<Map<String, Object>> json() {
        verifySwaggerAllowed();
        return asJson(new SwaggerGenerator().generateSwaggerMap());
    }

    private void verifySwaggerAllowed() { // also check in ActionAdjustmentProvider
        verifyOrClientError("Swagger is not enabled.", config.isSwaggerEnabled());
    }
}

@@ -198,16 +198,59 @@
 Config;%0A
+import org.dbflute.optional.OptionalThing;%0A
 import o
@@ -754,16 +754,342 @@
 able %7B%0A%0A
+    // ===================================================================================%0A    //                                                                          Definition%0A    //                                                                          ==========%0A    private static final String _apiPrefix = %22api%22;%0A%0A
     // =
@@ -2132,16 +2132,169 @@
 erator()
+ %7B%0A            protected OptionalThing%3CString%3E prepareApplicationVersion() %7B%0A                return OptionalThing.of(_apiPrefix);%0A            %7D%0A        %7D
 .generat

add baseUrl to "api"