/// <inheritdoc/> protected override void SetResponses(OpenApiOperation operation) { if (EdmOperation.IsAction() && EdmOperation.ReturnType == null) { operation.Responses.Add(Constants.StatusCode204, Constants.StatusCode204.GetResponse()); } else { // function should have a return type. OpenApiResponse response = new OpenApiResponse { Description = "Success", Content = new Dictionary <string, OpenApiMediaType> { { Constants.ApplicationJsonMediaType, new OpenApiMediaType { Schema = Context.CreateEdmTypeSchema(EdmOperation.ReturnType) } } } }; operation.Responses.Add(Constants.StatusCode200, response); } // both action & function has the default response. operation.Responses.Add(Constants.StatusCodeDefault, Constants.StatusCodeDefault.GetResponse()); base.SetResponses(operation); }
/// <inheritdoc/> protected override void SetBasicInfo(OpenApiOperation operation) { // Summary operation.Summary = "Invoke " + (EdmOperation.IsAction() ? "action " : "function ") + EdmOperation.Name; // OperationId if (Context.Settings.EnableOperationId) { string operationId = String.Join(".", Path.Segments.Where(s => !(s is ODataKeySegment)).Select(s => s.Identifier)); if (EdmOperation.IsAction()) { operation.OperationId = operationId; } else { ODataOperationSegment operationSegment = Path.LastSegment as ODataOperationSegment; string pathItemName = operationSegment.GetPathItemName(Context.Settings, new HashSet <string>()); if (Context.Model.IsOperationOverload(operationSegment.Operation)) { string hash = pathItemName.GetHashSHA256(); operation.OperationId = operationId + "-" + hash.Substring(0, 4); } else { operation.OperationId = operationId; } } } base.SetBasicInfo(operation); }
/// <inheritdoc/> protected override void SetBasicInfo(OpenApiOperation operation) { // Summary operation.Summary = "Invoke " + (EdmOperation.IsAction() ? "action " : "function ") + EdmOperation.Name; // OperationId if (Context.Settings.EnableOperationId) { // When the key segment is available, // its EntityType name will be used // in the operationId to avoid potential // duplicates in entity vs entityset functions/actions List <string> identifiers = new(); foreach (ODataSegment segment in Path.Segments) { if (segment is not ODataKeySegment) { identifiers.Add(segment.Identifier); } else { identifiers.Add(segment.EntityType.Name); } } string operationId = string.Join(".", identifiers); if (EdmOperation.IsAction()) { operation.OperationId = operationId; } else { ODataOperationSegment operationSegment = Path.LastSegment as ODataOperationSegment; string pathItemName = operationSegment.GetPathItemName(Context.Settings, new HashSet <string>()); if (Context.Model.IsOperationOverload(operationSegment.Operation)) { string hash = pathItemName.GetHashSHA256(); operation.OperationId = operationId + "-" + hash.Substring(0, 4); } else { operation.OperationId = operationId; } } } base.SetBasicInfo(operation); }
/// <inheritdoc/> protected override void SetTags(OpenApiOperation operation) { string value = EdmOperation.IsAction() ? "Actions" : "Functions"; OpenApiTag tag = new OpenApiTag { Name = NavigationSource.Name + "." + value, }; tag.Extensions.Add(Constants.xMsTocType, new OpenApiString("container")); operation.Tags.Add(tag); Context.AppendTag(tag); base.SetTags(operation); }
/// <inheritdoc/> protected override void SetBasicInfo(OpenApiOperation operation) { // Summary operation.Summary = "Invoke " + (EdmOperation.IsAction() ? "action " : "function ") + EdmOperation.Name; // Description operation.Description = Context.Model.GetDescriptionAnnotation(EdmOperation); // OperationId if (Context.Settings.EnableOperationId) { // When the key segment is available, // its EntityType name will be used // in the operationId to avoid potential // duplicates in entity vs entityset functions/actions List <string> identifiers = new(); foreach (ODataSegment segment in Path.Segments) { if (segment is not ODataKeySegment) { identifiers.Add(segment.Identifier); } else { identifiers.Add(segment.EntityType.Name); } } string operationId = string.Join(".", identifiers); if (EdmOperation.IsAction()) { operation.OperationId = operationId; } else { if (Path.LastSegment is ODataOperationSegment operationSegment && Context.Model.IsOperationOverload(operationSegment.Operation)) { operation.OperationId = operationId + "-" + Path.LastSegment.GetPathHash(Context.Settings); } else { operation.OperationId = operationId; } }
/// <inheritdoc/> protected override void SetBasicInfo(OpenApiOperation operation) { // Summary operation.Summary = "Invoke " + (EdmOperation.IsAction() ? "action " : "function ") + EdmOperation.Name; // OperationId if (Context.Settings.EnableOperationId) { StringBuilder operationId = new StringBuilder(NavigationSource.Name); if (HasTypeCast) { ODataTypeCastSegment typeCast = Path.Segments.FirstOrDefault(s => s is ODataTypeCastSegment) as ODataTypeCastSegment; operationId.Append("."); operationId.Append(typeCast.EntityType.Name); } else { operationId.Append("."); operationId.Append(NavigationSource.EntityType().Name); } operationId.Append("."); operationId.Append(EdmOperation.Name); if (EdmOperation.IsAction()) { operation.OperationId = operationId.ToString(); } else { ODataOperationSegment operationSegment = Path.LastSegment as ODataOperationSegment; string pathItemName = operationSegment.GetPathItemName(Context.Settings); string md5 = pathItemName.GetHashMd5(); operation.OperationId = operationId.Append(".").Append(md5.Substring(8)).ToString(); } } base.SetBasicInfo(operation); }
/// <inheritdoc/> protected override void SetBasicInfo(OpenApiOperation operation) { // Summary operation.Summary = "Invoke " + (EdmOperation.IsAction() ? "action " : "function ") + EdmOperation.Name; // OperationId if (Context.Settings.EnableOperationId) { string operationId = String.Join(".", Path.Segments.Where(s => !(s is ODataKeySegment)).Select(s => s.Name)); if (EdmOperation.IsAction()) { operation.OperationId = operationId; } else { ODataOperationSegment operationSegment = Path.LastSegment as ODataOperationSegment; string pathItemName = operationSegment.GetPathItemName(Context.Settings); string md5 = pathItemName.GetHashMd5(); operation.OperationId = operationId + "." + md5.Substring(0, 4); } } base.SetBasicInfo(operation); }