npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

api2notionsync

v1.0.9

Published

Automatically synchronizes the `api-docs` in OpenAPI format or swagger to `Notion`

Downloads

46

Readme

API2NotionSync

Automatic Posting API docs to Notion

Known Issues

  • ~~Permission Error Issue~~ / Resolved on 2023-12-12
  • ~~Environment Variable Application Error~~ / Resolved on 2023-12-12

Table of Contents

CLI Global

To Install

  • Clone the repository and run npm install
  • or, install globally with npm install -g api2notionsync

Example

api2notionsync --run --host "https://www.example.com" --NOTION_API_KEY {your_API_KEY} --NOTION_PAGE_ID {your_notion_page_id}

Options

| Parameter | Type | Default | Description | | --- | --- | --- | --- | | -r, --run | NONE | NONE | Initiates posting of API documentation to Notion. | | -v, --version | NONE | NONE | Displays the library's version. | | -h, --help | NONE | NONE | Provides help regarding library options. | | --host | string | NONE | Sets the host of the server with swagger or OpenApi v3 documentation. This is set as an environment variable and can be registered using EXPORT SERVER_HOST=?. Retrieves the file from /v3/api-docs.yaml. | | --NOTION_API_KEY | string | NONE | Enter your NOTION API KEY obtained from the Notion API. Set it as an environment variable, registerable via EXPORT NOTION_API_KEY=?. | | --NOTION_PAGE_ID | string | NONE | Enter your NOTION PAGE ID obtained from the Notion API. Set it as an environment variable, registerable via EXPORT NOTION_PAGE_ID=?. | | -m, --markdown | boolean | false | Use this option to convert the document to markdown without posting to Notion. Saved as docs.md in the library's temp directory. | | -i, --input | string | .\resource | If you have a .YAML API document formatted to OAS v3, enter its absolute path. If entered correctly, the file from your local path will be used. |

Using in Projects

To Install

  • npm install api2notionsync

server.js

// server.js
const api2notionsync = require('api2notionsync');

/* your swagger setting */

// Check if the following swagger-jsdoc settings are present
const swaggerYaml = yaml.dump(swaggerSpec);
app.get('/v3/api-docs.yaml', (req, res) => {
    res.setHeader('Content-Type', 'application/yaml');
    res.send(swaggerYaml);
});

/* your server code */

// append this command
api2notionsync.run();

You can optionally specify the arguments to pass when calling the method.

api2notionsync.run({ isMarkdownOnly: true, pathInput: "./your/path" });

api2notionsync.run({ pathInput: "./your/path" });

Setting .env Environment Variables

Ensure your .env file contains API key information for Notion and the server host for API documentation. Read the .env file using the dotenv library.

//.env file

NOTION_API_KEY=secret_example
NOTION_PAGE_ID=example
SERVER_HOST=https://www.example.com

Setting Environment Variables in Terminal

Without a .env file, you can directly set environment variables in the terminal as follows:

Linux, macOS

export NOTION_API_KEY="secret_example"
export NOTION_PAGE_ID="example"
export SERVER_HOST="https://www.example.com"

Windows (PowerShell)

$env:NOTION_API_KEY="secret_example"
$env:NOTION_PAGE_ID="example"
$env:SERVER_HOST="https://www.example.com"

Anticipated Issues

1. SaveApiDocs Stage - Waiting for Axios

Issue

Occurrence of 저장 대기 n회

Our library searches for a file named api-docs.yaml at SERVER_HOST/v3/api-docs.yaml.
If unable to find this path, it sends requests up to 10 times every 5 seconds Continuous occurrence of 저장 대기 n회 indicates a need to check the v3/api-docs.yaml path.

Solution

  • Java: The yaml path is automatically set. Issues have been identified with v2, and a fix is planned.
  • Node: You must manually specify the path using swagger-jsdoc. If you have set up swagger using swagger-ui-express, it's a straightforward process. Insert the following code in a suitable location within your JS project.
const swaggerJsdoc = require('swagger-jsdoc');
const yaml = require('js-yaml');

const swaggerYaml = yaml.dump(swaggerSpec);

// An example app.use code for comparison.
// app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerSpec));

app.get('/v3/api-docs.yaml', (req, res) => {
    res.setHeader('Content-Type', 'application/yaml');
    res.send(swaggerYaml);
});

2. All Tag Docs Posting - Failure to Post

Issue

Occurrence of a red gauge during All Tag Docs Posting

Checking node_modules/log/trace.error is the best approach.
Typically, failure to post a specific item stems from Notion Api specifications, often occurring when the converted Md is excessively large. If failures persist for all postings, check the status of the Notion page and network.

Solution

  • Continuous failure for all postings: Check the status of the Notion page and network.
  • Failure of individual postings: Separate the API requests. A fix is planned for this issue.