Skip to content

Commit

Permalink
Filter out ignored entities (#733)
Browse files Browse the repository at this point in the history
Filter out ignored OpenAPI tags and operations
  • Loading branch information
gregberge authored Feb 28, 2025
1 parent dd2a6b7 commit 497ee68
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changeset/tricky-rules-act.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@gitbook/integration-openapi': patch
---

Filter out ignored tags and operations
8 changes: 4 additions & 4 deletions bun.lock
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
},
"integrations/formspree": {
"name": "@gitbook/integration-formspree",
"version": "0.2.6",
"version": "0.2.7",
"dependencies": {
"@gitbook/runtime": "packages/runtime",
},
Expand Down Expand Up @@ -344,7 +344,7 @@
"dependencies": {
"@gitbook/api": "*",
"@gitbook/document": "*",
"@gitbook/openapi-parser": "^2.0.0",
"@gitbook/openapi-parser": "^2.0.1",
"@gitbook/runtime": "*",
},
"devDependencies": {
Expand Down Expand Up @@ -551,7 +551,7 @@
"name": "@gitbook/cli",
"version": "0.20.1",
"bin": {
"gitbook": "./cli.js"
"gitbook": "./cli.js",
},
"dependencies": {
"@gitbook/api": "*",
Expand Down Expand Up @@ -917,7 +917,7 @@

"@gitbook/integration-zoominfo": ["@gitbook/integration-zoominfo@workspace:integrations/zoominfo"],

"@gitbook/openapi-parser": ["@gitbook/[email protected].0", "", { "dependencies": { "@scalar/openapi-parser": "^0.10.4", "@scalar/openapi-types": "^0.1.6" } }, "sha512-jF2B+XeWpFLvIjCvczOlssJmSV/QHOmfp9j47xX8qTN/yX/QX+ApL5RWtM4Hggf7GvgbnEwXKuB2pLEhP0FjIA=="],
"@gitbook/openapi-parser": ["@gitbook/[email protected].1", "", { "dependencies": { "@scalar/openapi-parser": "^0.10.4", "@scalar/openapi-types": "^0.1.6" } }, "sha512-vHGt+SzBVyKgJuIJNjfc3Z+8IFVcDLYXSqxpYM0NQN56DWPRJRaWBZJf6y8nbHAqH0txJwLt5XqbWLU4dAlB4Q=="],

"@gitbook/runtime": ["@gitbook/runtime@workspace:packages/runtime"],

Expand Down
2 changes: 1 addition & 1 deletion integrations/openapi/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"@gitbook/api": "*",
"@gitbook/runtime": "*",
"@gitbook/document": "*",
"@gitbook/openapi-parser": "^2.0.0"
"@gitbook/openapi-parser": "^2.0.1"
},
"devDependencies": {
"@gitbook/cli": "workspace:*",
Expand Down
16 changes: 13 additions & 3 deletions integrations/openapi/src/parser/spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { ExposableError } from '@gitbook/runtime';
import { dereference, type OpenAPIV3 } from '@gitbook/openapi-parser';
import { GitBookAPI, OpenAPISpec } from '@gitbook/api';
import { assert } from '../utils';
import { dereference, type OpenAPIV3, shouldIgnoreEntity } from '@gitbook/openapi-parser';
import { GitBookAPI } from '@gitbook/api';

type HttpMethod = 'get' | 'post' | 'put' | 'delete' | 'options' | 'head' | 'patch' | 'trace';

Expand Down Expand Up @@ -122,6 +121,12 @@ export function divideOpenAPISpecSchema(schema: OpenAPIV3.Document): OpenAPIGrou
return;
}

// Ignore operations marked as ignored in the spec.
// @ts-expect-error will be fixed in next @gitbook/openapi-parser release
if (shouldIgnoreEntity(operation)) {
return;
}

const firstExistingTag = operation.tags?.find((tag) =>
schema.tags?.some((t) => t.name === tag),
);
Expand All @@ -134,6 +139,11 @@ export function divideOpenAPISpecSchema(schema: OpenAPIV3.Document): OpenAPIGrou
// If the schema has tags, use this order to sort the groups.
if (schema.tags) {
return schema.tags.reduce<OpenAPIGroup[]>((tagGroups, tag) => {
// Ignore tags marked as ignored in the spec.
// @ts-expect-error will be fixed in next @gitbook/openapi-parser release
if (shouldIgnoreEntity(tag)) {
return tagGroups;
}
const group = groups.find((group) => group.id === tag.name);
if (group) {
tagGroups.push(group);
Expand Down

0 comments on commit 497ee68

Please sign in to comment.