File: Modeler\PaginatedOpenApiExtension.cs
Web Access
Project: src\src\Microsoft.DotNet.SwaggerGenerator\Microsoft.DotNet.SwaggerGenerator.CodeGenerator\Microsoft.DotNet.SwaggerGenerator.CodeGenerator.csproj (Microsoft.DotNet.SwaggerGenerator.CodeGenerator)
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
 
using System;
using Microsoft.OpenApi;
using Microsoft.OpenApi.Any;
using Microsoft.OpenApi.Interfaces;
using Microsoft.OpenApi.Writers;
 
namespace Microsoft.DotNet.SwaggerGenerator.Modeler
{
    public class PaginatedOpenApiExtension : IOpenApiExtension
    {
        private OpenApiObject _value;
 
        public PaginatedOpenApiExtension(OpenApiObject value)
        {
            _value = value;
        }
 
        public string PageParameterName
        {
            get => ((OpenApiString) _value["page"]).Value;
            set => _value["page"] = new OpenApiString(value);
        }
 
        public string PageSizeParameterName
        {
            get => ((OpenApiString) _value["pageSize"]).Value;
            set => _value["pageSize"] = new OpenApiString(value);
        }
 
        public static IOpenApiExtension Parse(IOpenApiAny value, OpenApiSpecVersion version)
        {
            if (value.AnyType != AnyType.Object)
            {
                throw new ArgumentException("x-ms-paginated extension only accepts an object");
            }
            var obj = (OpenApiObject) value;
            return new PaginatedOpenApiExtension(obj);
        }
 
        public void Write(IOpenApiWriter writer, OpenApiSpecVersion specVersion)
        {
            _value.Write(writer, specVersion);
        }
    }
}