1

I have got a Java 8 Spring project that already has swagger configured to auto generate the swagger web-page documentation. I would like to also generate a single json file that contains all endpoints every time that project builds.

Is there a way to generate this using Java annotations or XML/property from Swagger or Spring?

OneNoOne
  • 587
  • 7
  • 23
  • you can take a look at https://springfox.github.io/springfox/, i use this to generate my swagger docs – ghovat Nov 19 '19 at 11:56
  • Why can't you go to `my-app/swagger.json` to get the json response of your end points? – nabster Nov 19 '19 at 21:17

2 Answers2

1

No, you can't generate json file with annotation. But you can do it in @SpringBootTest. When the test run, do request to port on which server started, retrieve api docs and write them to file.

Valeriy K.
  • 2,616
  • 1
  • 30
  • 53
0

There isn't an automatic way provided by Swagger or Spring for customized fields, but there is a direct translation from swagger.yml to swagger.json. To resolve my problem, that needs only custom fields, I used Swagger Parser to serialize the fields that I wanted into a json file. It is far from ideal, but It did work.

OneNoOne
  • 587
  • 7
  • 23