1.0.8 • Published 1 month ago

newton-aidocs v1.0.8

Weekly downloads
-
License
MIT
Repository
github
Last release
1 month ago

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

  1. Install newton globally:
npm install -g newton-aidocs
  1. 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

  1. Check the version you have installed:
npx newton --version
  1. 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

  1. 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);
});
.
.
.
  1. 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.

What is transmogrify?

1.0.8

1 month ago

1.0.7

1 month ago

1.0.6

1 month ago

1.0.5

1 month ago

1.0.4

1 month ago

1.0.3

1 month ago

1.0.2

1 month ago