Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Sep 26 00:19
    dependabot[bot] labeled #2643
  • Sep 26 00:19
    dependabot[bot] labeled #2643
  • Sep 26 00:19

    dependabot[bot] on maven

    build(deps): bump rest-assured … (compare)

  • Sep 26 00:19
    dependabot[bot] opened #2643
  • Sep 19 12:41
    jknack closed #2309
  • Sep 19 11:44

    dependabot[bot] on maven

    (compare)

  • Sep 19 11:44

    jknack on 3.x

    build(deps): bump aws-java-sdk-… Merge pull request #2642 from j… (compare)

  • Sep 19 11:44
    jknack closed #2642
  • Sep 19 11:44

    dependabot[bot] on maven

    (compare)

  • Sep 19 11:44
    jknack milestoned #2642
  • Sep 19 11:44
    jknack milestoned #2642
  • Sep 19 11:44

    jknack on 3.x

    build(deps): bump okhttp.versio… Merge pull request #2641 from j… (compare)

  • Sep 19 11:44
    jknack closed #2641
  • Sep 19 11:24
    dependabot[bot] labeled #2642
  • Sep 19 11:24
    dependabot[bot] labeled #2642
  • Sep 19 11:24

    dependabot[bot] on maven

    build(deps): bump aws-java-sdk-… (compare)

  • Sep 19 11:24
    dependabot[bot] opened #2642
  • Sep 19 10:26
    dependabot[bot] synchronize #2641
  • Sep 19 10:26

    dependabot[bot] on maven

    build(deps): bump okhttp.versio… (compare)

  • Sep 19 10:26
    dependabot[bot] edited #2641
Nguyen Huu Tuan
@snowyukischnee

i've work around this problem by move the OpenAPIDefinition to the RouterConfig class

@OpenAPIDefinition(
        info = @Info(
                title = "Title",
                description = "description",
                termsOfService = "Terms",
                contact = @Contact(
                        name = "Jooby",
                        url = "https://jooby.io",
                        email = "support@jooby.io"
                ),
                license = @License(
                        name = "Apache",
                        url = "https://jooby.io/LICENSE"
                ),
                version = "10"
        ),
        tags = @Tag(name = "mytag")
)
public class RouterConfig implements Extension {

    @Override
    public void install(@Nonnull Jooby app) throws Exception {
        app.mvc(CustomerController.class);
    }
}

and create my customized openapi module

public class CustomOpenAPIModule extends OpenAPIModule {

    private Class<?> apiDefinitionClass;

    public CustomOpenAPIModule(Class<?> apiDefinitionClass) {
        super();
        this.apiDefinitionClass = apiDefinitionClass;
    }

    @Override
    public void install(@Nonnull Jooby application) throws Exception {
        String dir = Optional.ofNullable(apiDefinitionClass.getPackage()).map(Package::getName).orElse("/").replace(".", "/");
        String appname = apiDefinitionClass.getSimpleName();
        Field fFormat = getClass().getSuperclass().getDeclaredField("format");
        fFormat.setAccessible(true);
        EnumSet<Format> format = (EnumSet<Format>) fFormat.get(this);
        Field fopenAPIPath = getClass().getSuperclass().getDeclaredField("openAPIPath");
        fopenAPIPath.setAccessible(true);
        String openAPIPath = (String) fopenAPIPath.get(this);
        for (Format ext : format) {
            String filename = String.format("/%s.%s", appname, ext.name().toLowerCase());
            String openAPIFileLocation = Router.normalizePath(dir) + filename;
            application.assets(Router.noTrailingSlash(Router.normalizePath(openAPIPath + "/openapi." + ext.name().toLowerCase())), openAPIFileLocation);
        }
        Method mConfigureUI = getClass().getSuperclass().getDeclaredMethod("configureUI", Jooby.class);
        mConfigureUI.setAccessible(true);
        mConfigureUI.invoke(this, application);
    }
}

and this is work fine except my code will be bad

Edgar Espina
@jknack
Ok, but why?
why do you need to put the controller inside an Extension?
for example, you are forking how it works and might miss something new from module (like bug fixing, new features, etc)
Also, open-api doesn’t use reflection and your version does it… not necessarily bad but not need it
Nguyen Huu Tuan
@snowyukischnee
yes, this is just a workaround
since my project structure that will seperate the route register from the main app
the App class contains no information about it will has route A or route B
I just move the definition to another to do that
Edgar Espina
@jknack
don’t get it
but if you ruly want this, try this instead: https://jooby.io/#router-composing-routes
So you still have your “MainApp"
Nguyen Huu Tuan
@snowyukischnee
yes
Edgar Espina
@jknack
then you create N more routers and from there you register the mvc controllers
Nguyen Huu Tuan
@snowyukischnee
i just dont want to define everything inside my main
Edgar Espina
@jknack
class A extens Jooby {
   {
      mvc(Controller.class);
   }
}
Then:
Nguyen Huu Tuan
@snowyukischnee
public static void main(String[] args) {
        Jooby.runApp(args, app -> {
            // app name
            app.setName(App.class.getSimpleName());
            app.install(new GracefulShutdown());
            app.decorator(new AccessLogHandler());
            app.error(new HttpDefaultJsonHandler());
            // metrics
            app.install(new MetricsModule("/actuator")
                    .threadDump()
                    .ping()
                    .healthCheck("deadlock", new ThreadDeadlockHealthCheck())
                    .metric("memory", new MemoryUsageGaugeSet())
                    .metric("threads", new ThreadStatesGaugeSet())
                    .metric("gc", new GarbageCollectorMetricSet())
                    .metric("fs", new FileDescriptorRatioGauge())
            );
            // openapi
            app.install(new CustomOpenAPIModule(RouterConfig.class));
            // dependency injection
            app.install(new GuiceModule(
                    // inject here
            ));

            app.mvc(CustomerController.class);
        });
    }
like this
Edgar Espina
@jknack
Jooby.runApp(args, app -> {
    app.use(new A());
})
that is supported by open api
and follow the design/goal of extensions: infrasture support
Nguyen Huu Tuan
@snowyukischnee
so I'll have to define every config inside the instance?
since I've familiar with spring and I just want to rewrite my project using a different framework
Edgar Espina
@jknack
don’t follow
What you show me, looks good. Just remove the install you did for your custom module:
```
public static void main(String[] args) {
        Jooby.runApp(args, app -> {
            // app name
            app.setName(App.class.getSimpleName());
            app.install(new GracefulShutdown());
            app.decorator(new AccessLogHandler());
            app.error(new HttpDefaultJsonHandler());
            // metrics
            app.install(new MetricsModule("/actuator")
                    .threadDump()
                    .ping()
                    .healthCheck("deadlock", new ThreadDeadlockHealthCheck())
                    .metric("memory", new MemoryUsageGaugeSet())
                    .metric("threads", new ThreadStatesGaugeSet())
                    .metric("gc", new GarbageCollectorMetricSet())
                    .metric("fs", new FileDescriptorRatioGauge())
            );
            // openapi
            app.install(new OpenApiModule());
            // dependency injection
            app.install(new GuiceModule(
                    // inject here
            ));

            app.mvc(CustomerController.class);
        });
    }
```
Nguyen Huu Tuan
@snowyukischnee
okay
Edgar Espina
@jknack
Another thing to keep in mind if you come from Spring
is the Guice bean scope: prototype (new insance each time)
while spring ccontroller are singleton by default
Nguyen Huu Tuan
@snowyukischnee
yes, i've see the different
another question
in the mvc controller, how can i define a filter
i cant find it anywhere inside the mvc api section
Edgar Espina
@jknack
well yea, we don’t have that type of composition/isolation yet
the way it works is like every other route
so if you need a filter for a controller:
decorator(next -> ctx -> …);

mvc(Controller.class);
so that route run before all controller routes
Nguyen Huu Tuan
@snowyukischnee
oh
Edgar Espina
@jknack
yea, controller methods are “expanded” as lambda routes by APT proccessor
pipeline works exactly the same
Nguyen Huu Tuan
@snowyukischnee
so i might switch to router
i've worked with expressjs before
Edgar Espina
@jknack
yea it is similar
Nguyen Huu Tuan
@snowyukischnee
and this router look similar
Edgar Espina
@jknack
1.x was identical
2.x is similar not identical
Nguyen Huu Tuan
@snowyukischnee
i've not look into the 1.x yet