public static bool HasSharedResponseContract(
        OpenApiDocument apiDocument,
        List <ApiOperationSchemaMap> operationSchemaMappings,
        string focusOnSegmentName)
    {
        ArgumentNullException.ThrowIfNull(apiDocument);
        ArgumentNullException.ThrowIfNull(operationSchemaMappings);
        ArgumentNullException.ThrowIfNull(focusOnSegmentName);

        foreach (var(_, value) in apiDocument.GetPathsByBasePathSegmentName(focusOnSegmentName))
        {
            foreach (var apiOperation in value.Operations)
            {
                if (apiOperation.Value.Responses is null)
                {
                    continue;
                }

                var responseModelName     = apiOperation.Value.Responses.GetModelNameForStatusCode(HttpStatusCode.OK);
                var isSharedResponseModel = !string.IsNullOrEmpty(responseModelName) &&
                                            operationSchemaMappings.IsShared(responseModelName);
                if (isSharedResponseModel)
                {
                    return(true);
                }
            }
        }

        return(false);
    }
Exemple #2
0
        public void GetPathsByBasePathSegmentName(int expectedCount, string basePathSegmentName, OpenApiDocument openApiDocument)
        {
            // Act
            var actual = openApiDocument.GetPathsByBasePathSegmentName(basePathSegmentName);

            // Assert
            Assert.NotNull(actual);
            Assert.Equal(expectedCount, actual.Count);
        }