

GitHub - sugarkubes/generators: API Generator - instantly generate REST and Grap...
source link: https://github.com/sugarkubes/generators
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

README.md
Instantly Generate Rest & GraphQL OAS 3.0 compliant APIs ?
Install
npm i -g sugar-generate
Prereqs
- have mongodb installed and running!
- have nodejs installed
Getting Started
- Create your schema. It could be as simple as:
{ "schema": { "name": { "type": "String", "default": "" }, "isDead": { "type": "Boolean", "default": false }, "age": { "type": "Number", "default": false } }, "statics": {} }
save this to monkey.json
- generate your api
sugar-generate \ --type api \ --name monkey \ --schema ./samples/monkey.json \ --destination /private/var/andrew/generator-tests/3
- Run or build the docker container and visit http://localhost:3000
cd /wrannaman/generator npm i npm start # Or build the docker container! docker build -t myMonkeys:0.1.0 .
Features ?
- Generates simple Nodejs code
- Graphql and Rest out of the box
- Uses Mongodb with Mongoose ORM
- Easy to build / deploy
- Dockerfile included
- Generates CRUD APIs
- create
- get (many, with pagination; supports search, sort, filter, pagination out of the box)
- getOne
- update
- delete
What it's good at ?
- Generating an initial API
- Microservice oriented
- Ready to deploy (build with docker => deploy)
What it's not good at (yet) ?
- idempotent changes (i.e. it doesn't know if you wrote code in there or changed things around)
- working with modified code
- populating table joins
- custom actions inside controller functions
How It Works
- Feed it a json schema (see below's Example Schema)
- Name it
- Tell it where to put the code.
- Build your generated code with the docker file
- Deploy it and move on
TODO
- basic generator tests
- graphql tests
- other databases?
- your ideas?
- react components for the api?!?!
- middleware for auth, token validation, etc.
Example Schema
{ "schema": { "first_name": { "type": "String", "default": "" }, "last_name": { "type": "String", "default": "" }, "email": { "type": "String", "trim": true, "required": true, "unique": true, "immutable": true, // Don't let this change from api on update }, "password": { "type": "String", "trim": true, "select": false, "immutable": true, // Don't let this change from api on update }, "intro": { "type": "Boolean", "default": false }, "team": { "type": "ObjectId", // This references another collection "ref": "Team" }, "sub": { "one": { "type": "String", "trim": true, "required": true }, "two": { "type": "Number", "required": true } }, "role": { "type": "String", "enum": ["user", "maker"], "default": "user" } }, "statics": { "statuses": ["created", "under_review", "listed", "deleted"], "status": { "active": "active", "inactive": "inactive", "deleted": "deleted" } } }
Graphql support
graphql is supported and gets created by default so you can choose between rest and graphql
Graphql is on http://localhost:3000/graphql
Generated project structure
.
├── configs # Config File
├── connection # DB Connections (mongo, redis)
├── controller # Controllers
│ ├── <model name> # Functions (one file, one function) create, delete, update, get, getOne
├── models # DB Models
├── router # Endpoint Routes
├── tests # Single Test File
Generated tests
** WARNING ** running the tests will pull the config file from configs/config.json and clear the DB
npm run test
Recommend
-
39
quicktype can now generate Kotlin types and serializers from JSON sample data. Here's the Pokémon sample running in a quicktype playground, demonstrating Kotlin, Java, and Swift code generated from the same sample JSON data: .quicktype { dis...
-
106
README.md 老婆生成器Random waifu generator 网址 一键生成老婆 施工中 rep...
-
9
New validate() Method, First configurable Generator (MSBuildDeps), Renamed Multiple Toolchains & Generators, 2 New Meson Classes, Improve Lockfile Support for Private Requirements, Support for build_requires to Affect package_id (Workaround)...
-
11
Use Iterators, Generators, and Generator ExpressionsBy Rahul Agarwal 28 November 2020
-
9
How to generate code using Roslyn source generators in real world scenariosRoslyn (as of 16.8 Preview 3) now brings first-class support for source code generators that run as part of a project compilation. The provided
-
19
In the previous post, I described the LoggerMessage source generator that can give performance benefits without the boilerplate. In this post I look at the updates to the source generator API in .NET 6, why the changes were made,...
-
7
Generate SEO-optimized content instantly with Juice.ai
-
7
Support is great. Feedback is even better."PageGenie is still a prototype and MVP. I'd love to get your guys input to see whether this tool is actually something which you'd like to see developed further, as well as any suggestions y...
-
10
ChatGPT powered platform to instantly generate workflowsSort by: I'd be curious to hear from the engineering team, what do you think was the most challenging part of gettin...
-
10
Generate Text & Convert it into Human-like Speech instantlyAudiosonicGenerate Text & Convert it into Human-like Speech instantlyFree Options
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK