Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions generator/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down Expand Up @@ -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
Expand All @@ -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')
Expand All @@ -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

Expand All @@ -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)

Expand Down
11 changes: 5 additions & 6 deletions generator/templates/ApiTemplate.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const template = `

export const title = '<%- tag %>'

<% operations.forEach(function(operation){ %>
Expand All @@ -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>
<% }; -%>
Expand All @@ -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>
Expand Down Expand Up @@ -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>
<% });
Expand Down
24 changes: 20 additions & 4 deletions src/components/NavigationAPI.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ export const apiNavigation = [
{ title: 'Quickstart', href: '/api/guides/quickstart' },
{ title: 'Authentication', href: '/api/guides/authentication' },
{ title: 'Errors', href: '/api/guides/errors' },
// { title: 'Events', href: '/accounts' },
],
},
{
Expand All @@ -25,22 +24,39 @@ export const apiNavigation = [
{ title: 'Users', href: '/api/resources/users' },
{ title: 'Tokens', href: '/api/resources/tokens' },
{ title: 'Peers', href: '/api/resources/peers' },
{ title: 'Ingress Ports', href: '/api/resources/ingress-ports' },
{ title: 'Setup Keys', href: '/api/resources/setup-keys' },
{ title: 'Groups', href: '/api/resources/groups' },
{ title: 'Policies', href: '/api/resources/policies' },
{ title: 'Posture-Checks', href: '/api/resources/posture-checks' },
{ title: 'Geo-Locations', href: '/api/resources/geo-locations' },
{ title: 'Posture Checks', href: '/api/resources/posture-checks' },
{ title: 'Geo Locations', href: '/api/resources/geo-locations' },
{ title: 'Routes (deprecated)', href: '/api/resources/routes' },
{ title: 'Networks', href: '/api/resources/networks' },
{ title: 'DNS', href: '/api/resources/dns' },
{ title: 'DNS Zones', href: '/api/resources/dns-zones' },
{ title: 'Services', href: '/api/resources/services' },
{ title: 'Events', href: '/api/resources/events' },
{ title: 'Event Streaming', href: '/api/resources/event-streaming-integrations' },
{ title: 'Jobs', href: '/api/resources/jobs' },
{ title: 'Identity Providers', href: '/api/resources/identity-providers' },
{ title: 'Instance', href: '/api/resources/instance' },
],
},
{
title: 'Cloud Resources',
links: [
{ title: 'Ingress Ports', href: '/api/resources/ingress-ports' },
{ title: 'IDP (SCIM)', href: '/api/resources/idp' },
{ title: 'Event Streaming', href: '/api/resources/event-streaming-integrations' },
{ title: 'EDR Peers', href: '/api/resources/edr-peers' },
{ title: 'EDR Falcon', href: '/api/resources/edr-falcon-integrations' },
{ title: 'EDR Huntress', href: '/api/resources/edr-huntress-integrations' },
{ title: 'EDR Intune', href: '/api/resources/edr-intune-integrations' },
{ title: 'EDR SentinelOne', href: '/api/resources/edr-sentinelone-integrations' },
{ title: 'MSP', href: '/api/resources/msp' },
{ title: 'Invoice', href: '/api/resources/invoice' },
{ title: 'Usage', href: '/api/resources/usage' },
],
},
]

export function NavigationAPI({tableOfContents, className}) {
Expand Down
Loading