mirror of
https://github.com/netbirdio/docs.git
synced 2026-10-08 22:59:04 +02:00
api generator cleanup
This commit is contained in:
File diff suppressed because it is too large
Load Diff
-4425
File diff suppressed because it is too large
Load Diff
+5
-4
@@ -4,7 +4,7 @@ import { OpenAPIV3, OpenAPIV2 } from 'openapi-types'
|
|||||||
import * as fs from 'fs'
|
import * as fs from 'fs'
|
||||||
import * as ejs from 'ejs'
|
import * as ejs from 'ejs'
|
||||||
|
|
||||||
export default async function gen(inputFileName: string, outputDir: string, apiUrl: string) {
|
export default async function gen(inputFileName: string, outputDir: string) {
|
||||||
const specRaw = fs.readFileSync(inputFileName, 'utf8')
|
const specRaw = fs.readFileSync(inputFileName, 'utf8')
|
||||||
const spec = JSON.parse(specRaw) as any
|
const spec = JSON.parse(specRaw) as any
|
||||||
// console.log('spec', spec)
|
// console.log('spec', spec)
|
||||||
@@ -13,7 +13,7 @@ export default async function gen(inputFileName: string, outputDir: string, apiU
|
|||||||
case '3.0.0':
|
case '3.0.0':
|
||||||
case '3.0.1':
|
case '3.0.1':
|
||||||
case '3.0.3':
|
case '3.0.3':
|
||||||
await gen_v3(spec, outputDir, { apiUrl })
|
await gen_v3(spec, outputDir)
|
||||||
break
|
break
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@@ -55,12 +55,13 @@ export type component = {
|
|||||||
parameters: schemaParameter[]
|
parameters: schemaParameter[]
|
||||||
}
|
}
|
||||||
|
|
||||||
async function gen_v3(spec: OpenAPIV3.Document, dest: string, { apiUrl }: { apiUrl: string }) {
|
async function gen_v3(spec: OpenAPIV3.Document, dest: string) {
|
||||||
const specLayout = spec.tags || []
|
const specLayout = spec.tags || []
|
||||||
// const operations: enrichedOperation[] = []
|
// const operations: enrichedOperation[] = []
|
||||||
const tagGroups = new Map<string, enrichedOperation[]>()
|
const tagGroups = new Map<string, enrichedOperation[]>()
|
||||||
|
const server = spec.servers.pop().url
|
||||||
Object.entries(spec.paths).forEach(([key, val]) => {
|
Object.entries(spec.paths).forEach(([key, val]) => {
|
||||||
const fullPath = `${apiUrl}${key}`
|
const fullPath = `${server}${key}`
|
||||||
|
|
||||||
toArrayWithKey(val!, 'operation').forEach((o) => {
|
toArrayWithKey(val!, 'operation').forEach((o) => {
|
||||||
const operation = o as v3OperationWithPath
|
const operation = o as v3OperationWithPath
|
||||||
|
|||||||
+1
-13
@@ -24,22 +24,10 @@ function handleInput(command: string, options: any) {
|
|||||||
export default async function DocGenerator({
|
export default async function DocGenerator({
|
||||||
input,
|
input,
|
||||||
output,
|
output,
|
||||||
type,
|
|
||||||
url,
|
|
||||||
}: {
|
}: {
|
||||||
input: string
|
input: string
|
||||||
output: string
|
output: string
|
||||||
type: 'api'
|
|
||||||
url?: string
|
|
||||||
}) {
|
}) {
|
||||||
switch (type) {
|
await ApiGenerator(input, output)
|
||||||
case 'api':
|
|
||||||
await ApiGenerator(input, output, url || '')
|
|
||||||
break
|
|
||||||
|
|
||||||
default:
|
|
||||||
await console.log('Unrecognized type: ', type)
|
|
||||||
break
|
|
||||||
}
|
|
||||||
return 'Done'
|
return 'Done'
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
"version" : "0.0.1"
|
"version" : "0.0.1"
|
||||||
},
|
},
|
||||||
"servers" : [ {
|
"servers" : [ {
|
||||||
"url" : "https://netbird.io",
|
"url" : "https://api.netbird.io",
|
||||||
"description" : "Default server"
|
"description" : "Default server"
|
||||||
} ],
|
} ],
|
||||||
"security" : [ {
|
"security" : [ {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
openapi: 3.0.1
|
openapi: 3.0.1
|
||||||
servers:
|
servers:
|
||||||
- url: https://netbird.io
|
- url: https://api.netbird.io
|
||||||
description: Default server
|
description: Default server
|
||||||
info:
|
info:
|
||||||
title: NetBird REST API
|
title: NetBird REST API
|
||||||
|
|||||||
@@ -1,144 +0,0 @@
|
|||||||
const template = `
|
|
||||||
---
|
|
||||||
id: usage
|
|
||||||
slug: /usage
|
|
||||||
title: Usage
|
|
||||||
toc_max_heading_level: 3
|
|
||||||
---
|
|
||||||
|
|
||||||
|
|
||||||
<!-- AUTOGENERATED: DO NOT EDIT DIRECTLY IF THIS IS VERSION "next" -->
|
|
||||||
|
|
||||||
<%- info.description %>
|
|
||||||
|
|
||||||
<!-- AUTOGENERATED: DO NOT EDIT DIRECTLY IF THIS IS VERSION "next" -->
|
|
||||||
|
|
||||||
|
|
||||||
<% sections.forEach(function(section){ %>
|
|
||||||
|
|
||||||
## <%- section.title %> [#<%= section.id %>]
|
|
||||||
|
|
||||||
<%- section.description %>
|
|
||||||
|
|
||||||
<% section.operations.forEach(function(operation){ %>
|
|
||||||
|
|
||||||
<!-- AUTOGENERATED: DO NOT EDIT DIRECTLY IF THIS IS VERSION "next" -->
|
|
||||||
|
|
||||||
### <%- operation.summary %> [#<%- operation.operationId %>]
|
|
||||||
|
|
||||||
\`\`\`
|
|
||||||
<%- operation.operation.toUpperCase() %> <%- operation.fullPath %>
|
|
||||||
\`\`\`
|
|
||||||
|
|
||||||
<!-- AUTOGENERATED: DO NOT EDIT DIRECTLY IF THIS IS VERSION "next" -->
|
|
||||||
|
|
||||||
<% if(operation.parameters && operation.parameters.filter((parameter) => parameter.in === 'path').length > 0){ %>
|
|
||||||
#### Path Parameters
|
|
||||||
|
|
||||||
<ul className="method-list-group not-prose">
|
|
||||||
<% operation.parameters
|
|
||||||
.filter((parameter) => parameter.in === 'path').forEach(function(parameter){ %>
|
|
||||||
<li className="method-list-item">
|
|
||||||
<h4 className="method-list-item-label">
|
|
||||||
<span className="method-list-item-label-name">
|
|
||||||
<%- parameter.name %>
|
|
||||||
</span>
|
|
||||||
<span className="method-list-item-label-badge">
|
|
||||||
<%- parameter.required ? 'required' : 'optional' %>
|
|
||||||
</span>
|
|
||||||
<span className="method-list-item-validation">
|
|
||||||
<%- parameter.type %>
|
|
||||||
</span>
|
|
||||||
</h4>
|
|
||||||
<% if(parameter.example){ %>
|
|
||||||
<h4 className="method-list-item-label">
|
|
||||||
Example:
|
|
||||||
<span className="method-list-item-label-badge">
|
|
||||||
<%- parameter.example %>
|
|
||||||
</span>
|
|
||||||
</h4>
|
|
||||||
<% } %>
|
|
||||||
<div class="method-list-item-description">
|
|
||||||
<%- parameter.description %>
|
|
||||||
</div>
|
|
||||||
</li>
|
|
||||||
<% }); %>
|
|
||||||
</ul>
|
|
||||||
<% }; %>
|
|
||||||
|
|
||||||
<% if(operation.parameters && operation.parameters.filter((parameter) => parameter.in === 'header').length > 0){ %>
|
|
||||||
#### Header Parameters
|
|
||||||
<ul className="method-list-group not-prose">
|
|
||||||
<% operation.parameters
|
|
||||||
.filter((parameter) => parameter.in === 'header').forEach(function(parameter){ %>
|
|
||||||
<li className="method-list-item">
|
|
||||||
<h4 className="method-list-item-label">
|
|
||||||
<span className="method-list-item-label-name">
|
|
||||||
<%- parameter.name %>
|
|
||||||
</span>
|
|
||||||
<span className="method-list-item-label-badge">
|
|
||||||
<%- parameter.required ? 'required' : 'optional' %>
|
|
||||||
</span>
|
|
||||||
<span className="method-list-item-validation">
|
|
||||||
<%- parameter.type %>
|
|
||||||
</span>
|
|
||||||
</h4>
|
|
||||||
<% if(parameter.example){ %>
|
|
||||||
<h4 className="method-list-item-label">
|
|
||||||
Example:
|
|
||||||
<span className="method-list-item-label-badge">
|
|
||||||
<%- parameter.example %>
|
|
||||||
</span>
|
|
||||||
</h4>
|
|
||||||
<% } %>
|
|
||||||
<div class="method-list-item-description">
|
|
||||||
<%- parameter.description %>
|
|
||||||
</div>
|
|
||||||
</li>
|
|
||||||
<% }); %>
|
|
||||||
</ul>
|
|
||||||
<% }; %>
|
|
||||||
|
|
||||||
|
|
||||||
<!-- AUTOGENERATED: DO NOT EDIT DIRECTLY IF THIS IS VERSION "next" -->
|
|
||||||
|
|
||||||
<% if(operation.requestBody?.content && operation.requestBody?.content['application/json']){ %>
|
|
||||||
#### Body Parameters
|
|
||||||
|
|
||||||
\`\`\`json
|
|
||||||
<%- JSON.stringify(operation.requestBody?.content['application/json'], null, 2) %>
|
|
||||||
\`\`\`
|
|
||||||
<% }; %>
|
|
||||||
|
|
||||||
<!-- AUTOGENERATED: DO NOT EDIT DIRECTLY IF THIS IS VERSION "next" -->
|
|
||||||
|
|
||||||
#### Responses
|
|
||||||
|
|
||||||
<Tabs scrollable size="small" type="underlined" defaultActiveId="<%- operation.responseList[0].responseCode %>">
|
|
||||||
<% operation.responseList.forEach(function(response){ %>
|
|
||||||
<TabPanel id="<%- response.responseCode %>" label="<%- response.responseCode %>">
|
|
||||||
|
|
||||||
<%- response.description %>
|
|
||||||
|
|
||||||
<!-- AUTOGENERATED: DO NOT EDIT DIRECTLY IF THIS IS VERSION "next" -->
|
|
||||||
|
|
||||||
<% if(response?.content && response?.content['application/json']){ %>
|
|
||||||
\`\`\`json
|
|
||||||
<%- JSON.stringify(response.content['application/json'], null, 2) %>
|
|
||||||
\`\`\`
|
|
||||||
<% }; %>
|
|
||||||
|
|
||||||
<!-- AUTOGENERATED: DO NOT EDIT DIRECTLY IF THIS IS VERSION "next" -->
|
|
||||||
|
|
||||||
</TabPanel>
|
|
||||||
<% }); %>
|
|
||||||
</Tabs>
|
|
||||||
|
|
||||||
<br />
|
|
||||||
<% }); %>
|
|
||||||
<% }); %>
|
|
||||||
|
|
||||||
|
|
||||||
`.trim()
|
|
||||||
|
|
||||||
export default template
|
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
import { SpecLink } from './Spec'
|
|
||||||
import { Url } from 'url'
|
|
||||||
|
|
||||||
export type CliInfo = {
|
|
||||||
id: string
|
|
||||||
version: string
|
|
||||||
title: string
|
|
||||||
language: string
|
|
||||||
source: Url
|
|
||||||
bugs: Url
|
|
||||||
spec: Url
|
|
||||||
description: string
|
|
||||||
options: string
|
|
||||||
}
|
|
||||||
|
|
||||||
export type CliCommand = {
|
|
||||||
id: string
|
|
||||||
title: string
|
|
||||||
summary: string
|
|
||||||
description: string
|
|
||||||
tags: string[]
|
|
||||||
links: SpecLink[]
|
|
||||||
usage: string
|
|
||||||
subcommands: string[]
|
|
||||||
options: string
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface CliSpec {
|
|
||||||
clispec: '001'
|
|
||||||
|
|
||||||
info: CliInfo
|
|
||||||
|
|
||||||
commands: CliCommand[]
|
|
||||||
}
|
|
||||||
@@ -1,36 +0,0 @@
|
|||||||
import { SpecLink } from './Spec'
|
|
||||||
import { Url } from 'url'
|
|
||||||
|
|
||||||
export type Tag = {
|
|
||||||
id: string
|
|
||||||
title: string
|
|
||||||
description?: string
|
|
||||||
}
|
|
||||||
|
|
||||||
export type ConfigInfo = {
|
|
||||||
id: string
|
|
||||||
version: string
|
|
||||||
title: string
|
|
||||||
source: Url
|
|
||||||
bugs: Url
|
|
||||||
spec: Url
|
|
||||||
description: string
|
|
||||||
tags: Tag[]
|
|
||||||
}
|
|
||||||
|
|
||||||
export type ConfigParameter = {
|
|
||||||
id: string
|
|
||||||
title: string
|
|
||||||
tags: string[]
|
|
||||||
required: boolean
|
|
||||||
description: string
|
|
||||||
links: SpecLink[]
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface ConfigSpec {
|
|
||||||
configspec: '001'
|
|
||||||
|
|
||||||
info: ConfigInfo
|
|
||||||
|
|
||||||
parameters: ConfigParameter[]
|
|
||||||
}
|
|
||||||
@@ -1,75 +0,0 @@
|
|||||||
import { SpecLink } from './Spec'
|
|
||||||
import { Url } from 'url'
|
|
||||||
|
|
||||||
export type SdkInfo = {
|
|
||||||
id: string
|
|
||||||
version: string
|
|
||||||
title: string
|
|
||||||
language: string
|
|
||||||
source: Url
|
|
||||||
bugs: Url
|
|
||||||
spec: Url
|
|
||||||
description: string
|
|
||||||
options: string
|
|
||||||
}
|
|
||||||
|
|
||||||
export type SdkType = {
|
|
||||||
id: string
|
|
||||||
title: string
|
|
||||||
summary: string
|
|
||||||
source: Url
|
|
||||||
value: string
|
|
||||||
ref?: SdkType
|
|
||||||
links: SpecLink[]
|
|
||||||
}
|
|
||||||
|
|
||||||
export type FunctionAttribute = {
|
|
||||||
id: string
|
|
||||||
title: string
|
|
||||||
required: boolean
|
|
||||||
description: string
|
|
||||||
type?: string[]
|
|
||||||
ref?: string // If a "type" is not supplied, a "ref" must be. This is a pointer to a type.
|
|
||||||
children: FunctionAttribute[]
|
|
||||||
}
|
|
||||||
|
|
||||||
export type FunctionReturn = {
|
|
||||||
id: string
|
|
||||||
title: string
|
|
||||||
value: string
|
|
||||||
description: string
|
|
||||||
ref?: string // This is a pointer to a type.
|
|
||||||
}
|
|
||||||
|
|
||||||
export type FunctionExample = {
|
|
||||||
id: string
|
|
||||||
title: string
|
|
||||||
description?: string
|
|
||||||
links: SpecLink[]
|
|
||||||
code: string
|
|
||||||
returns?: FunctionReturn
|
|
||||||
}
|
|
||||||
|
|
||||||
export type Function = {
|
|
||||||
id: string
|
|
||||||
title: string
|
|
||||||
summary: string
|
|
||||||
source: Url
|
|
||||||
description?: string
|
|
||||||
usage: string
|
|
||||||
tags: string[]
|
|
||||||
links: SpecLink[]
|
|
||||||
attributes?: FunctionAttribute[]
|
|
||||||
returns?: FunctionReturn[]
|
|
||||||
examples?: FunctionExample[]
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface SdkSpec {
|
|
||||||
sdkspec: '001'
|
|
||||||
|
|
||||||
info: SdkInfo
|
|
||||||
|
|
||||||
functions: Function[]
|
|
||||||
|
|
||||||
types: SdkType[]
|
|
||||||
}
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
import { Url } from 'url'
|
|
||||||
|
|
||||||
export type SpecLink = {
|
|
||||||
name: string
|
|
||||||
url: Url
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user