swagger-api/swagger-codegen

Queury Parameters get sent as parmeterMap's and not as part of the query string

Open

#2,339 opened on Mar 8, 2016

View on GitHub
 (2 comments) (0 reactions) (0 assignees)HTML (12,701 stars) (5,474 forks)batch import
Client: Scalahelp wanted

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