1

Im trying to build service using swagger inflector. But currenltl i encountered some problem, when im trying to post complex object to my swagger controller. Please take a look on my configuration provided bellow.

My swagger.yaml:

swagger: "2.0" info: version: 1.0.0 title: Dummy Controller basePath: /v1 tags: - name: Dummy Controller description: Dummy controller schemes: - http paths: /someService/create: post: tags: - someService summary: Test description: "" operationId: createPoint consumes: - application/json - application/xml produces: - application/xml - application/json parameters: - in: body name: body description: Created object required: false schema: $ref: '#/definitions/Point' responses: default: description: successful operation definitions: Point: title: Point description: '' type: object properties: latitude: description: '' type: string longitude: description: '' type: string required: - latitude - longitude ApiResponse: properties: code: type: integer format: int32 type: type: string message: type: string xml: name: "##default" 

My controller:

public class SomeServiceController { public ResponseContext createPoint(RequestContext request, Point point){ System.out.println(point); return new ResponseContext() .status(Status.OK); } } 

When im trying to make post like this:

POST http://localhost:8080/v1/someService/create { "latitude":"10", "longitude":"20" } 

Im getting

11:36:51.814 [qtp931940545-13] ERROR i.s.i.c.SwaggerOperationController - failed to invoke method public io.swagger.inflector.models.ResponseContext com.swagger.test.SomeServiceController.createPoint(io.swagger.inflector.models.RequestContext,com.swagger.test.model.Point) java.lang.IllegalArgumentException: argument type mismatch 

My dependencies:

<dependencies> <dependency> <groupId>io.swagger</groupId> <artifactId>swagger-inflector</artifactId> <version>1.0.2</version> </dependency> <dependency> <groupId>org.apache.cxf</groupId> <artifactId>cxf-rt-frontend-jaxrs</artifactId> <version>3.1.1</version> </dependency> </dependencies> 

Please help! What i have missed?

4
  • Did you add the Content-Type: application/json header to your request? Commented Dec 13, 2017 at 10:31
  • @Helen Yes, ive tried both json and xml (for xml structure) content types.. Commented Dec 13, 2017 at 11:36
  • As i found later, the object which comes to controller is ObjectNode type.. So it means that swagger doesnt do any conversion to referenced model? Commented Dec 13, 2017 at 12:32
  • No idea. Can you try the latest version of Inflector, 2.0.0-rc0? Commented Dec 13, 2017 at 12:37

1 Answer 1

2

The next problem was found: My model objects (Point) was placed in wrong package. If inflector cant find model it will pass JsonNode to Controller method. Thats why i have recieved argument type mismatch. Java was unable to map JsonNode to Point.

Hope it will help to someone!

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.