Skip to content

Java and JAX-RS: auto generate class containing all resources #171

@giovannibotta

Description

@giovannibotta

The generated Java API is composed of a bunch of classes each representing a JAX-RS resource. I am ok with this code structure, but I'd like to have an additional class that encapsulate those in order to set once and for all the api key or the base path of the endpoints. It would be something like this:

class Api {
  String token, path;
  SomeApi getSomeApi(){
    return new SomeApi(token, path);
  }
  SomeOtherApi getSomeOtherApi(){
    return new SomeApi(token, path);
  }
}

In this way the clients only have to create an instance of Api with the correct token and base path and that'll get propagated. It's like a giant builder class basically.

Is it possible to write a mustache file that uses each resource and creates these methods? There would obviously be a convention for the constructor.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions