Sage-Bionetworks / research-benchmarking-technology

Main repository of the Research & Benchmarking Technology Team
Apache License 2.0
1 stars 1 forks source link

Create mustache template as part of the openapi-generator templates to create mongo db models #7

Closed thomasyu888 closed 2 years ago

thomasyu888 commented 3 years ago

Currently mongo DB models have to be created manually, but I think this could potentially be created automatically.

tschaffter commented 2 years ago

DB and API models may not be a 1:1 match. At best a generator could be used to generate the initial schemas, which would likely need to be tailored.

There is actually a generator called mysql-schema provided by openapi-generator that generate MySQL instructions to create the DB and tables. However this does not generate Python DB models that can be used in a Flask app, for example. To see the type of files generated by this generator using the ROCC OpenAPI specification as example, run the command npx @openapitools/openapi-generator-cli generate -g mysql-schema -o schema -i https://sage-bionetworks.github.io/rocc-schemas/latest/openapi.yaml. The folder schema will automatically be created and populated with the generated files.

BTW I created MongoDB model for TypeScript and the client library Mongoose last week. It took me about half a day coming up with the model while also writing code to use these models, which is not much time.