newton-aidocs
v1.0.8
Published
A CLI that creates your API documentation for you with AI
Downloads
15
Maintainers
Readme
Example
Node.js (Express) project
[showing input and outputs]
const express = require('express');
const app = express();
app.post('/users', (req, res) => {
const { username, email } = req.body;
res.status(200).json({ message: 'User created successfully', username, email });
if (!username || !email) {
res.status(400).send('Missing required arguments');
}
});
.
.
.
[full source in examples/express-app/index.js]
Set up
Installing
- Install
newton
globally:
npm install -g newton-aidocs
- Perform first time set up by configuring
newton
with an OpenAI API key that has billing set up:
npx newton
Note: This creates a
.newton
file in your home directory where this API key, along with any other future customizable newton configurations, is stored.
Updating
- Check the version you have installed:
npx newton --version
- If it is not equivalent to the latest version:
npm update -g newton-aidocs
Usage
To start an interactive prompt to provide newton
with the details to generate the documentation for your API:
npx newton
If you have an existing api-documentation.json
file previously generated by newton
and want to export it to another newton
format (i.e. Markdown, HTML, Next.js):
npx newton -t
Changelog
Specifications
- For Express.js (Node.js) projects,
newton
works best when:
- the input file contains Express.js routes, e.g. where each route begins on a new line with
app.{get, post, put, delete}
:
const express = require('express')
const app = express()
const port = 80
app.use(express.json());
app.post('/api/auth', async (req, res) => {
const uid = req.body.uid;
const user = db.collection('users').doc(uid);
await user.set({
uid: uid,
last_login: Timestamp.now(),
});
res.send('Logged in user with uid ' + uid);
});
.
.
.
- For Flask (Python) projects,
newton
works best when:
- the input file contains the Flask routes, e.g. where each route begins on a new line with
@app.route
:
from flask import Flask, request
.
.
.
app = Flask(__name__)
@app.route("/user/metadata", methods=['GET'])
def get_user():
email = request.args.get('email')
user = users.get_user(email)
return user, 200
@app.route("/user/create", methods=['POST'])
def create_user():
email = request.args.get('email')
role = request.args.get('role')
if role not in ["staff"]:
return "Invalid role", 400
user_created = users.create_user(email, role)
return user_created, 200
.
.
.
Note: The files mentioned above are provided for illustrative purposes only and do not guarantee functionality. However, their formats served as a guideline for Newton's parsing functionalities.