-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[CLI] Generate full REST API (model+repository+controller) from model schema #2090
Comments
Thank you @orshlom for the proposal. Could you please describe the scenario you are trying to address in more details, from the point of view of LB4 app developer? Are you trying to import Swagger spec generated from a LB3 application into a LB4 application, as a tool for migrating from LB3 to LB4? Or is the intention to import arbitrary OpenAPI Schema, allowing LB4 app developers to maintain additional metadata inside the OpenAPI spec (as opposed to having the metadata in TypeScript code)? I'd also like to improve the GH issue title to better describe the specifics. Would the following text describe your scenario correctly? [CLI] Generate full REST API (model+repository+controller) from model schema Also, how do you envision keeping the model schema and the generated TypeScript artifacts in sync? For example, when a new property is added to the model schema, how would you like to update the generated model TS file? When a new relation is added, how would you like to update the generated repository TS file? If the intention is to use some sort of a schema as the single source of truth for the data access (model + repository), then it may be better to define models & repositories at runtime (similarly to how LB3 works) and skip the code generation. See #2036 and #565 |
Another option might be for The openapi spec is not explicit in the kind of link (one, many, belongs, etc.) so openapi extensions could be used to explain what kind of relationship (link) exists. |
@orshlom Thank you for kicking off the discussion. +1 to introduce Please also check out strongloop/loopback-swagger#81. It added some extensions to |
Thanks for commenting @bajtos and @raymondfeng. I agree with the new title name, as it better suits this proposal. The #2036 you have mentioned discusses about creating functionality in runtime. My intention, however, is to have the relevant files for keeping the ability to extend the basic functionality of the models. Some elaboration for the proposal, based on your comments:
|
Thank you for describing the difference, I better understand your use case now. There is still one aspect that's not clear to me:
Are we talking about the initial scaffolding only, where the developer takes the YAML file and produces a set of model/repository/controller files, and any further updates must be done in the scaffolded files? If that's the goal, then I am proposing to investigate non-interactive JSON model offered by our CLI (CLI args Conceptually:
I am afraid our current documentation in Command line interface does not correctly describe configuration formats used by different commands. I guess you will have to discover this from source code. It would be great if you could contribute this knowledge into our documentation afterwards. |
Thanks @bajtos ! The CLI
Not really. For our use case, the generated code is something that should not be edited since the build process we will put in place will likely overwrite any changes made to generated code. So this would be more than initial scaffolding. The files would already include the necessary updates for default CRUD. |
Interesting. How do you envision to apply the necessary updates? Also if the generated code should be never modified, then what is the advantage of generating the source code files over the approach described in #2036, where the repository & controllers are defined at runtime only? |
Updates should be made to the source of truth ( If we can avoid generating code and use the in-memory approach that might be a good option for us. Your comment in #1889 (comment) seems like a possible approach for this. |
PR #2245 is in progress, moving it to the "In Progress" pipeline. |
This issue has been marked stale because it has not seen activity within six months. If you believe this to be in error, please contact one of the code owners, listed in the |
This issue has been closed due to continued inactivity. Thank you for your understanding. If you believe this to be in error, please contact one of the code owners, listed in the |
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:yaml
schema.For example:
Expected Behavior
In order to provide basic but functional application, this is my proposal after reading this comment:
For each model provided in the yaml schema, create a
<model_name>.repository.ts
file that contain basic CRUD operations.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 OpenAPI
yaml
file:The text was updated successfully, but these errors were encountered: