private List <Parameter> CreateGetParameters(Utils.TypeDescription typeDescription, bool needPathParameter) { var parameters = new List <Parameter>(); var partitionKey = typeDescription.ColumnDescriptions.FirstOrDefault(c => c.IsPartitionKey); if (needPathParameter && partitionKey != default(Utils.ColumnDescription)) { parameters.Add( new Parameter { Name = "id", In = ParameterIn.Path, Required = true, Type = "string", Description = $"{partitionKey.CamelCaseName}: Id for {typeDescription.CSharpName}", } ); } var indexes = typeDescription.ColumnDescriptions.Where(c => c.IsClusteringKey || c.IsIndex).ToList(); foreach (var index in indexes) { var parameter = new Parameter { Name = Utils.Utils.CamelCase(index.CamelCaseName), In = ParameterIn.Query, Required = false, Type = GetParameterType(index.CassandraType), Format = GetParameterFormat(index.CassandraType) }; parameters.Add(parameter); } return(parameters); }
private PathItem CreatePathItem(Utils.TypeDescription typeDescription, string idParam = null) { var pathItem = new PathItem { Parameters = null }; var readPrivilege = (new List <string> { "read" }).AsEnumerable(); var readSecurityRequirement = new Dictionary <SecuritySchemes, IEnumerable <string> > { { SecuritySchemes.Oauth2, readPrivilege } }; var readWritePrivilege = (new List <string> { "read", "write" }).AsEnumerable(); var readWriteSecurityRequirement = new Dictionary <SecuritySchemes, IEnumerable <string> > { { SecuritySchemes.Oauth2, readWritePrivilege } }; var getParameter = new Parameter { In = ParameterIn.Body, Required = true, Ref = $"#/definitions/{typeDescription.CSharpName}" }; var getParameters = new List <Parameter> { getParameter }; pathItem.Get = new Operation { Produces = acceptedFormats, Consumes = acceptedFormats, Description = $"Retrieves all {typeDescription.CSharpName}s.", OperationId = $"get{typeDescription.CSharpName}" + ((idParam != null) ? "ById" : ""), SecurityRequirements = (IDictionary <SecuritySchemes, IEnumerable <string> >)readSecurityRequirement, Parameters = CreateGetParameters(typeDescription, idParam != null), Responses = CreateResponsesFor(new List <string> { "200", "303", "401", "404", "500" }, typeDescription.CSharpName) }; /* * pathItem.Post = new Operation * { * Produces = acceptedFormats, * Consumes = acceptedFormats, * Description = $"Creates a {typeDescription.Name}.", * OperationId = $"add{typeDescription.Name}", * SecurityRequirements = (IDictionary<SecuritySchemes, IEnumerable<string>>)readWriteSecurityRequirement, * Parameters = new List<Parameter> { * new Parameter * { * In = ParameterIn.Body, * Required = true, * Ref = $"#/definitions/{typeDescription.Name}" * } }, * Responses = CreateResponsesFor(new List<string> { "200", "201", "303", "401", "404", "500" }, typeDescription.Name) * }; * * if (idParam == null) * { * pathItem.Put = new Operation * { * Produces = acceptedFormats, * Consumes = acceptedFormats, * Description = $"Update an existing {typeDescription.Name}.", * OperationId = $"update{typeDescription.Name}", * Responses = pathItem.Get.Responses, * }; * } * else * { * pathItem.Delete = pathItem.Post; * pathItem.Delete.Description = $"Delete an existing {typeDescription.Name}."; * pathItem.Delete.OperationId = $"delete{typeDescription.Name}"; * } */ return(pathItem); }