diff --git a/README.md b/README.md index 6a1e6fd..ba618df 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,7 @@ SPDX-License-Identifier: AGPL-3.0-or-later - [🎮 Quick start](#-quick-start) - [💾 Build](#-build) + - [💾🪫 Build on ARM32](#-build-on-arm32) - [🐋 Docker](#-docker) - [🔧 Configuration](#-configuration) - [📋 Testing](#-testing) @@ -130,6 +131,9 @@ Options: * `--openapi-path ` env: **OPENAPI_PATH** specify where to mount the swagger docs (default: "/docs") + * `--openapi-info ` + env: **OPENAPI_INFO** + provide the json info for the swagger docs (default: "./openapi_info.json") * `--hostname ` env: **HOSTNAME** Provide the hostname to serve the server (default: "0.0.0.0") diff --git a/src/cli.ts b/src/cli.ts index af26dba..422832c 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -75,6 +75,11 @@ program .env('OPENAPI_PATH') .default('/docs') ) + .addOption( + new Option('--openapi-info ', 'Provide the json info for the swagger docs') + .env('OPENAPI_INFO') + .default('./openapi_info.json') + ) .addOption( new Option('--hostname ', 'specify the hostname to serve the server') .env('HOSTNAME') diff --git a/src/openapi.ts b/src/openapi.ts index ef17da7..c568d54 100644 --- a/src/openapi.ts +++ b/src/openapi.ts @@ -7,6 +7,7 @@ import { OpenAPIV3_1 } from 'openapi-types'; import p from '../package.json' with { type: 'json' }; import { JSONSchema, Metadata } from './types.js'; import { config } from './cli.js'; +import { readFileSync } from 'fs'; export const defaultTagsName = { zen: '📑 Zencode APIs', @@ -119,30 +120,41 @@ export const defaultTags = [ } ]; -export const definition: Partial = { - openapi: '3.1.0', - paths: {}, - info: { - title: 'noˑcodeˑroom', - version: p.version, - description: `## Restful api from zencode smart contracts with no code! +const openapiInfo = { + title: 'noˑcodeˑroom', + version: p.version, + description: `## Restful api from zencode smart contracts with no code! This is a simple API autogenerated from a folder within your server. To add new endpoints you should add new zencode contracts in the directory. **NB** The files should be in form of \`endpoint.zen\` then your contract will run on \`/endpoint\``, - termsOfService: 'https://forkbomb.solutions/privacy-policy/', - contact: { - email: 'info@forkbomb.eu', - name: 'Forkbomb BV', - url: 'https://forkbomb.solutions' - }, - license: { - name: 'GNU Affero General Public License v3.0 or later', - url: 'https://www.gnu.org/licenses/agpl-3.0' - } + termsOfService: 'https://forkbomb.solutions/privacy-policy/', + contact: { + email: 'info@forkbomb.eu', + name: 'Forkbomb BV', + url: 'https://forkbomb.solutions' }, + license: { + name: 'GNU Affero General Public License v3.0 or later', + url: 'https://www.gnu.org/licenses/agpl-3.0' + } +}; + +function getOpenapiInfo(): OpenAPIV3_1.InfoObject { + try { + const content = readFileSync(config.openapiInfo, 'utf-8'); + return Object.assign({}, openapiInfo, JSON.parse(content)); + } catch { + return openapiInfo; + } +} + +export const definition: Partial = { + openapi: '3.1.0', + paths: {}, + info: getOpenapiInfo(), tags: [] }; diff --git a/tests/cli.test.ts b/tests/cli.test.ts index 4bbf90e..65a3db2 100644 --- a/tests/cli.test.ts +++ b/tests/cli.test.ts @@ -8,6 +8,7 @@ const res = { basepath: '', debug: false, hostname: '0.0.0.0', + openapiInfo: './openapi_info.json', openapiPath: '/docs', port: 0, template: './applet_template.html',