예제 #1
0
        public DocumentDefinition(string version, string title, string description = null, Uri termsOfService = null)
        {
            _root = Document(version, title, description, termsOfService);
            Root  = _root;

            var properties = typeof(TDocumentDefinition)
                             .GetProperties(BindingFlags.Static | BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic)
                             .Select(p =>
            {
                var getter = p.GetMethod;
                var deleg  = getter.IsStatic ? getter.Invoke(null, null) : getter.Invoke(this, null);

                switch (getter.ReturnType)
                {
                case Type t when t == typeof(Path):
                    ((Path)deleg)();
                    break;

                case Type t when t == typeof(Operation):
                    ((Operation)deleg)();
                    break;

                case Type t when t == typeof(Response):
                    ((Response)deleg)();
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
                return(1);
            }).ToArray();
        }
예제 #2
0
        public static DslPathItem GetPath(this DslDocument document, string path, string separator = "/")
        {
            var fullPath = separator + path;

            if (!document.Document.Paths.TryGetValue(fullPath, out var pathItem))
            {
                pathItem = new OpenApiPathItem
                {
                    Operations = new Dictionary <OperationType, OpenApiOperation>(),
                };
                document.Document.Paths.Add(fullPath, pathItem);
            }

            return(new DslPathItem(document, pathItem));
        }
예제 #3
0
 public DslPathItem(DslDocument document, OpenApiPathItem pathItem)
 {
     Document = document;
     PathItem = pathItem;
 }