Skip to content

How to build models, repositories and controllers dynamically at runtime #4296

@bajtos

Description

@bajtos

This is a follow-up for the spike #4235

So far, our documentation and tooling was focused on the use case where most of application artifacts are static, defined in source files. In the Epic From model definition to REST API #2036, we are working on a more declarative approach, where we have a model source file and a configuration file, and the bootstrapper creates the repository & controller classes during the boot process.

In this story, I would like to show our users even more flexible and dynamic approach, where they have full control of all aspects at runtime - from defining the model class (e.g. based on schema discovery) to exposing the REST API (or decide not to).

Examples

See the demo application presented in #4235:

  1. Accept a MySQL connection string (host+port+database+credentials) and a list of table names.
  2. Connect to the specified MySQL database.
  3. Discover model schemas from the given tables
  4. Define LB4 models for the given tables
  5. Expose these models via REST API
  6. Return a list of URL paths of the newly added models (e.g. /Products, /CoffeeShops)

Acceptance criteria

A new documentation page with the following sections & content:

MUST HAVE

  • Define a model class from a ModelDefinition object
  • Define a repository class for the given model, how to configure dependencies (the datasource to use)
  • Define a controller class for the given model & repository, how to configure dependencies (the repository to use) and how to build the REST API path (e.g. /products for Product model).
  • Discover model definition from a database, build ModelDefinition object from the discovered schema in juggler/LB3 format.

The page can use code snippets from the demo controller (see #4235) to illustrate the approach in practice.

SHOULD HAVE

These items are not strictly required for the initial version. If you decide to leave them out, then create follow-up stories and/or move them to acceptance criteria of and existing story like #2740.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions