-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: upload openapi info from external file (#410)
* feat: upload openapi info from external file * test: update cli tests * docs: typo
- Loading branch information
1 parent
95ebc51
commit c830ea2
Showing
4 changed files
with
39 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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<OpenAPIV3_1.Document> = { | ||
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: '[email protected]', | ||
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: '[email protected]', | ||
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<OpenAPIV3_1.Document> = { | ||
openapi: '3.1.0', | ||
paths: {}, | ||
info: getOpenapiInfo(), | ||
tags: [] | ||
}; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters