/// <summary> /// Generate a single <see cref="OpenApiCallback"/> matching the given <see cref="WebHookTrigger"/> /// </summary> /// <param name="trigger"></param> /// <param name="context"></param> /// <returns></returns> protected OpenApiCallback Generate(WebHookTrigger trigger, OperationFilterContext context) { var schema = context.SchemaGenerator.GenerateSchema(trigger.PayloadType, context.SchemaRepository); var result = new OpenApiCallback(); result.AddPathItem(RuntimeExpression.Build($"{{$request.body#/{PseudoCamelCase(nameof(IWebHook.Callback))}}}"), new OpenApiPathItem { Operations = new Dictionary <OperationType, OpenApiOperation> { [OperationType.Post] = new OpenApiOperation { OperationId = trigger.Id, Description = trigger.Description, Responses = _responses, Parameters = _parameters, RequestBody = new OpenApiRequestBody { Required = true, Content = new Dictionary <string, OpenApiMediaType> { ["application/json"] = new OpenApiMediaType { Schema = schema } } }, } } }); return(result); }
private void CollectCallbackReferences(OpenApiCallback callback) { if (callback == null) { return; } if (callback.UnresolvedReference) { if (!_unresolvedReferences.Contains(callback.Reference)) { _unresolvedReferences.Add(callback.Reference); } return; } foreach (var pathItem in callback.PathItems) { foreach (var operation in pathItem.Value.Operations) { CollectOperationReferences(operation.Value); } foreach (var parameter in pathItem.Value.Parameters) { CollectParameterReferences(parameter); } } }
public override void Visit(OpenApiCallback callback) { if (callback.UnresolvedReference) { throw new ArgumentException("Single pass reference resolution expects this element to already be resolved"); } }
public void Traverse(OpenApiCallback callback) { if (callback == null) { return; } Visitor.Visit(callback); if (callback.PathItems != null) { foreach (var item in callback.PathItems) { Traverse(item.Value); } } }
/// <summary> /// Generate a single <see cref="OpenApiCallback"/> matching the given <see cref="WebHookTrigger"/> /// </summary> /// <param name="trigger"></param> /// <returns></returns> protected OpenApiCallback Generate(WebHookTrigger trigger) { var triggerProperties = new Dictionary <string, OpenApiSchema>(trigger.Template.Properties) { [PseudoCamelCase(DefaultWebHookSender.TimestampKey)] = new OpenApiSchema { Type = "string", Format = "date-time" }, [PseudoCamelCase(DefaultWebHookSender.TriggerKey)] = new OpenApiSchema { Type = "string" }, [PseudoCamelCase(DefaultWebHookSender.UniqueIdKey)] = new OpenApiSchema { Type = "string", Format = "uuid" } }; var result = new OpenApiCallback(); result.AddPathItem(RuntimeExpression.Build($"{{$request.body#/{PseudoCamelCase(nameof(IWebHook.Callback))}}}"), new OpenApiPathItem { Operations = new Dictionary <OperationType, OpenApiOperation> { [OperationType.Post] = new OpenApiOperation { OperationId = trigger.Id, Description = trigger.Description, Responses = _responses, Parameters = _parameters, RequestBody = new OpenApiRequestBody { Required = true, Content = new Dictionary <string, OpenApiMediaType> { ["application/json"] = new OpenApiMediaType { Schema = new OpenApiSchema { Type = "object", Properties = triggerProperties } } } }, } } }); return(result); }
public static OpenApiCallback LoadCallback(ParseNode node) { var mapNode = node.CheckMapNode("callback"); var pointer = mapNode.GetReferencePointer(); if (pointer != null) { return(mapNode.GetReferencedObject <OpenApiCallback>(ReferenceType.Callback, pointer)); } var domainObject = new OpenApiCallback(); ParseMap(mapNode, domainObject, _callbackFixedFields, _callbackPatternFields); return(domainObject); }
/// <summary> /// Visits <see cref="OpenApiCallback"/> and child objects /// </summary> internal void Walk(OpenApiCallback callback) { if (callback == null) { return; } _visitor.Visit(callback); if (callback != null) { foreach (var item in callback.PathItems) { var pathItem = item.Value; Walk(item.Key.ToString(), () => Walk(pathItem)); } } }
/// <summary> /// Visits <see cref="OpenApiCallback"/> and child objects /// </summary> internal void Walk(OpenApiCallback callback, bool isComponent = false) { if (callback == null || ProcessAsReference(callback, isComponent)) { return; } _visitor.Visit(callback); if (callback != null) { foreach (var item in callback.PathItems) { _visitor.CurrentKeys.Callback = item.Key.ToString(); var pathItem = item.Value; Walk(item.Key.ToString(), () => Walk(pathItem)); _visitor.CurrentKeys.Callback = null; } } }
/// <summary> /// Visits <see cref="OpenApiCallback"/> /// </summary> public virtual void Visit(OpenApiCallback callback) { }
/// <summary> /// Execute validation rules against an <see cref="OpenApiCallback"/> /// </summary> /// <param name="item">The object to be validated</param> public override void Visit(OpenApiCallback item) => Validate(item);
public override void Visit(OpenApiCallback callback) { EncodeCall(); base.Visit(callback); }
public override void Visit(OpenApiCallback callback) { CallbackCount++; }
private void AddCallback(IList <PropertyParsingNode> nodes, OpenApiComponents components, OpenApiCallback callback) { if (callback == null) { return; } if (callback.UnresolvedReference) { AddCallback(nodes, components, callback.Reference); return; } foreach (var pathItem in callback.PathItems) { foreach (var operation in pathItem.Value.Operations) { foreach (var parameter in operation.Value.Parameters) { AddParameter(nodes, components, parameter.Reference); } AddRequestBody(nodes, components, operation.Value.RequestBody.Reference); foreach (var response in operation.Value.Responses) { AddResponse(nodes, components, response.Value.Reference); } } foreach (var parameter in pathItem.Value.Parameters) { AddParameter(nodes, components, parameter.Reference); } } }