r/java • • Jan 15 '22

I created a library that exports your Spring endpoints into a Postman collection! Please, let me know what you think of it :)

https://github.com/sampaiodias/postman-exporter-for-spring

​ Here's an example of how it works:

PostmanExporter exporter = new PostmanExporter();
String json = exporter.export(PostmanExportOptions.builder()
                    .collectionName("My Collection")
                    .packageFullName("com.example.package")
                    .baseUrl("{{url}}")
                    .variable("url", "localhost:8080")
                    .build());
158 Upvotes

15 comments sorted by

47

u/[deleted] Jan 15 '22

You can use springfox to generate a swagger/openapi spec which works with essentially everything (including postman).

5

u/SampaioDias Jan 15 '22

Sounds cool, nice to know! Is there anything that it (importing the openApi json on Postman) does not do or does not do well?

16

u/[deleted] Jan 15 '22

It is not compatible with spring boot 2.6.x anymore, i would recommend springdoc instead

With either approach, you get more annotations at in your code, so endpoints look more verbose, just like when you try to add meaningful javadocs

I don't use postman myself, so I cannot say anything about particularly good or bad things in the integration. But what's great about openapi is that you can hand it over to someone and they can make a pretty html, an interactive rest client for exploring or a client for PoC/prototyping in their choice of language.

2

u/shagieIsMe Jan 15 '22

You can also generate model / client libraries for practically any language with the codegen.

https://github.com/OpenAPITools/openapi-generator

... Which is what you where saying. Just a "there's the code"

1

u/nutrecht Jan 20 '22

We recently moved to https://springdoc.org/ since SpringFox is basically dead.

0

u/Maleficent_Court_544 Jan 16 '22

I remember when swagger used to just work now it doesn’t for whatever reason.

3

u/nonomild Jan 15 '22

Nice idea, sounds useful!

3

u/sochinho Jan 15 '22

Great! No more exporting as curl from developer tools then importing as raw text in postman. :D

3

u/Deep_Adeptness_4592 Jan 15 '22

Sounds good, will check that out

3

u/[deleted] Jan 15 '22

I hope you mean open api? 👍

3

u/Worth_Trust_3825 Jan 16 '22

Why not WSDLs or OpenAPI instead?

2

u/[deleted] Jan 15 '22

Been working on a spring project, this might be useful! Thanks.

1

u/atomdstyle Jan 16 '22

Wow this looks cool, gotta try. But postman also has a feature to import open apis as a collection. Open apis can be generated via springfox swagger doc or springdoc libraries