Ejemplo n.º 1
0
        private static SwaggerParameter FindReferencedParameter(string reference, IDictionary <string, SwaggerParameter> parameters)
        {
            if (reference != null && reference.StartsWith("#", StringComparison.Ordinal))
            {
                var parts = reference.Split('/');
                if (parts.Length == 3 && parts[1].Equals("parameters"))
                {
                    SwaggerParameter p = null;
                    if (parameters.TryGetValue(parts[2], out p))
                    {
                        return(p);
                    }
                }
            }

            return(null);
        }
Ejemplo n.º 2
0
 public IEnumerable <SwaggerParameter> AsParameters()
 {
     if (asParamCache == null)
     {
         Func <string, bool> isFormDataMimeType = type => type == "multipart/form-data" || type == "application/x-www-form-urlencoded";
         if (isFormDataMimeType(Content?.Keys?.FirstOrDefault()) && Content.Values.First().Schema != null) // => in: formData
         {
             var schema = Content.Values.First().Schema;
             asParamCache = schema.Properties.Select(prop =>
                                                     new SwaggerParameter
             {
                 Description = prop.Value.Description,
                 In          = ParameterLocation.FormData,
                 Name        = prop.Key,
                 IsRequired  = schema.Required?.Contains(prop.Key) ?? false,
                 Schema      = prop.Value,
                 Extensions  = schema.Extensions,
                 Style       = prop.Value?.Style
             });
         }
         else // => in: body
         {
             var schema = Content?.Values.FirstOrDefault()?.Schema;
             var p      = new SwaggerParameter
             {
                 Description = Description,
                 In          = ParameterLocation.Body,
                 Name        = Extensions.GetValue <string>("x-ms-requestBody-name") ?? "body",
                 IsRequired  = Required,
                 Schema      = schema,
                 Reference   = Reference,
                 Extensions  = Extensions,
                 Style       = schema?.Style
             };
             asParamCache = new [] { p };
         }
     }
     return(asParamCache);
 }