Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Operation GET generates both body param and path param #66

Open
anitaan opened this issue Feb 13, 2018 · 4 comments
Open

Operation GET generates both body param and path param #66

anitaan opened this issue Feb 13, 2018 · 4 comments

Comments

@anitaan
Copy link

anitaan commented Feb 13, 2018

Hi

I am new to swagger and http-akka. When I annotate my GET method I get this,
"/questions/{id}" : {
"get" : {
"tags" : [ "questions" ],
"summary" : "Retrives a question",
"description" : "",
"operationId" : "GetQuestion",
"produces" : [ "application/json" ],
"parameters" : [ {
"in" : "body",
"name" : "body",
"required" : false,
"schema" : {
"type" : "string"
}
}, {
"name" : "id",
"in" : "path",
"description" : "The unique id of the question",
"required" : true,
"type" : "string",
"default" : "test"
} ],
"responses" : {
"200" : {
"description" : "Returns the info if found",
"schema" : {
"$ref" : "#/definitions/Question"
}
},
"404" : {
"description" : "Resource not found"
},
"500" : {
"description" : "Internal server error"
}
}
}
}
},

But I have not specified any body. Seems it just turns up automatically.

What do I do wrong, here is the anotation on the method.

@path("/{id}")
@ApiOperation(value = "Retrives a question", nickname = "GetQuestion", httpMethod = "GET", response = classOf[Question])
@ApiImplicitParams(Array(
new ApiImplicitParam(name = "id", value = "The unique id of the question", defaultValue="test", required = true, dataType = "string", paramType = "path")
))
@ApiResponses(Array(
new ApiResponse(code = 200, message = "Returns the info if found", response = classOf[Question]),
new ApiResponse(code = 404, message = "Resource not found"),
new ApiResponse(code = 500, message = "Internal server error")
))
def getById(id: String): Future[Option[Question]] = Future {
questions.find(_.id == id)
}

@pjfanning
Copy link
Collaborator

swagger-akka-http uses swagger-jaxrs under the hood.
It looks for every function in your class and documents the input and output params on the function.
By also specifying ApiImplicitParam annotation, it seems to the code that you have 2 inputs.
You could replace the ApiImplicitParam annotation with an ApiModelProperty annotation like in https://github.com/swagger-api/swagger-scala-module/blob/develop/src/test/scala/models/EnumModels.scala

@anitaan
Copy link
Author

anitaan commented Feb 23, 2018

Hi
Thank you for your answer. Sorry for not responding faster. Maybe you have a different solution described, but I solved it by annotating with ignore on the input param to the function like this;
def getById(@ApiParam(hidden = true) id: String): Future[Option[UserProfile]]

It worked:-)

@rtehok
Copy link

rtehok commented Jul 25, 2022

Hello,

I got the same issue because, apparently, when you create a method def function(id: String, foo: String) and do not want to use the param foo, a body request gets added in the generated cURL with something like curl -X GET -d 'string' http://host:80/<id>.
Even if cURL handles it correctly, swagger doesn't.
After some research and experimentation, I managed to find a solution by writing this (could not find @ApiParam annotation)

  @GET
  @Path("foo/{id}")
  @Produces(Array(MediaType.APPLICATION_JSON))
  @Operation(summary = "find id info", description = "",
    responses = Array(
      new ApiResponse(responseCode = "200", description = "information",
        content = Array(new Content(schema = new Schema(implementation = classOf[IdResponse])))),
      new ApiResponse(responseCode = "500", description = "Internal server error"))
  )
  def getModel(@Parameter(name = "id", in = ParameterIn.PATH, description = "id") @PathParam("modelId") id: String)
                       (@Parameter(name = "user", in = ParameterIn.DEFAULT, description = "user info", hidden = true, required = false) user: User): Route = {

Using the @Parameters annotation does not seem to work and using function currying seems the only way to make this work.

@pjfanning
Copy link
Collaborator

@ApiParam is an annotation for swagger 1.x annotation lib - @Parameter is the closed equivalent in the newer swagger annotation lib

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants