How to pass array of string as parameters in swagger ui - swagger

Below is the REST api which i want to document using Swagger UI
#ApiOperation(
nickname = "alertForBundleId",
value = "alertForBundleId",
notes = "",
httpMethod = "GET")
def alertForBundleId(
#ApiParam(name = "mfr", value = "Manufacturer", required = true) #PathParam("mfr") mfr: String,
#ApiParam(name = "col", value = "Columns", required = true) #QueryParam("col") cols: List[String])){...}
Here cols parameter is accepting List of string.When i pass two elements for the list separating by new line, then its generates url like ?col=sysid%2Calert_idwhile it should be like ?col=sysid&col=alert_idit works well for single element listAny help will be greatly appreciated.

Related

How to call a value in map element only when it matches another var

I am using the Terraform provider mrparkers/keycloak to attempt to assign Keycloak groups a list of users.
The snippet below creates realms, groups, and users correctly, but I am stumped on the final line for calling a list of users which should belong to the group being looped through.
Anything to point me in the right direction would be hugely appreciated. :)
vars
variable "realms" {
description = "realms"
type = set(string)
default = ["mrpc"]
}
variable "mrpc-groups" {
type = map(object({
name = string
realm = string
members = set(string)
}))
default = {
"0" = {
realm = "mrpc"
name = "mrpc-admins"
members = ["hellfire", "hellfire2"]
},
"1" = {
realm = "mrpc"
name = "mrpc-mods"
members = ["hellfire2"]
}
}
}
variable "mrpc-users" {
type = map(object({
username = string
email = string
first_name = string
last_name = string
realm = string
}))
default = {
"0" = {
realm = "mrpc"
username = "hellfire"
email = "bla#bla.bla"
first_name = "hell"
last_name = "fire"
}
"1" = {
realm = "mrpc"
username = "hellfire2"
email = "bla2#bla.bla"
first_name = "hell2"
last_name = "fire2"
}
}
}
resources
resource "keycloak_realm" "realm" {
for_each = var.realms
realm = each.value
}
resource "keycloak_group" "group" {
for_each = var.mrpc-groups
realm_id = each.value["realm"]
name = each.value["name"]
depends_on = [keycloak_realm.realm]
}
resource "keycloak_user" "user" {
for_each = var.mrpc-users
realm_id = each.value["realm"]
username = each.value["username"]
email = each.value["email"]
first_name = each.value["first_name"]
last_name = each.value["last_name"]
}
resource "keycloak_group_memberships" "group_members" {
for_each = keycloak_group.group
realm_id = each.value["realm_id"]
group_id = each.value["name"]
members = [ "hellfire2" ]
# i want this to be var.mrpc-groups.*.members (* used incorrectly here i think)
# if
# var.mrpc-groups.*.name == each.value["name"]
#
# so that the correct member list in the vars is used when the matching group is being looped over
# any method to get the final outcome is good :)
}
We can use the distinct and flatten functions in conjunction with a for expression within a list constructor to solve this:
distinct(flatten([for key, attrs in var.mrpc_groups : attrs.members]))
As tested locally, this will return the following for your values exactly as requested in the question indicated by var.mrpc-groups.*.members:
members = [
"hellfire",
"hellfire2",
]
The for expression iterates through the variable mrpc_groups map and returns the list(string) value assigned to the members key within each group's key value pairs. The lambda/closure scope variables are simply key and attrs because the context is unclear to me, so I was unsure what a more descriptive name would be.
The returned structure would be a list where each element would be the list assigned to the members key (i.e. [["hellfire", "hellfire2"], ["hellfire2"]]). We use flatten to flatten the list of lists into a single list comprised of the elements of each nested list.
There would still be duplicates in this flattened list, and therefore we use the distinct function to return a list comprised of only unique elements.
For the additional question about assigning the members associated with the group at the current iteration, we can simply implement the following:
members = flatten([for key, attrs in var.mrpc_groups : attrs.members if attrs.name == each.value["name"]])
This will similarly iterate through the map variable of var.mrpc_groups, and construct a list of the members list filtered to only the group matching the name of the current group iterated through keycloak_group.group. We then flatten again because it is also a nested list similar to the first question and answer.
Note that for this additional question it would be easier for you in general and for this answer if you restructured the variable keys to be the name of the group instead of as a nested key value pair.

Docusign API Ruby: How to set predefined Custom Fields for an Envelope creation?

I created some enveloppe custom fields in the admin of Docusign.
So I'd to know how to set their value when I create an enveloppe from the docusign Ruby API.
I've tried to set there like this, but it doesn't work. When I send the envelope the custom fields are not filled.
envelope_definition = DocuSign_eSign::EnvelopeDefinition.new
custom_fields = DocuSign_eSign::CustomFieldsEnvelope.new(
{"name":"enveloppe_annee","value":"2019"}
)
envelope_definition.custom_fields = [custom_fields]
The envelope_definition.custom_fields attribute takes a single instance of custom_fields. (Not an array)
custom_fields is an object that has two attributes:
list_custom_fields wants an array of ListCustomField
text_custom_fields wants an array of TextCustomField
Based on the above, can you redo your request?
envelope_definition = DocuSign_eSign::EnvelopeDefinition.new({status: 'sent', templateId:'a19dXXXX-XXXX-4ce7-XXXX-56cXXXX83364', emailSubject: 'Example Document Signing'})
signer = DocuSign_eSign::TemplateRole.new({email: 'email#eample.com', name: 'Johny Walker', roleName: 'signer'})
text = DocuSign_eSign::Text.new
text.tab_label = 'label_id of the custom field'
text.value = 'value for the custom field'
tabs = DocuSign_eSign::Tabs.new
tabs.text_tabs = [text]
signer.tabs = tabs
envelope_definition.template_roles = [signer]
This should work for you

how to add namespace.expect for parameters passed in url as argument

I have written below Resource Class:
#clinic_api_ns.route("/patient/profile")
class PatientProfile(Resource):
def get(self):
patient = request.args.get(patient)
relative = request.args.get(relative)
relationType = request.args.get(relationType)
contactNumber = request.args.get(contactNumber)
townCity = request.args.get(townCity)
return controller.get_patient_profile(patient, relative, relationType, contactNumber, townCity)
so that to get patient profile , I can use passed parameters through URL such as http://ip.address/api/clinic/patient/profile?patient=<patientName>&relative=<relativeName>&relationType=<relation>
but this throws error in swagger documentation and even if I tried adding #_api_ns.expect(patient_profile, validate=True)
where patient_profile is
class PatientProfile(object):
profile = clinic_api_ns.model("profile", {
"patient": fields.String(required=True, description="name of the patient."),
"relative": fields.String(required=True, description="name of parent or husband."),
"relation": fields.String(required=True, description="type of relation with patient."),
"contactnumber": fields.String(required=True, description="contact number of the patient."),
"townCity": fields.String(required=True, description="town or city the patient belongs to."),
})
You can use parser to solve this.
parser = api.parser()
parser.add_argument('param', type=int, help='Some param', location='path') # "location='path'" means look only in the querystring
#api.expect(parser)

Swagger is adding additional body parameter for get method

I'm using swagger akka-http wrapper, Currently for my get request swagger is adding additional body parameter in swagger spec of type string
#Path("/{id}/status")
#ApiOperation(httpMethod = "GET", response = classOf[JobStatus], value = "Returns Job status")
#ApiImplicitParams(Array(
new ApiImplicitParam(name = "id", required = true, dataType = "integer", paramType = "path", value = "Job id for which status be fetched")))
#ApiResponses(Array(
new ApiResponse(code = 200, message = "OK", response = classOf[JobStatus]),
new ApiResponse(code = 404, message = "Job not found")))
def getStatus(id: String): Route =
get {
....
I'm wondering this is because of getStatus method taking parameter "id", Do any one have any suggestion
The generated docs are based on the both the function parameters and the implicit parameters (ie the union of the 2 parameter sets).
I would suggest that you remove the ApiImplicitParam annotation and add an ApiModelProperty annotation to the id field in the function parameter list if you need to override its declared type of String.
Example use of ApiModelProperty annotation:
https://github.com/pjfanning/swagger-akka-http-sample/blob/master/src/main/scala/com/example/akka/addoption/AddOptionActor.scala

Passing an entire object through Action Link

Is it possible to pass an entire object from my view to my controller. In my for each the address is populated as expected however I am struggling to pass this complete object back to my controller method "EditPlusNewAddress".
#if (Model.Count() > 0)
{
<table border="1" cellpadding="1">
#foreach (var address in Model)
{
<tr>
<td>#address.postcode</td>
<td>#address.lat</td>
<td>#address.lng</td>
<td>#address.thorofare</td>
<td>#address.dthorofare</td>
<td>#address.county</td>
<td>#address.paon</td>
<td>#address.saon</td>
<td>#address.posttown</td>
<td>#address.uprn</td>
<td>#Html.ActionLink("Select Address", "EditPlusNewAddress", new { evpId = 11}, new JsonAddressModel{ county = address.county,
dthorofare = address.dthorofare,
ExtensionData = address.ExtensionData,
lat = address.lat,
lng = address.lng,
paon = address.paon,
postcode = address.postcode,
posttown = address.posttown,
saon = address.saon,
thorofare = address.thorofare,
uprn = address.uprn}, null)</td>
</tr>
}
</table>
}
I'm getting the following errors:
Error 2 Argument 4: cannot convert from 'AnonymousType#1' to 'string'
Error 3 Argument 5: cannot convert from
'Solution.Core.AddressService.JsonAddressModel' to
'System.Web.Routing.RouteValueDictionary'
Error 1 'System.Web.Mvc.HtmlHelper>'
does not contain a definition for 'ActionLink' and the best extension
method overload
'System.Web.Mvc.Html.LinkExtensions.ActionLink(System.Web.Mvc.HtmlHelper,
string, string, string, System.Web.Routing.RouteValueDictionary,
System.Collections.Generic.IDictionary)' has some
invalid arguments
We don't pass objects back from a view, we pass name:value combinations and build a model from that on the server:
In this case all you need is an [HttpGet] action on your controller accepting a JsonAddressModel parameter
[HttpGet]
public ActionResult EditPlusNewAddress(JsonAddressModel model)
{
....
}
Then in your view you pass up the values you want to use. Here the error message should have given you the clue, as you're simply using the wrong type of object... a JsonAddressModel instead of a RouteValueDictionary.
This is because you went a position to far in your ActionLink definition. So assuming evpId is the Identifier for you JsonAddressModel it should have just been:
#Html.ActionLink("Select Address", "EditPlusNewAddress",
new { evpId = 11 ,
county = address.county,
dthorofare = address.dthorofare,
ExtensionData = address.ExtensionData,
lat = address.lat,
lng = address.lng,
paon = address.paon,
postcode = address.postcode,
posttown = address.posttown,
saon = address.saon,
thorofare = address.thorofare,
uprn = address.uprn
})
That would be how you build up an url that looked like:
/Controller/EditPlusNewAddress?evpId=11&county=burbank&dthorofare=abc&......
The model binder is then smart enough to take the query string and build a JsonAddressModel out of it. So that would be how you could pass around a complex url for sharing search filters, etc.
The problem however is GET is supposed to be an idempotent operation. Whereas you're calling your action "EditPlusNewAddress" which sounds like you want to change something server side and for that, good practice dictates, that you should be creating a form and POSTing it back.
GET links that change things reeks of malware, evil doers and/or incompetence.

Resources