Exemplo n.º 1
0
        internal IDictionary <ODataSegment, IDictionary <string, string> > CalculateParameterMapping(OpenApiConvertSettings settings)
        {
            IDictionary <ODataSegment, IDictionary <string, string> > parameterMapping = new Dictionary <ODataSegment, IDictionary <string, string> >();

            // From Open API spec, parameter name is case sensitive, so don't use the IgnoreCase HashSet.
            // HashSet<string> parameters = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
            HashSet <string> parameters = new HashSet <string>();

            foreach (var segment in Segments)
            {
                // So far, only care about the key segment and operation segment
                if (segment.Kind == ODataSegmentKind.Key)
                {
                    ODataKeySegment keySegment = (ODataKeySegment)segment;
                    parameterMapping[keySegment] = keySegment.GetKeyNameMapping(settings, parameters);
                }
                else if (segment.Kind == ODataSegmentKind.Operation)
                {
                    ODataOperationSegment operationSegment = (ODataOperationSegment)segment;
                    parameterMapping[operationSegment] = operationSegment.GetNameMapping(settings, parameters);
                }
            }

            return(parameterMapping);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Gets the path item name.
        /// </summary>
        /// <param name="settings">The settings.</param>
        /// <returns>The string.</returns>
        public string GetPathItemName(OpenApiConvertSettings settings)
        {
            Utils.CheckArgumentNull(settings, nameof(settings));

            // From Open API spec, parameter name is case sensitive, so don't use the IgnoreCase HashSet.
            // HashSet<string> parameters = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
            HashSet <string> parameters = new HashSet <string>();
            StringBuilder    sb         = new StringBuilder();

            if (!string.IsNullOrWhiteSpace(settings.PathPrefix))
            {
                sb.Append("/");
                sb.Append(settings.PathPrefix);
            }

            foreach (var segment in Segments)
            {
                string pathItemName = segment.GetPathItemName(settings, parameters);

                if (segment.Kind == ODataSegmentKind.Key &&
                    (settings.EnableKeyAsSegment == null || !settings.EnableKeyAsSegment.Value))
                {
                    sb.Append("(");
                    sb.Append(pathItemName);
                    sb.Append(")");
                }
                else // other segments
                {
                    if (segment.Kind == ODataSegmentKind.Operation)
                    {
                        ODataOperationSegment operation = (ODataOperationSegment)segment;
                        if (operation.IsEscapedFunction && settings.EnableUriEscapeFunctionCall)
                        {
                            sb.Append(":/");
                            sb.Append(pathItemName);
                            continue;
                        }
                    }

                    sb.Append("/");
                    sb.Append(pathItemName);
                }
            }

            return(sb.ToString());
        }
Exemplo n.º 3
0
        /// <summary>
        /// Gets the path item name.
        /// </summary>
        /// <param name="settings">The settings.</param>
        /// <returns>The string.</returns>
        public string GetPathItemName(OpenApiConvertSettings settings)
        {
            Utils.CheckArgumentNull(settings, nameof(settings));

            HashSet <string> parameters = new HashSet <string>();
            StringBuilder    sb         = new StringBuilder();

            foreach (var segment in Segments)
            {
                string pathItemName = segment.GetPathItemName(settings, parameters);

                if (segment.Kind == ODataSegmentKind.Key &&
                    (settings.EnableKeyAsSegment == null || !settings.EnableKeyAsSegment.Value))
                {
                    sb.Append("(");
                    sb.Append(pathItemName);
                    sb.Append(")");
                }
                else // other segments
                {
                    if (segment.Kind == ODataSegmentKind.Operation)
                    {
                        ODataOperationSegment operation = (ODataOperationSegment)segment;
                        if (operation.IsEscapedFunction && settings.EnableUriEscapeFunctionCall)
                        {
                            sb.Append(":/");
                            sb.Append(pathItemName);
                            continue;
                        }
                    }

                    sb.Append("/");
                    sb.Append(pathItemName);
                }
            }

            return(sb.ToString());
        }