示例#1
0
    public static OpenApiPagingExtension Parse(IOpenApiAny source)
    {
        if (source is not OpenApiObject rawObject)
        {
            throw new ArgumentOutOfRangeException(nameof(source));
        }
        var extension = new OpenApiPagingExtension();

        if (rawObject.TryGetValue(nameof(NextLinkName).ToFirstCharacterLowerCase(), out var nextLinkName) && nextLinkName is OpenApiString nextLinkNameStr)
        {
            extension.NextLinkName = nextLinkNameStr.Value;
        }

        if (rawObject.TryGetValue(nameof(OperationName).ToFirstCharacterLowerCase(), out var opName) && opName is OpenApiString opNameStr)
        {
            extension.OperationName = opNameStr.Value;
        }

        if (rawObject.TryGetValue(nameof(ItemName).ToFirstCharacterLowerCase(), out var itemName) && itemName is OpenApiString itemNameStr)
        {
            extension.ItemName = itemNameStr.Value;
        }

        return(extension);
    }
示例#2
0
    public void ParsesPagingInfo()
    {
        // Arrange
        var obj = new OpenApiObject
        {
            ["nextLinkName"]  = new OpenApiString("@odata.nextLink"),
            ["operationName"] = new OpenApiString("more"),
            ["itemName"]      = new OpenApiString("item"),
        };

        // Act
        var extension = OpenApiPagingExtension.Parse(obj);

        // Assert
        Assert.Equal("@odata.nextLink", extension.NextLinkName);
        Assert.Equal("item", extension.ItemName);
        Assert.Equal("more", extension.OperationName);
    }