We already have a minimal REST API that says Hello World! in our demo application. In this page we will enrich the API with some SeedStack

A Swagger descriptor

Swagger is a popular API description format. It helps in discovering API, whereas by humans or by machines.

To add a Swagger descriptor to our project, we just need to add the following dependency:

Show version
dependencies {

To see the Swagger descriptor, restart the application and point your browser to


You should see an empty Swagger descriptor. That’s because we haven’t declared any REST resource as a discoverable API. Now annotate the HelloResource class with @Api:


import javax.inject.Inject;
import org.generated.project.domain.model.person.PersonRepository;

public class HelloResource {
    private PersonRepository personRepository;
    private GreeterService greeterService;

    public String hello() {
        return personRepository.findByName("ella")

The JSON descriptor should now contain the basic information on the /hello API. If we want something more human-friendly, we can display the descriptor inside the Swagger demo UI.

On the Swagger UI, enter the application Swagger descriptor URL in the top field and press «Explore».

For now, you should see a failure due to the descriptor being loaded from a different origin (localhost) than the displayed page ( We will fix that by enabling Cross-Origin Resource Sharing (CORS) on our app.

Enable CORS

To enable CORS, just add the following configuration at the bottom of the application.yaml file:

    cors: true

Learn more about CORS options on the CORS documentation page.

See the result

Now refresh the browser page. You should see a human-friendly version of the Swagger descriptor.

If you click on the /hello API, you can try it out directly from this UI.

Now what ?

What we learned

In this page you have learned:

  • How to add a Swagger descriptor for your REST API,
  • How to enable CORS to make your REST API available from other origins.


If you can’t get this to work, check the troubleshooting page.

Next step

If you want to learn more, continue on the tutorial to learn about testing.


On this page