Skip to content

Commit

Permalink
Spec updates (#433)
Browse files Browse the repository at this point in the history
* added SBT token page

* updated spec to open all tags

* updated example merger with security scheme

* updated example gen

* merged master

* Revert "merged master"

This reverts commit b7ed6d2.
  • Loading branch information
JamesLawton authored Nov 6, 2024
1 parent 9f6381d commit 5ff37b0
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 9 deletions.
1 change: 1 addition & 0 deletions docs/components/SpecAPIComponent/APIComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ function APIComponent({ specType }: any) {
token: apiKey,
},
},
defaultOpenAllTags: true
})
}

Expand Down
62 changes: 53 additions & 9 deletions libs/example_merger.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,38 @@ const saveOpenAPIDocument = (filePath, document) => {

const addExamplesToOpenAPI = (doc, examples) => {
// Check if the document title contains 'Metadata' or 'Indexer'
if (
doc.info.title.includes('Metadata') ||
doc.info.title.includes('Indexer') ||
doc.info.title.includes('Analytics')
) {
if (doc.info.title.includes('Metadata') || doc.info.title.includes('Analytics')) {
doc.tags = [
{
name: 'public',
description:
'Endpoints accessible by passing your project-access-key in the header. This is injected whenever you login automatically.',
},
{
name: 'secret',
description:
'Endpoints that require a Sequence service token intended to be secret. You can manually generate one on Sequence Builder and pass it as a Bearer Token.',
},
]
}

if (doc.info.title.includes('Indexer')) {
doc.components.securitySchemes = {
ApiKeyAuth: {
type: 'apiKey',
in: 'header',
description:
'Project access key for authenticating requests, get an access key at https://sequence.build',
name: 'X-Access-Key',
},
BearerAuth: {
type: 'http',
scheme: 'bearer',
bearerFormat: 'JWT',
description: 'JWT Service Token generated from Sequence Builder',
},
}

doc.tags = [
{
name: 'public',
Expand Down Expand Up @@ -70,14 +97,18 @@ const addExamplesToOpenAPI = (doc, examples) => {
requestBody.content['multipart/form-data'] =
requestBody.content['multipart/form-data'] || {}
requestBody.content['multipart/form-data'].example = ex.request

}

if (requestBody.content['multipart/form-data']) {
requestBody.content['multipart/form-data'].example = ex.request
}

if (requestBody.content['application/json']) {
requestBody.content['application/json'].example = ex.request
requestBody.content['application/json'].examples = {}
requestBody.content['application/json'].examples[exampleName] = {}
requestBody.content['application/json'].examples[exampleName].value = ex.request
requestBody.content['application/json'].examples[exampleName].summary = ex.summary
}
}
}
Expand All @@ -89,15 +120,28 @@ const addExamplesToOpenAPI = (doc, examples) => {
if (!response.content) {
response.content = {
'application/json': {
example: ex.response,
examples: {
exampleName: {
value: ex.response,
summary: ex.summary
}
}
},
}
} else {
if (response.content['application/json']) {
response.content['application/json'].example = ex.response
response.content['application/json'].examples = {}
response.content['application/json'].examples[exampleName] = {}
response.content['application/json'].examples[exampleName].value = ex.response
response.content['application/json'].examples[exampleName].summary = ex.summary
} else {
response.content['application/json'] = {
example: ex.response,
examples: {
exampleName: {
value: ex.response,
summary: ex.summary
}
}
}
}
}
Expand Down

0 comments on commit 5ff37b0

Please sign in to comment.