How it works...

It's all based on annotations. The main ones are those applied to the ContactApplication class because whatever is documented here will be the root of the API documentation. Let's check these annotations more closely:

@OpenAPIDefinition(info = @Info(
title = "Chapter 08 MicroProfile OpenAPI",
version = "1.0.0",
contact = @Contact(
name = "Elder Moraes",
email = "[email protected]",
url = "https://eldermoraes.com")
),
servers = {
@Server(url = "/ch08mpopenapi", description = "localhost")
}
)

Note that we are just analyzing the OpenAPI annotations. These classes have other annotations, but they refer to other features.

The @OpenAPIDefinition annotation has under it all of the global information that you can provide about this API.

Now, let's check the documentation given to the ContactResource class:

@Tag(name = "Contact API service", description = "Methods for Contact management")

The @Tag annotation will host general information about this service. Let's check the methods:

    @APIResponse(responseCode = "200",
description = "Contact list response",
name = "ContactListResponse"
)

Here, the @APIResponse annotation gives information about the response given by the method. 

If your method has some parameter, you just add something like this:

    @Parameter(name = "id",
description = "Contact Id",
required = true,
allowEmptyValue = false
)

So, no more guessing about how a service works: just inform it!

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.44.23