swagger-api / swagger-api/swagger-codegen
Queury Parameters get sent as parmeterMap's and not as part of the query string
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
I posted this to the scalatra website first just to see if anyone else is having issues. The framework does not support 2.X, so am not sure if this behaviour change, but if i don't have to use my implicit conversion and am just doing something silly that would be great.
Greetings. (this may belong to another list, apologies i'm starting here)
I have the following defintion for a scalata method
val createContactSwaggerDocs = apiOperation[ContactSubmissionResponse]("createContact")
.summary("Create a new contact row")
.notes("Creates a new Contact and emails the team, returns the data from the post")
.parameters(
queryParam[String]("send").description("set to send to deliver email, tests will turn this off at will"),
bodyParam[CreateContact]("newContact").description("Contact data").required)
.responseMessages(
ResponseMessageObject[ContactSubmissionResponse](Ok()),
ResponseMessageObject(BadRequest()),
ResponseMessageObject(Conflict()),
ResponseMessageObject(Forbidden()),
ResponseMessageObject(InternalServerError())
post("/:send", operation(createContactSwaggerDocs)) {
...
}
THe following is generated via swagger-codegen.sh
def createContact(send: String, newContact: CreateContact): ApiRequest[ResponseModel[ContactSubmissionResponse]] =
ApiRequest[ResponseModel[ContactSubmissionResponse]](ApiMethods.POST, baseUrl, "/contact/{send}", "application/json")
.withBody(newContact)
.withQueryParam("send", send)
.withSuccessResponse[ResponseModel[ContactSubmissionResponse]](200)
.withErrorResponse[ResponseModel[EmptyResponse]](400)
.withErrorResponse[ResponseModel[EmptyResponse]](500)
.withErrorResponse[ResponseModel[EmptyResponse]](403)
.withErrorResponse[ResponseModel[EmptyResponse]](409)
}
THe body param comes over perfectly, but the query param which i have defined as
ApiInvoker().execute(ContactApi.createContact("foobar",formData)) // anything but "send" in the variable will stop emailing from going out mainly for testing.
The issue is that when i dump the request body from scalatra i get
POST: /contact/%7Bsend%7D -- parameterMap: {send=[foobar]} -- body: {"email":"jeff.foo@bar.com","phoneNumber":"6175557705","issuerId":1,"firstName":"Heffe","lastName":"Last","subject":"Here is my subject","body":"asdfasdfasdf","contacted":0}
which when i try to access via a params("send") match, i will end up logging {send} - curly's included.
params("send") match {
case "send" =>
ContactIssuerEmail.sendMail(result, IssuersModel.find(contact.issuerId).get)
result.copy(sent = Option(UTCDateTime.now), contacted = 1).save()
logger.info(s"Saved sent time")
case _ => logger.info(s"OK, not sending email with paramater ${params("send")}")
when i run this through postman, with any variable, it works fine, sends when :send is send, and does not when its any other string, and i also use this successfully in specs2 for testing.
Going through swagger
ApiInvoker.execute(ApiClient.createContact("send",model))
i always get an object of a list. I can send them all through the post command, and in this case its rather simple to do, but i'd like to PUT("/:id") to be legit.
I assume i'm doing something wrong, so thanks in advance for pointing it out. When i send via postman, the params is marked simply as the string not as POST: /contact/%7Bsend%7D -- parameterMap: {send=[foobar]}. I don't mind parsing this out, but does not feel the canonical way of handling this as it seems specific to swagger, as specs2 and postman work fine with scalatra.
Jeff
If you want to see my solution, its here:
https://github.com/scalatra/scalatra/issues/562
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the generated Scala client entry points shown in the report: ApiInvoker.execute, ApiClient.createContact, and ApiRequest.withQueryParam. Compare the generated request URL and parameter handling with the working Postman and specs2 requests, then review the linked scalatra issue for the reported solution. Done means route parameters are substituted into the path instead of leaving {send} in the request URL.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- scala
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100