Showing results for 
Search instead for 
Did you mean: 

Append throws Exception on endpoint definition

Frequent Visitor

Append throws Exception on endpoint definition

I have a springboot project and a swagger.yaml file to generate the java code through openapi maven plugin. 
I would like to append "throws Exception" on a method of generated api java interface. I read documentation but I didn't find anything. Is there a way to specify on swagger.yaml file which excpetion should be added to the endpoint?




Re: Append throws Exception on endpoint definition



Assuming you are referring to codegen 2.x version (latest version is 2.4.0), and to "spring" server generator, atm generated operation methods in interface and/or controller don't throw Exception.


There are ongoing efforts and tickets (e.g. to allow to add such behaviour as an option (and any help in this or other areas is welcome..), but with current version that is not possible.


The best way to achieve what you mention with current version is probably using custom templates (see, adding the `throw Exception` to the custom template, and passing the `templateDirectory` parameter (

In this case, you would copy the related template dir ( to a dir of your choice (then referenced in parameter), and modify needed files (in this case `api.mustache` and `apiController.mustache`)




api.mustache line 103


{{#jdk8}}default {{/jdk8}}{{#responseWrapper}}{{.}}<{{/responseWrapper}}ResponseEntity<{{>returnTypes}}>{{#responseWrapper}}>{{/responseWrapper}} {{#delegate-method}}_{{/delegate-method}}{{operationId}}({{#allParams}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}}{{#hasMore}},{{/hasMore}}{{/allParams}}) throws Exception{{^jdk8}};{{/jdk8}}{{#jdk8}} {



New Here?
Join us and watch the welcome video: