コード例 #1
0
        private OpenApiRequestBody GenerateRequestBodyFromBodyParameter(
            ApiDescription apiDescription,
            SchemaRepository schemaRepository,
            ApiParameterDescription bodyParameter)
        {
            var contentTypes = InferRequestContentTypes(apiDescription);

            var isRequired = bodyParameter.IsRequiredParameter();

            var schema = GenerateSchema(
                bodyParameter.ModelMetadata.ModelType,
                schemaRepository,
                bodyParameter.PropertyInfo(),
                bodyParameter.ParameterInfo());

            return(new OpenApiRequestBody
            {
                Content = contentTypes
                          .ToDictionary(
                    contentType => contentType,
                    contentType => new OpenApiMediaType
                {
                    Schema = schema
                }
                    ),
                Required = isRequired
            });
        }
コード例 #2
0
        private OpenApiParameter GenerateParameter(
            ApiParameterDescription apiParameter,
            SchemaRepository schemaRepository)
        {
            var name = _options.DescribeAllParametersInCamelCase
                ? apiParameter.Name.ToCamelCase()
                : apiParameter.Name;

            var location = (apiParameter.Source != null && ParameterLocationMap.ContainsKey(apiParameter.Source))
                ? ParameterLocationMap[apiParameter.Source]
                : ParameterLocation.Query;

            var isRequired = apiParameter.IsRequiredParameter();

            var schema = (apiParameter.ModelMetadata != null)
                ? GenerateSchema(
                apiParameter.ModelMetadata.ModelType,
                schemaRepository,
                apiParameter.PropertyInfo(),
                apiParameter.ParameterInfo(),
                apiParameter.RouteInfo)
                : new OpenApiSchema {
                Type = "string"
            };

            var parameter = new OpenApiParameter
            {
                Name     = name,
                In       = location,
                Required = isRequired,
                Schema   = schema
            };

            var filterContext = new ParameterFilterContext(
                apiParameter,
                _schemaGenerator,
                schemaRepository,
                apiParameter.PropertyInfo(),
                apiParameter.ParameterInfo());

            foreach (var filter in _options.ParameterFilters)
            {
                filter.Apply(parameter, filterContext);
            }

            return(parameter);
        }