Skip to content
Open
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
5 changes: 5 additions & 0 deletions scripts/notion-openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -1513,6 +1513,11 @@
"summary": "Create comment",
"description": "Creates a comment in a page or existing discussion thread.",
"operationId": "create-a-comment",
"parameters": [
{
"$ref": "#/components/parameters/notionVersion"
}
],
"requestBody": {
"content": {
"application/json": {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import fs from 'node:fs'
import path from 'node:path'
import { describe, expect, it } from 'vitest'
import type { OpenAPIV3 } from 'openapi-types'

/**
* Every Notion API operation must declare the shared Notion-Version header
* parameter so HttpClient.buildDefaultHeaders() can attach the version.
*/
describe('Notion OpenAPI spec Notion-Version coverage', () => {
const spec = JSON.parse(
fs.readFileSync(path.resolve(process.cwd(), 'scripts/notion-openapi.json'), 'utf-8'),
) as OpenAPIV3.Document

const notionVersionRef = '#/components/parameters/notionVersion'

function hasNotionVersionParameter(operation: OpenAPIV3.OperationObject): boolean {
return (operation.parameters ?? []).some((param) => {
if ('$ref' in param) {
return param.$ref === notionVersionRef
}
return param.in === 'header' && param.name === 'Notion-Version'
})
}

it('declares Notion-Version on every operation', () => {
const missing: string[] = []

for (const [pathKey, pathItem] of Object.entries(spec.paths ?? {})) {
for (const method of ['get', 'post', 'put', 'patch', 'delete'] as const) {
const operation = pathItem?.[method]
if (!operation?.operationId) {
continue
}
if (!hasNotionVersionParameter(operation)) {
missing.push(`${method.toUpperCase()} ${pathKey} (${operation.operationId})`)
}
}
}

expect(missing).toEqual([])
})
})