api generator cleanup

This commit is contained in:
Pascal Fischer
2023-05-09 17:45:59 +02:00
parent c9200f4bea
commit b5c24e786d
11 changed files with 8 additions and 10072 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -4,7 +4,7 @@ import { OpenAPIV3, OpenAPIV2 } from 'openapi-types'
import * as fs from 'fs'
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 spec = JSON.parse(specRaw) as any
// 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.1':
case '3.0.3':
await gen_v3(spec, outputDir, { apiUrl })
await gen_v3(spec, outputDir)
break
default:
@@ -55,12 +55,13 @@ export type component = {
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 operations: enrichedOperation[] = []
const tagGroups = new Map<string, enrichedOperation[]>()
const server = spec.servers.pop().url
Object.entries(spec.paths).forEach(([key, val]) => {
const fullPath = `${apiUrl}${key}`
const fullPath = `${server}${key}`
toArrayWithKey(val!, 'operation').forEach((o) => {
const operation = o as v3OperationWithPath

View File

@@ -24,22 +24,10 @@ function handleInput(command: string, options: any) {
export default async function DocGenerator({
input,
output,
type,
url,
}: {
input: string
output: string
type: 'api'
url?: string
}) {
switch (type) {
case 'api':
await ApiGenerator(input, output, url || '')
break
default:
await console.log('Unrecognized type: ', type)
break
}
await ApiGenerator(input, output)
return 'Done'
}

View File

@@ -6,7 +6,7 @@
"version" : "0.0.1"
},
"servers" : [ {
"url" : "https://netbird.io",
"url" : "https://api.netbird.io",
"description" : "Default server"
} ],
"security" : [ {

View File

@@ -1,6 +1,6 @@
openapi: 3.0.1
servers:
- url: https://netbird.io
- url: https://api.netbird.io
description: Default server
info:
title: NetBird REST API

View File

@@ -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

View File

@@ -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[]
}

View File

@@ -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[]
}

View File

@@ -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[]
}

View File

@@ -1,6 +0,0 @@
import { Url } from 'url'
export type SpecLink = {
name: string
url: Url
}