private IEnumerable <OpenApiParameter> GenerateComplexParameter(ParameterDescriptor apiParameter, SchemaRepository schemaRespository) { var parameters = new List <OpenApiParameter>(); var propertyInfos = apiParameter.Type.GetProperties(); foreach (var propertyInfo in propertyInfos) { if (!propertyInfo.PropertyType.IsSample()) { throw new LmsException("指定QString 参数不允许指定复杂类型参数"); } var name = apiParameter.From == ParameterFrom.Path ? apiParameter.Name : propertyInfo.Name; name = _options.DescribeAllParametersInCamelCase ? name.ToCamelCase() : name; var location = ParameterLocationMap[apiParameter.From]; var isRequired = (apiParameter.From == ParameterFrom.Path) || apiParameter.Type.GetCustomAttributes().Any(attr => RequiredAttributeTypes.Contains(attr.GetType())); var schema = GenerateSchema(apiParameter.Type, schemaRespository, propertyInfo, null); var parameter = new OpenApiParameter { Name = name, In = location, Required = isRequired, Schema = schema }; var filterContext = new ParameterFilterContext( apiParameter, _schemaGenerator, schemaRespository, null, apiParameter.ParameterInfo); foreach (var filter in _options.ParameterFilters) { filter.Apply(parameter, filterContext); } parameters.Add(parameter); } return(parameters); }
private OpenApiParameter GenerateSampleParameter(ParameterDescriptor apiParameter, SchemaRepository schemaRespository) { var name = _options.DescribeAllParametersInCamelCase ? apiParameter.Name.ToCamelCase() : apiParameter.Name; var location = ParameterLocationMap[apiParameter.From]; var isRequired = (apiParameter.From == ParameterFrom.Path) || apiParameter.Type.GetCustomAttributes() .Any(attr => RequiredAttributeTypes.Contains(attr.GetType())); var schema = GenerateSchema(apiParameter.Type, schemaRespository, null, apiParameter.ParameterInfo); var parameter = new OpenApiParameter { Name = name, In = location, Required = isRequired, Schema = schema }; var filterContext = new ParameterFilterContext( apiParameter, _schemaGenerator, schemaRespository, null, apiParameter.ParameterInfo); foreach (var filter in _options.ParameterFilters) { filter.Apply(parameter, filterContext); } return(parameter); }