public ChangedSecurityRequirementsBO Diff( IList <OpenApiSecurityRequirement> left, IList <OpenApiSecurityRequirement> right, DiffContextBO context) { left ??= new List <OpenApiSecurityRequirement>(); right = right != null?GetCopy(right) : new List <OpenApiSecurityRequirement>(); var changedSecurityRequirements = new ChangedSecurityRequirementsBO(left, right); foreach (var leftSecurity in left) { var rightSecOpt = Contains(right, leftSecurity); if (rightSecOpt == null) { changedSecurityRequirements.Missing.Add(leftSecurity); } else { var rightSec = rightSecOpt; right.Remove(rightSec); var diff = _openApiDiff.SecurityRequirementDiff .Diff(leftSecurity, rightSec, context); if (diff != null) { changedSecurityRequirements.Changed.Add(diff); } } } changedSecurityRequirements.Increased.AddRange(right); return(ChangedUtils.IsChanged(changedSecurityRequirements)); }
public ChangedPathBO Diff(OpenApiPathItem left, OpenApiPathItem right, DiffContextBO context) { var oldOperationMap = left.Operations; var newOperationMap = right.Operations; var operationsDiff = MapKeyDiff <OperationType, OpenApiOperation> .Diff(oldOperationMap, newOperationMap); var sharedMethods = operationsDiff.SharedKey; var changedPath = new ChangedPathBO(context.URL, left, right, context) { Increased = operationsDiff.Increased, Missing = operationsDiff.Missing }; foreach (var operationType in sharedMethods) { var oldOperation = oldOperationMap[operationType]; var newOperation = newOperationMap[operationType]; var diff = _openApiDiff .OperationDiff .Diff(oldOperation, newOperation, context.CopyWithMethod(operationType)); if (diff != null) { changedPath.Changed.Add(diff); } } changedPath.Extensions = _openApiDiff .ExtensionsDiff .Diff(left.Extensions, right.Extensions, context); return(ChangedUtils.IsChanged(changedPath)); }
public ChangedAPIResponseBO Diff(OpenApiResponses left, OpenApiResponses right, DiffContextBO context) { var responseMapKeyDiff = MapKeyDiff <string, OpenApiResponse> .Diff(left, right); var sharedResponseCodes = responseMapKeyDiff.SharedKey; var responses = new Dictionary <string, ChangedResponseBO>(); foreach (var responseCode in sharedResponseCodes) { var diff = _openApiDiff .ResponseDiff .Diff(left[responseCode], right[responseCode], context); if (diff != null) { responses.Add(responseCode, diff); } } var changedApiResponse = new ChangedAPIResponseBO(left, right, context) { Increased = responseMapKeyDiff.Increased, Missing = responseMapKeyDiff.Missing, Changed = responses, Extensions = _openApiDiff .ExtensionsDiff .Diff(left.Extensions, right.Extensions, context) }; return(ChangedUtils.IsChanged(changedApiResponse)); }
private void CompareAdditionalProperties(OpenApiSchema leftSchema, OpenApiSchema rightSchema, DiffContextBO context) { var left = leftSchema.AdditionalProperties; var right = rightSchema.AdditionalProperties; if (left != null || right != null) { var apChangedSchema = new ChangedSchemaBO { Context = context, OldSchema = left, NewSchema = right }; if (left != null && right != null) { var addPropChangedSchemaOp = OpenApiDiff .SchemaDiff .Diff(left, right, context.CopyWithRequired(false)); apChangedSchema = addPropChangedSchemaOp ?? apChangedSchema; } var changed = ChangedUtils.IsChanged(apChangedSchema); if (changed != null) { ChangedSchema.AddProp = changed; } } }
public ChangedOAuthFlowsBO Diff(OpenApiOAuthFlows left, OpenApiOAuthFlows right) { var changedOAuthFlows = new ChangedOAuthFlowsBO(left, right); if (left != null && right != null) { changedOAuthFlows.ImplicitOAuthFlow = _openApiDiff .OAuthFlowDiff .Diff(left.Implicit, right.Implicit); changedOAuthFlows.PasswordOAuthFlow = _openApiDiff .OAuthFlowDiff .Diff(left.Password, right.Password); changedOAuthFlows.ClientCredentialOAuthFlow = _openApiDiff .OAuthFlowDiff .Diff(left.ClientCredentials, right.ClientCredentials); changedOAuthFlows.AuthorizationCodeOAuthFlow = _openApiDiff .OAuthFlowDiff .Diff(left.AuthorizationCode, right.AuthorizationCode); } changedOAuthFlows.Extensions = _openApiDiff .ExtensionsDiff .Diff(left?.Extensions, right?.Extensions); return(ChangedUtils.IsChanged(changedOAuthFlows)); }
public ChangedHeadersBO Diff(IDictionary <string, OpenApiHeader> left, IDictionary <string, OpenApiHeader> right, DiffContextBO context) { var headerMapDiff = MapKeyDiff <string, OpenApiHeader> .Diff(left, right); var sharedHeaderKeys = headerMapDiff.SharedKey; var changed = new Dictionary <string, ChangedHeaderBO>(); foreach (var headerKey in sharedHeaderKeys) { var oldHeader = left[headerKey]; var newHeader = right[headerKey]; var changedHeaders = _openApiDiff .HeaderDiff .Diff(oldHeader, newHeader, context); if (changedHeaders != null) { changed.Add(headerKey, changedHeaders); } } return(ChangedUtils.IsChanged( new ChangedHeadersBO(left, right, context) { Increased = headerMapDiff.Increased, Missing = headerMapDiff.Missing, Changed = changed })); }
protected override ChangedHeaderBO ComputeDiff(OpenApiHeader left, OpenApiHeader right, DiffContextBO context) { left = RefPointer.ResolveRef(_leftComponents, left, left.Reference?.ReferenceV3); right = RefPointer.ResolveRef(_rightComponents, right, right.Reference?.ReferenceV3); var changedHeader = new ChangedHeaderBO(left, right, context) { Required = GetBooleanDiff(left.Required, right.Required), Deprecated = !left.Deprecated && right.Deprecated, Style = left.Style != right.Style, Explode = GetBooleanDiff(left.Explode, right.Explode), Description = _openApiDiff .MetadataDiff .Diff(left.Description, right.Description, context), Schema = _openApiDiff .SchemaDiff .Diff(left.Schema, right.Schema, context.CopyWithRequired(true)), Content = _openApiDiff .ContentDiff .Diff(left.Content, right.Content, context), Extensions = _openApiDiff .ExtensionsDiff .Diff(left.Extensions, right.Extensions, context) }; return(ChangedUtils.IsChanged(changedHeader)); }
protected override ChangedRequestBodyBO ComputeDiff(OpenApiRequestBody left, OpenApiRequestBody right, DiffContextBO context) { Dictionary <string, OpenApiMediaType> oldRequestContent = null; Dictionary <string, OpenApiMediaType> newRequestContent = null; OpenApiRequestBody oldRequestBody = null; OpenApiRequestBody newRequestBody = null; if (left != null) { oldRequestBody = RefPointer.ResolveRef( _openApiDiff.OldSpecOpenApi.Components, left, left.Reference?.ReferenceV3); if (oldRequestBody.Content != null) { oldRequestContent = (Dictionary <string, OpenApiMediaType>)oldRequestBody.Content; } } if (right != null) { newRequestBody = RefPointer.ResolveRef( _openApiDiff.NewSpecOpenApi.Components, right, right.Reference?.ReferenceV3); if (newRequestBody.Content != null) { newRequestContent = (Dictionary <string, OpenApiMediaType>)newRequestBody.Content; } } var leftRequired = oldRequestBody != null && oldRequestBody.Required; var rightRequired = newRequestBody != null && newRequestBody.Required; var changedRequestBody = new ChangedRequestBodyBO(oldRequestBody, newRequestBody, context) { ChangeRequired = leftRequired != rightRequired, Description = _openApiDiff .MetadataDiff .Diff( oldRequestBody?.Description, newRequestBody?.Description, context), Content = _openApiDiff .ContentDiff .Diff(oldRequestContent, newRequestContent, context), Extensions = _openApiDiff .ExtensionsDiff .Diff(GetExtensions(left), GetExtensions(right), context) }; return(ChangedUtils.IsChanged(changedRequestBody)); }
public ChangedPathsBO Diff(Dictionary <string, OpenApiPathItem> left, Dictionary <string, OpenApiPathItem> right) { var changedPaths = new ChangedPathsBO(left, right); foreach (var(key, value) in right) { changedPaths.Increased.Add(key, value); } foreach (var(key, value) in left) { var template = key.NormalizePath(); var result = right.Keys.FirstOrDefault(x => x.NormalizePath() == template); if (result != null) { if (!changedPaths.Increased.ContainsKey(result)) { throw new ArgumentException($"Two path items have the same signature: {template}"); } var rightPath = changedPaths.Increased[result]; changedPaths.Increased.Remove(result); var paramsDict = new Dictionary <string, string>(); if (key != result) { var oldParams = key.ExtractParametersFromPath(); var newParams = result.ExtractParametersFromPath(); for (var i = oldParams.Count - 1; i >= 0; i--) { paramsDict.Add(oldParams[i], newParams[i]); } } var context = new DiffContextBO { URL = key, Parameters = paramsDict }; var diff = _openApiDiff .PathDiff .Diff(value, rightPath, context); if (diff != null) { changedPaths.Changed.Add(result, diff); } } else { changedPaths.Missing.Add(key, value); } } return(ChangedUtils.IsChanged(changedPaths)); }
protected ChangedSchemaBO IsApplicable(DiffContextBO context) { if (ChangedSchema.ReadOnly.IsUnchanged() && ChangedSchema.WriteOnly.IsUnchanged() && !IsPropertyApplicable(ChangedSchema.NewSchema, context)) { return(null); } return(ChangedUtils.IsChanged(ChangedSchema)); }
public ChangedOAuthFlowBO Diff(OpenApiOAuthFlow left, OpenApiOAuthFlow right) { var changedOAuthFlow = new ChangedOAuthFlowBO(left, right); if (left != null && right != null) { changedOAuthFlow.ChangedAuthorizationUrl = left.AuthorizationUrl != right.AuthorizationUrl; changedOAuthFlow.ChangedTokenUrl = left.TokenUrl != right.TokenUrl; changedOAuthFlow.ChangedRefreshUrl = left.RefreshUrl != right.RefreshUrl; } changedOAuthFlow.Extensions = _openApiDiff .ExtensionsDiff .Diff(left?.Extensions, right?.Extensions); return(ChangedUtils.IsChanged(changedOAuthFlow)); }
public ChangedSecurityRequirementBO Diff( OpenApiSecurityRequirement left, OpenApiSecurityRequirement right, DiffContextBO context) { var changedSecurityRequirement = new ChangedSecurityRequirementBO(left, right != null ? GetCopy(right) : null); left ??= new OpenApiSecurityRequirement(); right ??= new OpenApiSecurityRequirement(); foreach (var(key, value) in left) { var rightSec = Contains(right, key.Reference?.ReferenceV3); if (rightSec.IsNullOrEmpty()) { changedSecurityRequirement.Missing.Add(key, value); } else { var rightSchemeRef = rightSec.Keys.First(); right.Remove(rightSchemeRef); var diff = _openApiDiff .SecuritySchemeDiff .Diff( key.Reference?.ReferenceV3, value.ToList(), rightSchemeRef.Reference?.ReferenceV3, rightSec[rightSchemeRef].ToList(), context); if (diff != null) { changedSecurityRequirement.Changed.Add(diff); } } } foreach (var(key, value) in right) { changedSecurityRequirement.Increased.Add(key, value); } return(ChangedUtils.IsChanged(changedSecurityRequirement)); }
public ChangedParametersBO Diff( List <OpenApiParameter> left, List <OpenApiParameter> right, DiffContextBO context) { var changedParameters = new ChangedParametersBO(left, right, context); if (null == left) { left = new List <OpenApiParameter>(); } if (null == right) { right = new List <OpenApiParameter>(); } foreach (var openApiParameter in left) { var leftPara = openApiParameter; leftPara = RefPointer.ResolveRef(_leftComponents, leftPara, leftPara.Reference?.ReferenceV3); var rightParam = Contains(_rightComponents, right, leftPara); if (rightParam == null) { changedParameters.Missing.Add(leftPara); } else { right.Remove(rightParam); var diff = _openApiDiff.ParameterDiff .Diff(leftPara, rightParam, context); if (diff != null) { changedParameters.Changed.Add(diff); } } } changedParameters.Increased.AddRange(right); return(ChangedUtils.IsChanged(changedParameters)); }
public ChangedContentBO Diff(IDictionary <string, OpenApiMediaType> left, IDictionary <string, OpenApiMediaType> right, DiffContextBO context) { var leftDict = (Dictionary <string, OpenApiMediaType>)left; var rightDict = (Dictionary <string, OpenApiMediaType>)right; var mediaTypeDiff = MapKeyDiff <string, OpenApiMediaType> .Diff(leftDict, rightDict); var sharedMediaTypes = mediaTypeDiff.SharedKey; var changedMediaTypes = new Dictionary <string, ChangedMediaTypeBO>(); foreach (var sharedMediaType in sharedMediaTypes) { var oldMediaType = left[sharedMediaType]; var newMediaType = right[sharedMediaType]; var changedMediaType = new ChangedMediaTypeBO(oldMediaType?.Schema, newMediaType?.Schema, context) { Schema = _openApiDiff .SchemaDiff .Diff( oldMediaType?.Schema, newMediaType?.Schema, context.CopyWithRequired(true)) }; if (!ChangedUtils.IsUnchanged(changedMediaType)) { changedMediaTypes.Add(sharedMediaType, changedMediaType); } } return(ChangedUtils.IsChanged(new ChangedContentBO(leftDict, rightDict, context) { Increased = mediaTypeDiff.Increased, Missing = mediaTypeDiff.Missing, Changed = changedMediaTypes })); }
public ChangedSecuritySchemeBO Diff( string leftSchemeRef, List <string> leftScopes, string rightSchemeRef, List <string> rightScopes, DiffContextBO context) { var leftSecurityScheme = _leftComponents.SecuritySchemes[leftSchemeRef]; var rightSecurityScheme = _rightComponents.SecuritySchemes[rightSchemeRef]; var changedSecuritySchemeOpt = CachedDiff( leftSecurityScheme, rightSecurityScheme, leftSchemeRef, rightSchemeRef, context); var changedSecurityScheme = changedSecuritySchemeOpt ?? new ChangedSecuritySchemeBO(leftSecurityScheme, rightSecurityScheme); changedSecurityScheme = GetCopyWithoutScopes(changedSecurityScheme); if (changedSecurityScheme != null && leftSecurityScheme.Type == SecuritySchemeType.OAuth2) { var changed = ChangedUtils.IsChanged(ListDiff.Diff( new ChangedSecuritySchemeScopesBO(leftScopes, rightScopes) )); if (changed != null) { changedSecurityScheme.ChangedScopes = changed; } } return(ChangedUtils.IsChanged(changedSecurityScheme)); }
protected override ChangedResponseBO ComputeDiff(OpenApiResponse left, OpenApiResponse right, DiffContextBO context) { left = RefPointer.ResolveRef(_leftComponents, left, left.Reference?.ReferenceV3); right = RefPointer.ResolveRef(_rightComponents, right, right.Reference?.ReferenceV3); var changedResponse = new ChangedResponseBO(left, right, context) { Description = _openApiDiff .MetadataDiff .Diff(left.Description, right.Description, context), Content = _openApiDiff .ContentDiff .Diff(left.Content, right.Content, context), Headers = _openApiDiff .HeadersDiff .Diff(left.Headers, right.Headers, context), Extensions = _openApiDiff .ExtensionsDiff .Diff(left.Extensions, right.Extensions, context) }; return(ChangedUtils.IsChanged(changedResponse)); }
public ChangedMetadataBO Diff(string left, string right, DiffContextBO context) { return(ChangedUtils.IsChanged(new ChangedMetadataBO(left, right))); }
public ChangedOperationBO Diff( OpenApiOperation oldOperation, OpenApiOperation newOperation, DiffContextBO context) { var changedOperation = new ChangedOperationBO(context.URL, context.Method, oldOperation, newOperation) { Summary = _openApiDiff .MetadataDiff .Diff(oldOperation.Summary, newOperation.Summary, context), Description = _openApiDiff .MetadataDiff .Diff(oldOperation.Description, newOperation.Description, context), IsDeprecated = !oldOperation.Deprecated && newOperation.Deprecated }; if (oldOperation.RequestBody != null || newOperation.RequestBody != null) { changedOperation.RequestBody = _openApiDiff .RequestBodyDiff .Diff( oldOperation.RequestBody, newOperation.RequestBody, context.CopyAsRequest()); } var parametersDiff = _openApiDiff .ParametersDiff .Diff(oldOperation.Parameters.ToList(), newOperation.Parameters.ToList(), context); if (parametersDiff != null) { RemovePathParameters(context.Parameters, parametersDiff); changedOperation.Parameters = parametersDiff; } if (oldOperation.Responses != null || newOperation.Responses != null) { var diff = _openApiDiff .APIResponseDiff .Diff(oldOperation.Responses, newOperation.Responses, context.CopyAsResponse()); if (diff != null) { changedOperation.APIResponses = diff; } } if (oldOperation.Security != null || newOperation.Security != null) { var diff = _openApiDiff .SecurityRequirementsDiff .Diff(oldOperation.Security, newOperation.Security, context); if (diff != null) { changedOperation.SecurityRequirements = diff; } } changedOperation.Extensions = _openApiDiff .ExtensionsDiff .Diff(oldOperation.Extensions, newOperation.Extensions, context); return(ChangedUtils.IsChanged(changedOperation)); }