1.0.9 • Published 5 months ago

api2notionsync v1.0.9

Weekly downloads
-
License
ISC
Repository
github
Last release
5 months ago

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

ParameterTypeDefaultDescription
-r, --runNONENONEInitiates posting of API documentation to Notion.
-v, --versionNONENONEDisplays the library's version.
-h, --helpNONENONEProvides help regarding library options.
--hoststringNONESets 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_KEYstringNONEEnter your NOTION API KEY obtained from the Notion API. Set it as an environment variable, registerable via EXPORT NOTION_API_KEY=?.
--NOTION_PAGE_IDstringNONEEnter your NOTION PAGE ID obtained from the Notion API. Set it as an environment variable, registerable via EXPORT NOTION_PAGE_ID=?.
-m, --markdownbooleanfalseUse this option to convert the document to markdown without posting to Notion. Saved as docs.md in the library's temp directory.
-i, --inputstring.\resourceIf 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.
``` properties
//.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.
1.0.9

5 months ago

1.0.8

5 months ago

1.0.2

5 months ago

1.0.1

5 months ago

1.0.0

5 months ago

1.0.7

5 months ago

1.0.6

5 months ago

1.0.5

5 months ago

1.0.4

5 months ago

1.0.3

5 months ago

0.1.11

5 months ago

0.1.12

5 months ago

0.1.13

5 months ago

0.1.14

5 months ago

0.1.15

5 months ago

0.1.10

5 months ago

0.1.9

5 months ago

0.1.8

5 months ago

0.1.7

5 months ago

0.1.6

5 months ago

0.1.5

5 months ago

0.1.2

5 months ago

0.1.1

5 months ago

0.1.4

5 months ago

0.1.3

5 months ago

0.1.0

5 months ago

0.0.4

5 months ago

0.0.3

5 months ago

0.0.2

5 months ago

0.0.1

5 months ago