Search code examples
javaspringswaggerswagger-codegen

how is ApiOriginFilter.java generated


I have a project which I found ApiOriginFilter.java under generated code, is this auto generated by swagger?

And,

There is a method doFilter which contains response headers.

Currently, a value is set to Access-Control-Allow-Origin : *, I want to change to Access-Control-Allow-Origin : http://example.org

As this file is auto generated, which yaml file and where should I add my change so that http://exampl.org will appear instead of *


Solution

  • The swagger-codegen generates source files based on mustache templates. In the folder for the spring templates you can see the following supporting file: apiOriginFilter.mustache

    you can the change Access-Control-Allow-Origin inside of the template file.

    https://github.com/swagger-api/swagger-codegen/blob/master/modules/swagger-codegen/src/main/resources/JavaSpring/apiOriginFilter.mustache

    There's more details on modifying templates inside the README.md

    https://github.com/swagger-api/swagger-codegen/