public static StringBuilder OnBuildMethodParameter(Method method,
            SwaggerParameter currentSwaggerParam,
            StringBuilder paramNameBuilder)
        {
            if (currentSwaggerParam == null)
            {
                throw new ArgumentNullException("currentSwaggerParam");
            }

            bool hasCollectionFormat = currentSwaggerParam.CollectionFormat != CollectionFormat.None;

            if (currentSwaggerParam.Type == DataType.Array && !hasCollectionFormat)
            {
                // If the parameter type is array default the collectionFormat to csv
                currentSwaggerParam.CollectionFormat = CollectionFormat.Csv;
            }

            if (hasCollectionFormat)
            {
                AddCollectionFormat(currentSwaggerParam, paramNameBuilder);
                if (currentSwaggerParam.In == ParameterLocation.Path)
                {
                    if (method == null || method.Url == null)
                    {
                       throw new ArgumentNullException("method"); 
                    }

                    method.Url = method.Url.Replace(
                        string.Format(CultureInfo.InvariantCulture, "{0}", currentSwaggerParam.Name),
                        string.Format(CultureInfo.InvariantCulture, "{0}", paramNameBuilder));
                }
            }
            return paramNameBuilder;
        }
        private static void AddCollectionFormat(SwaggerParameter swaggerParameter, StringBuilder parameterName)
        {
            if (swaggerParameter.In == ParameterLocation.FormData)
            {
                // http://vstfrd:8080/Azure/RD/_workitems/edit/3172874
                throw new NotImplementedException();
            }

            //Debug.Assert(!string.IsNullOrEmpty(swaggerParameter.CollectionFormat));
            Debug.Assert(swaggerParameter.CollectionFormat != CollectionFormat.None);
            parameterName.Append(":");

            switch (swaggerParameter.CollectionFormat)
            {
                case CollectionFormat.Csv:
                    parameterName.Append("commaSeparated");
                    break;

                case CollectionFormat.Pipes:
                    parameterName.Append("pipeSeparated");
                    break;

                case CollectionFormat.Ssv:
                    parameterName.Append("spaceSeparated");
                    break;

                case CollectionFormat.Tsv:
                    parameterName.Append("tabSeparated");
                    break;

                case CollectionFormat.Multi:
                    // TODO multi is not supported yet: http://vstfrd:8080/Azure/RD/_workitems/edit/3172867
                    throw new NotSupportedException(string.Format(CultureInfo.InvariantCulture, 
                        Resources.MultiCollectionFormatNotSupported,
                        swaggerParameter.Name));
                default:
                    throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, 
                        Resources.InvalidCollectionFormat,
                        swaggerParameter.CollectionFormat, 
                        swaggerParameter.Name));
            }
        }
Example #3
0
 public ParameterBuilder(SwaggerParameter swaggerParameter, SwaggerModeler modeler)
     : base(swaggerParameter, modeler)
 {
     _swaggerParameter = swaggerParameter;
 }
Example #4
0
        public SwaggerParameter Unwrap(SwaggerParameter swaggerParameter)
        {
            if (swaggerParameter == null)
            {
                throw new ArgumentNullException("swaggerParameter");
            }

            // If referencing global parameters serializationProperty
            if (swaggerParameter.Reference != null)
            {
                string referenceKey = swaggerParameter.Reference.StripParameterPath();
                if (!ServiceDefinition.Parameters.ContainsKey(referenceKey))
                {
                    throw new ArgumentException(
                        string.Format(CultureInfo.InvariantCulture,
                        Resources.DefinitionDoesNotExist, referenceKey));
                }

                swaggerParameter = ServiceDefinition.Parameters[referenceKey];
            }

            // Unwrap the schema if in "body"
            if (swaggerParameter.Schema != null && swaggerParameter.In == ParameterLocation.Body)
            {
                swaggerParameter.Schema = Resolver.Unwrap(swaggerParameter.Schema);
            }

            return swaggerParameter;
        }