ninefinger
ninefinger

Reputation: 43

swagger-inflector and its use of x-swagger-router-controller and x-swagger-router-model

I am using swagger-inflector to design an API. I am trying to use x-swagger-router-controller and x-swagger-router-model as specified in the docs, but it is not working as specified.

The way I read the docs, these vendor extensions are supposed to create the class if it does not exist and then create a method named with the "operationId". However, they do not work as specified. (I looked at the code that I think is supposed to process this vendor extension, and it looks like the extension should be processed, but the classes are not created as expected. Well, the x-swagger-router-model generates the desired class name, but not the desired package).

If I use the inflector.yaml file and specify modelPackage and controllerPackage, the classes get created in those packages, but I need more granular control over what package is used for the generated classes. Am i doing something wrong, or is this broken?

Here is an example:

definitions:
  SomeObject:
    type: object
    x-swagger-router-model: com.example.api.dto.SomeObjectDTO
...
paths:
  /mypath:
    x-swagger-router-controller: com.example.api.controller.subpkg1.MyController
    get:
      ...

From the above example

I do not get a model class named SomeObjectDTO created in com/example/api/dto. If no modelPackage is specified in inflector.yaml, I get a model class named SomeObject created in the default package (io/swagger/...). The model class name that is generated in either case is SomeObject.java

I do not get a controller class named MyController created in com/example/api/controller/subpkg1. If no controllerPackage is specified in inflector.yaml, I get a controller class named "MyPathController" created in the default package (io/swagger/...). The controller class that is generated in either case is MyPathController.java.

It looks like this is a bug, or that I am missing something really obvious. Any pointers here?

Upvotes: 1

Views: 1830

Answers (1)

fehguy
fehguy

Reputation: 6824

the swagger-inflector code will not generate models for you--it will attempt to connect the routing information (via x-swagger-router-model) or via modelPackage + schema name. If that model cannot be loaded in the class loader, it will treat this model as a jackson JsonNode for all input (put/post) methods.

Upvotes: 1

Related Questions