-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add webhooks support #1304
Changes from 2 commits
c094d19
23bf484
454d27f
c33a1de
6b8c44f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -2,6 +2,7 @@ import { OpenAPIExternalDocumentation, OpenAPISpec } from '../types'; | |||||
|
||||||
import { ContentItemModel, MenuBuilder } from './MenuBuilder'; | ||||||
import { ApiInfoModel } from './models/ApiInfo'; | ||||||
import { WebhookModel } from './models/Webhook'; | ||||||
import { SecuritySchemesModel } from './models/SecuritySchemes'; | ||||||
import { OpenAPIParser } from './OpenAPIParser'; | ||||||
import { RedocNormalizedOptions } from './RedocNormalizedOptions'; | ||||||
|
@@ -15,6 +16,7 @@ export class SpecStore { | |||||
externalDocs?: OpenAPIExternalDocumentation; | ||||||
contentItems: ContentItemModel[]; | ||||||
securitySchemes: SecuritySchemesModel; | ||||||
'x-webhooks'?: WebhookModel; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is by OpenAPI spec, all vendor extensions should be prefixed by There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oops, my bad. This is our code not typing for OAS. @stasiukanya could you update it to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @adamaltman good catch! |
||||||
|
||||||
constructor( | ||||||
spec: OpenAPISpec, | ||||||
|
@@ -26,5 +28,6 @@ export class SpecStore { | |||||
this.externalDocs = this.parser.spec.externalDocs; | ||||||
this.contentItems = MenuBuilder.buildStructure(this.parser, this.options); | ||||||
this.securitySchemes = new SecuritySchemesModel(this.parser); | ||||||
this['x-webhooks'] = new WebhookModel(this.parser, options, this.parser.spec['x-webhooks']); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
} | ||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { OpenAPIPath, Referenced } from '../../types'; | ||
import { OpenAPIParser } from '../OpenAPIParser'; | ||
import { OperationModel } from './Operation'; | ||
import { isOperationName } from '../..'; | ||
import { RedocNormalizedOptions } from '../RedocNormalizedOptions'; | ||
|
||
export class WebhookModel { | ||
operations: OperationModel[] = []; | ||
|
||
constructor( | ||
parser: OpenAPIParser, | ||
options: RedocNormalizedOptions, | ||
infoOrRef?: Referenced<OpenAPIPath>, | ||
) { | ||
const webhooks = parser.deref<OpenAPIPath>(infoOrRef || {}); | ||
parser.exitRef(infoOrRef); | ||
|
||
for (const webhookName of Object.keys(webhooks)) { | ||
const webhook = webhooks[webhookName]; | ||
const operations = Object.keys(webhook).filter(isOperationName); | ||
for (const operationName of operations) { | ||
const operationInfo = webhook[operationName]; | ||
const operation = new OperationModel( | ||
parser, | ||
{ | ||
...operationInfo, | ||
httpVerb: operationName, | ||
}, | ||
undefined, | ||
options, | ||
false, | ||
); | ||
|
||
this.operations.push(operation); | ||
} | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder why not
webhook
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check out the screenshot above.
webhook
will be wider than the rest badges and will look ugly.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This label/badge needs to be configurable. "hook" is a pejorative word in various vernacular (can mean to cheat or prostitution).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@adamaltman Do you have any other ideas? Maybe
whook
orwebh
? We useopts
foroptions
anddel
fordelete
.