OpenAPI: Fix compatibility issues on other content sources

This commit is contained in:
fuma-nama
2024-08-12 20:49:44 +08:00
parent 70f15af238
commit c094fefcba
9 changed files with 24 additions and 16 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'fumadocs-openapi': patch
---
Fix compatibility issues on other content sources
+5 -2
View File
@@ -217,16 +217,19 @@ function pageContent(
});
}
// modify toc and structured data if possible
// it may not be compatible with other content sources except Fumadocs MDX
// TODO: Maybe add to frontmatter and let developers to handle them?
return `<APIPage operations={${JSON.stringify(props.operations)}} hasHead={${JSON.stringify(props.hasHead)}} />
export function startup() {
if (toc) {
if (typeof toc !== 'undefined') {
// toc might be immutable
while (toc.length > 0) toc.pop()
toc.push(...${JSON.stringify(toc)})
}
if (structuredData) {
if (typeof structuredData !== 'undefined') {
structuredData.headings = ${JSON.stringify(structuredData.headings)}
structuredData.contents = ${JSON.stringify(structuredData.contents)}
}
+2 -2
View File
@@ -7,13 +7,13 @@ full: true
<APIPage operations={[{"method":"get","path":"/special-events"},{"method":"post","path":"/special-events"},{"method":"get","path":"/special-events/{eventId}"},{"method":"patch","path":"/special-events/{eventId}"},{"method":"delete","path":"/special-events/{eventId}"}]} hasHead={true} />
export function startup() {
if (toc) {
if (typeof toc !== 'undefined') {
// toc might be immutable
while (toc.length > 0) toc.pop()
toc.push(...[{"depth":2,"title":"List special events","url":"#list-special-events"},{"depth":2,"title":"Create special events","url":"#create-special-events"},{"depth":2,"title":"Get special event","url":"#get-special-event"},{"depth":2,"title":"Update special event","url":"#update-special-event"},{"depth":2,"title":"Delete special event","url":"#delete-special-event"}])
}
if (structuredData) {
if (typeof structuredData !== 'undefined') {
structuredData.headings = [{"content":"List special events","id":"list-special-events"},{"content":"Create special events","id":"create-special-events"},{"content":"Get special event","id":"get-special-event"},{"content":"Update special event","id":"update-special-event"},{"content":"Delete special event","id":"delete-special-event"}]
structuredData.contents = [{"content":"Return a list of upcoming special events at the museum.","heading":"list-special-events"},{"content":"Creates a new special event for the museum.","heading":"create-special-events"},{"content":"Get details about a special event.","heading":"get-special-event"},{"content":"Update the details of a special event","heading":"update-special-event"},{"content":"Delete a special event from the collection. Allows museum to cancel planned events.","heading":"delete-special-event"}]
}
@@ -7,13 +7,13 @@ full: true
<APIPage operations={[{"method":"get","path":"/museum-hours"}]} hasHead={true} />
export function startup() {
if (toc) {
if (typeof toc !== 'undefined') {
// toc might be immutable
while (toc.length > 0) toc.pop()
toc.push(...[{"depth":2,"title":"Get museum hours","url":"#get-museum-hours"}])
}
if (structuredData) {
if (typeof structuredData !== 'undefined') {
structuredData.headings = [{"content":"Get museum hours","id":"get-museum-hours"}]
structuredData.contents = [{"content":"Get upcoming museum operating hours","heading":"get-museum-hours"}]
}
+2 -2
View File
@@ -7,13 +7,13 @@ full: true
<APIPage operations={[{"method":"post","path":"/tickets"},{"method":"get","path":"/tickets/{ticketId}/qr"}]} hasHead={true} />
export function startup() {
if (toc) {
if (typeof toc !== 'undefined') {
// toc might be immutable
while (toc.length > 0) toc.pop()
toc.push(...[{"depth":2,"title":"Buy museum tickets","url":"#buy-museum-tickets"},{"depth":2,"title":"Get ticket QR code","url":"#get-ticket-qr-code"}])
}
if (structuredData) {
if (typeof structuredData !== 'undefined') {
structuredData.headings = [{"content":"Buy museum tickets","id":"buy-museum-tickets"},{"content":"Get ticket QR code","id":"get-ticket-qr-code"}]
structuredData.contents = [{"content":"Purchase museum tickets for general entry or special events.","heading":"buy-museum-tickets"},{"content":"Return an image of your ticket with scannable QR code. Used for event entry.","heading":"get-ticket-qr-code"}]
}
+2 -2
View File
@@ -6,13 +6,13 @@ full: true
<APIPage operations={[{"method":"get","path":"/pets"},{"method":"post","path":"/pets"},{"method":"get","path":"/pets/{petId}"}]} hasHead={true} />
export function startup() {
if (toc) {
if (typeof toc !== 'undefined') {
// toc might be immutable
while (toc.length > 0) toc.pop()
toc.push(...[{"depth":2,"title":"List all pets","url":"#list-all-pets"},{"depth":2,"title":"Create a pet","url":"#create-a-pet"},{"depth":2,"title":"Info for a specific pet","url":"#info-for-a-specific-pet"}])
}
if (structuredData) {
if (typeof structuredData !== 'undefined') {
structuredData.headings = [{"content":"List all pets","id":"list-all-pets"},{"content":"Create a pet","id":"create-a-pet"},{"content":"Info for a specific pet","id":"info-for-a-specific-pet"}]
structuredData.contents = []
}
+2 -2
View File
@@ -6,13 +6,13 @@ full: true
<APIPage operations={[{"method":"get","path":"/v1/apis.getApi"},{"method":"post","path":"/v1/apis.createApi"},{"method":"get","path":"/v1/apis.listKeys"},{"method":"post","path":"/v1/apis.deleteApi"}]} hasHead={true} />
export function startup() {
if (toc) {
if (typeof toc !== 'undefined') {
// toc might be immutable
while (toc.length > 0) toc.pop()
toc.push(...[{"depth":2,"title":"Get Api","url":"#get-api"},{"depth":2,"title":"Create Api","url":"#create-api"},{"depth":2,"title":"List Keys","url":"#list-keys"},{"depth":2,"title":"Delete Api","url":"#delete-api"}])
}
if (structuredData) {
if (typeof structuredData !== 'undefined') {
structuredData.headings = [{"content":"Get Api","id":"get-api"},{"content":"Create Api","id":"create-api"},{"content":"List Keys","id":"list-keys"},{"content":"Delete Api","id":"delete-api"}]
structuredData.contents = []
}
+2 -2
View File
@@ -6,13 +6,13 @@ full: true
<APIPage operations={[{"method":"get","path":"/v1/keys.getKey"},{"method":"post","path":"/v1/keys.deleteKey"},{"method":"post","path":"/v1/keys.createKey"},{"method":"post","path":"/v1/keys.verifyKey"},{"method":"post","path":"/v1/keys.updateKey"},{"method":"post","path":"/v1/keys.updateRemaining"},{"method":"get","path":"/v1/keys.getVerifications"}]} hasHead={true} />
export function startup() {
if (toc) {
if (typeof toc !== 'undefined') {
// toc might be immutable
while (toc.length > 0) toc.pop()
toc.push(...[{"depth":2,"title":"Get Key","url":"#get-key"},{"depth":2,"title":"Delete Key","url":"#delete-key"},{"depth":2,"title":"Create Key","url":"#create-key"},{"depth":2,"title":"Verify Key","url":"#verify-key"},{"depth":2,"title":"Update Key","url":"#update-key"},{"depth":2,"title":"Update Remaining","url":"#update-remaining"},{"depth":2,"title":"Get Verifications","url":"#get-verifications"}])
}
if (structuredData) {
if (typeof structuredData !== 'undefined') {
structuredData.headings = [{"content":"Get Key","id":"get-key"},{"content":"Delete Key","id":"delete-key"},{"content":"Create Key","id":"create-key"},{"content":"Verify Key","id":"verify-key"},{"content":"Update Key","id":"update-key"},{"content":"Update Remaining","id":"update-remaining"},{"content":"Get Verifications","id":"get-verifications"}]
structuredData.contents = []
}
+2 -2
View File
@@ -6,13 +6,13 @@ full: true
<APIPage operations={[{"method":"get","path":"/v1/liveness"}]} hasHead={true} />
export function startup() {
if (toc) {
if (typeof toc !== 'undefined') {
// toc might be immutable
while (toc.length > 0) toc.pop()
toc.push(...[{"depth":2,"title":"Check Liveness","url":"#check-liveness"}])
}
if (structuredData) {
if (typeof structuredData !== 'undefined') {
structuredData.headings = [{"content":"Check Liveness","id":"check-liveness"}]
structuredData.contents = []
}