Skip to content

Commit

Permalink
Filter out ignored entities
Browse files Browse the repository at this point in the history
  • Loading branch information
gregberge committed Feb 28, 2025
1 parent 99ac594 commit d0bb4eb
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 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
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
14 changes: 11 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,11 @@ export function divideOpenAPISpecSchema(schema: OpenAPIV3.Document): OpenAPIGrou
return;
}

// Ignore operations marked as ignored in the spec.
if (shouldIgnoreEntity(operation)) {
return;
}

const firstExistingTag = operation.tags?.find((tag) =>
schema.tags?.some((t) => t.name === tag),
);
Expand All @@ -134,6 +138,10 @@ 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.
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 d0bb4eb

Please sign in to comment.