-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Description
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:
- Accept a MySQL connection string (host+port+database+credentials) and a list of table names.
- Connect to the specified MySQL database.
- Discover model schemas from the given tables
- Define LB4 models for the given tables
- Expose these models via REST API
- 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
ModelDefinitionobject - 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.
/productsforProductmodel). - Discover model definition from a database, build
ModelDefinitionobject 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.
- How to use a custom Model base class (e.g.
UserBaseprovided by the app) instead ofModelorEntity. - How to use a custom Repository base class (e.g.
MyCustomRepositoryprovided by the app) instead ofDefaultCrudRepository. We need to explain how to create a custom repository class (I think this part belongs to Repositories part of our docs?) and how to build a function for creating named repository classes from the repository class. For the second part, we can tell users to copy the code fromdefineCrudRepositoryClassfunction. See also Docs for exposing REST API of a Model with no custom classes #2740. - How to use a custom Controller to create a custom REST API. The current answer is to copy the code from
defineCrudRestController function. See also Docs for exposing REST API of a Model with no custom classes #2740.