mirror of
https://github.com/netbirdio/docs.git
synced 2026-04-16 07:26:35 +00:00
Escape MDX-specific characters in API templates and refine Navigation… (#638)
* Escape MDX-specific characters in API templates and refine NavigationAPI links * Update API pages with v0.66.0 --------- Co-authored-by: netbirddev <dev@netbird.io>
This commit is contained in:
@@ -7,6 +7,15 @@ import * as yaml from 'js-yaml';
|
||||
import { merge } from 'allof-merge'
|
||||
import RequestBodyObject = OpenAPIV3_1.RequestBodyObject;
|
||||
|
||||
function escapeMdx(text: string): string {
|
||||
if (!text) return text;
|
||||
return text
|
||||
.replace(/<=/g, "{'<='}")
|
||||
.replace(/>=/g, "{'>='}")
|
||||
.replace(/^- /gm, '\\- ')
|
||||
.replace(/\n- /g, '\n\\- ');
|
||||
}
|
||||
|
||||
// Pre-processes the spec to fix allOf with conflicting enums by merging them
|
||||
function fixConflictingEnumAllOf(obj: any): any {
|
||||
if (obj === null || typeof obj !== 'object') {
|
||||
@@ -123,7 +132,10 @@ async function gen_v3(spec: OpenAPIV3.Document, dest: string) {
|
||||
Object.entries(spec.paths).forEach(([key, val]) => {
|
||||
const fullPath = `${server}${key}`
|
||||
|
||||
toArrayWithKey(val!, 'operation').forEach((o) => {
|
||||
const httpMethods = ['get', 'post', 'put', 'delete', 'patch', 'options', 'head', 'trace']
|
||||
toArrayWithKey(val!, 'operation')
|
||||
.filter((o) => httpMethods.includes(o.operation))
|
||||
.forEach((o) => {
|
||||
const operation = o as v3OperationWithPath
|
||||
|
||||
var request = null
|
||||
@@ -135,7 +147,7 @@ async function gen_v3(spec: OpenAPIV3.Document, dest: string) {
|
||||
}
|
||||
|
||||
var response = null
|
||||
if(operation.responses["200"] != undefined && operation.responses["200"]["content"] != undefined && operation.responses["200"]["content"]["application/json"] != undefined) {
|
||||
if(operation.responses && operation.responses["200"] != undefined && operation.responses["200"]["content"] != undefined && operation.responses["200"]["content"]["application/json"] != undefined) {
|
||||
response = {
|
||||
example: extractInfo(operation.responses["200"]["content"]["application/json"].schema, 'example'),
|
||||
schema: extractInfo(operation.responses["200"]["content"]["application/json"].schema, 'type')
|
||||
@@ -158,7 +170,10 @@ async function gen_v3(spec: OpenAPIV3.Document, dest: string) {
|
||||
})
|
||||
})
|
||||
|
||||
const excludedTags = ['Checkout', 'AWS Marketplace', 'Plans', 'Subscription', 'Portal']
|
||||
|
||||
tagGroups.forEach((value: enrichedOperation[], key: string) => {
|
||||
if (excludedTags.includes(key)) return
|
||||
|
||||
const operations = value
|
||||
|
||||
@@ -176,11 +191,12 @@ async function gen_v3(spec: OpenAPIV3.Document, dest: string) {
|
||||
tag: key,
|
||||
sections,
|
||||
operations,
|
||||
escapeMdx,
|
||||
// components,
|
||||
})
|
||||
|
||||
// Write to disk
|
||||
let outputFile = dest + "/" + key.toLowerCase().replace(" ", "-") + ".mdx"
|
||||
let outputFile = dest + "/" + key.toLowerCase().replace(/ /g, "-") + ".mdx"
|
||||
writeToDisk(outputFile, content)
|
||||
// console.log('Saved: ', outputFile)
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
const template = `
|
||||
|
||||
export const title = '<%- tag %>'
|
||||
|
||||
<% operations.forEach(function(operation){ %>
|
||||
@@ -8,14 +7,14 @@ export const title = '<%- tag %>'
|
||||
|
||||
<Row>
|
||||
<Col>
|
||||
<%- operation.description %>
|
||||
<%- escapeMdx(operation.description) %>
|
||||
<% if(operation.parameters && operation.parameters.filter((parameter) => parameter.in === 'path').length > 0){ %>
|
||||
### Path Parameters
|
||||
<Properties>
|
||||
<% operation.parameters.filter((parameter) => parameter.in === 'path').forEach(function(parameter){ %>
|
||||
<Property name="<%- parameter.name %>" type="string" required=\{true\}>
|
||||
<%- parameter.description %>
|
||||
</Property>
|
||||
<%- escapeMdx(parameter.description) %>
|
||||
</Property>
|
||||
<% }); -%>
|
||||
</Properties>
|
||||
<% }; -%>
|
||||
@@ -24,7 +23,7 @@ export const title = '<%- tag %>'
|
||||
<Properties>
|
||||
<% operation.parameters.filter((parameter) => parameter.in === 'query').forEach(function(parameter){ %>
|
||||
<Property name="<%- parameter.name %>" type="<%- parameter.schema.type %>" required=\{false\}>
|
||||
<%- parameter.description %>
|
||||
<%- escapeMdx(parameter.description) %>
|
||||
</Property>
|
||||
<% }); -%>
|
||||
</Properties>
|
||||
@@ -76,7 +75,7 @@ function renderProperties(properties, required = [], depth = 0) {
|
||||
</Properties>
|
||||
</details>
|
||||
<% } else { %>
|
||||
<% if(value.description) { %><%- value.description %><% } %>
|
||||
<% if(value.description) { %><%- escapeMdx(value.description) %><% } %>
|
||||
<% } %>
|
||||
</Property>
|
||||
<% });
|
||||
|
||||
Reference in New Issue
Block a user