Ejemplo n.º 1
0
        public static void FillDirectoryInfo(DirectoryStructure parent, EndpointMetadata entry)
        {
            entry = entry ?? throw new ArgumentNullException(nameof(entry));

            parent = parent ?? throw new ArgumentNullException(nameof(parent));

            string[] parts = entry.Path.Split('/');

            foreach (string part in parts)
            {
                if (!string.IsNullOrEmpty(part) && parent is object)
                {
                    parent = parent.DeclareDirectory(part);
                }
            }

            RequestInfo dirRequestInfo = new RequestInfo();

            foreach (RequestMetadata requestMetadata in entry.AvailableRequests)
            {
                string method = requestMetadata.Operation.ToString();

                foreach (RequestContentMetadata content in requestMetadata.Content)
                {
                    if (string.IsNullOrWhiteSpace(content.ContentType))
                    {
                        dirRequestInfo.SetFallbackRequestBody(method, content.ContentType, SchemaDataGenerator.GetBodyString(content.BodySchema));
                    }

                    dirRequestInfo.SetRequestBody(method, content.ContentType, SchemaDataGenerator.GetBodyString(content.BodySchema));
                }

                dirRequestInfo.AddMethod(requestMetadata.Operation.ToString());
            }

            if (dirRequestInfo.Methods.Count > 0 && parent is object)
            {
                parent.RequestInfo = dirRequestInfo;
            }
        }
Ejemplo n.º 2
0
        public static void FillDirectoryInfo(DirectoryStructure parent, EndpointMetadata entry)
        {
            entry = entry ?? throw new ArgumentNullException(nameof(entry));

            parent = parent ?? throw new ArgumentNullException(nameof(parent));

            string[] parts = entry.Path.Split('/');

            foreach (string part in parts)
            {
                if (!string.IsNullOrEmpty(part) && parent is object)
                {
                    parent = parent.DeclareDirectory(part);
                }
            }

            RequestInfo dirRequestInfo = new RequestInfo();

            foreach (KeyValuePair <string, IReadOnlyDictionary <string, IReadOnlyList <Parameter> > > requestInfo in entry.AvailableRequests)
            {
                string method = requestInfo.Key;

                foreach (KeyValuePair <string, IReadOnlyList <Parameter> > parameterSetsByContentType in requestInfo.Value)
                {
                    if (string.IsNullOrEmpty(parameterSetsByContentType.Key))
                    {
                        dirRequestInfo.SetFallbackRequestBody(method, parameterSetsByContentType.Key, SchemaDataGenerator.GetBodyString(parameterSetsByContentType.Value));
                    }

                    dirRequestInfo.SetRequestBody(method, parameterSetsByContentType.Key, SchemaDataGenerator.GetBodyString(parameterSetsByContentType.Value));
                }

                dirRequestInfo.AddMethod(method);
            }

            if (dirRequestInfo.Methods.Count > 0 && parent is object)
            {
                parent.RequestInfo = dirRequestInfo;
            }
        }