-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Closed
Labels
Description
Description / Steps to reproduce / Feature proposal
The intention of this proposal is to create a fully functional REST API with ease imported from a schema and using an existing CLI tool lb4 openapi.
Current Behavior
Currently, the OpenAPI generator lb4 openapi is missing several functionalities:
- The command creates only partial properties information for models listed in the
yamlschema.
For example:
// IN CUSTOMER.JSON MODEL FILE (LB3):
...
"properties": {
"id": {
"type": "string",
"id": true,
"description": "Customer ID",
"defaultFn": "uuid",
"postgresql": {
"owner": "public",
"tableName": "customer",
...
}
...
}
...
// TRANSLATES INTO THIS IN CUSTOMER.MODEL.TS MODEL FILE (LB4):
...
@property({name: 'id'})
id: string;
...
- No repositories or datasources are created with the command.
- All controller CRUD methods are implemented with throwing a "Not implemented" error.
Expected Behavior
In order to provide basic but functional application, this is my proposal after reading this comment:
- Create a default repository file to provide default CRUD operations (same as using the CLI command lb4 repository):
For each model provided in the yaml schema, create a<model_name>.repository.tsfile that contain basic CRUD operations. - Use the newly created repository to provide basic functionality in the Controller file (instead of throwing "not implemented" errors).
- Add support for custom attributes in the yaml schema for relations and datasource:
current generator does not create a datasource connector, and there is no relations creation (although there is an issue #1359 regarding this).
The datasource file should be generated the same as creating one using the CLI command lb4 datasource.
It is possible using the OpenAPI extentions support to define properties for relations and datasource. For example, in the OpenAPIyamlfile:
...
Customer:
properties:
id:
description: Customer ID
type: string
name:
type: string
required:
- id
additionalProperties: false
x-lb-relations: <==== NEW ATTRIBUTE HERE
orders:
type: hasMany
model: Order
x-lb-datasource: postgreSQL <==== NEW ATTRIBUTE HERE
Order:
properties:
id:
description: Customer ID
type: string
name:
type: string
required:
- id
additionalProperties: false
x-lb-relations: <==== NEW ATTRIBUTE HERE
customer:
type: belongsTo
model: Customer
x-lb-datasource: postgreSQL <==== NEW ATTRIBUTE HERE
...
manjubhat and TomerSalton