Skip to content

Commit 307ef62

Browse files
authored
Add comments to production code (#10)
* Add comments to production code * Fix lint issues
1 parent fd68011 commit 307ef62

File tree

13 files changed

+124
-0
lines changed

13 files changed

+124
-0
lines changed

src/main/kotlin/io/opengood/autoconfig/openapidocs/Functions.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@ import io.swagger.v3.oas.models.Operation
44
import io.swagger.v3.oas.models.PathItem
55
import io.swagger.v3.oas.models.Paths
66

7+
/**
8+
* Creates a Paths object from a list of path strings.
9+
*
10+
* This function takes a list of path strings and converts them into a Paths object
11+
* that can be used in OpenAPI documentation. Each path is added as a PathItem with
12+
* a GET operation.
13+
*
14+
* @param list List of path strings to convert
15+
* @return Paths object containing all the paths from the list
16+
*/
717
internal fun getPaths(list: List<String>): Paths {
818
val paths = Paths()
919
list.forEach { paths.addPathItem(it, PathItem().get(Operation())) }

src/main/kotlin/io/opengood/autoconfig/openapidocs/OpenApiDocsAutoConfiguration.kt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,28 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
1414
import org.springframework.boot.context.properties.EnableConfigurationProperties
1515
import org.springframework.context.annotation.Bean
1616

17+
/**
18+
* Spring Boot auto-configuration class for OpenAPI documentation.
19+
*
20+
* This class automatically configures OpenAPI documentation for a Spring Boot application
21+
* based on the properties defined in OpenApiDocsProperties. It is enabled when the
22+
* "openapi-docs.enabled" property is set to "true".
23+
*/
1724
@AutoConfiguration
1825
@ConditionalOnProperty("openapi-docs.enabled", havingValue = "true")
1926
@EnableConfigurationProperties(value = [OpenApiDocsProperties::class])
2027
class OpenApiDocsAutoConfiguration(
2128
private val properties: OpenApiDocsProperties,
2229
) {
30+
/**
31+
* Creates and configures an OpenAPI bean based on the provided properties.
32+
*
33+
* This method sets up the OpenAPI documentation with information about the API,
34+
* including title, description, version, contact information, license, and security
35+
* settings if enabled.
36+
*
37+
* @return Configured OpenAPI instance
38+
*/
2339
@Bean
2440
fun openApi(): OpenAPI {
2541
log.info("Setup OpenAPI docs configuration")
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,21 @@
11
package io.opengood.autoconfig.openapidocs.enumeration
22

3+
/**
4+
* Enumeration of bearer token formats for OpenAPI security schemes.
5+
*
6+
* This enum defines the supported bearer token formats that can be used
7+
* in OpenAPI security schemes, such as JWT.
8+
*/
39
enum class BearerFormat(
410
private val value: String,
511
) {
612
JWT("JWT"),
713
;
814

15+
/**
16+
* Returns the string representation of the bearer format.
17+
*
18+
* @return String value of the bearer format
19+
*/
920
override fun toString() = value
1021
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,22 @@
11
package io.opengood.autoconfig.openapidocs.enumeration
22

3+
/**
4+
* Enumeration of OAuth2 grant types for OpenAPI security schemes.
5+
*
6+
* This enum defines the supported OAuth2 grant types that can be used
7+
* in OpenAPI security schemes, such as authorization code and client credentials.
8+
*/
39
enum class Oauth2GrantType(
410
private val value: String,
511
) {
612
AUTHORIZATION_CODE("authorizationCode"),
713
CLIENT_CREDENTIALS("clientCredentials"),
814
;
915

16+
/**
17+
* Returns the string representation of the OAuth2 grant type.
18+
*
19+
* @return String value of the OAuth2 grant type
20+
*/
1021
override fun toString() = value
1122
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,22 @@
11
package io.opengood.autoconfig.openapidocs.enumeration
22

3+
/**
4+
* Enumeration of security schemes for OpenAPI security definitions.
5+
*
6+
* This enum defines the supported security schemes that can be used
7+
* in OpenAPI security definitions, such as basic and bearer authentication.
8+
*/
39
enum class Scheme(
410
private val value: String,
511
) {
612
BASIC("basic"),
713
BEARER("bearer"),
814
;
915

16+
/**
17+
* Returns the string representation of the security scheme.
18+
*
19+
* @return String value of the security scheme
20+
*/
1021
override fun toString() = value
1122
}

src/main/kotlin/io/opengood/autoconfig/openapidocs/enumeration/Type.kt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,34 @@ package io.opengood.autoconfig.openapidocs.enumeration
33
import io.swagger.v3.oas.models.security.SecurityScheme
44
import java.util.Locale
55

6+
/**
7+
* Enumeration of security types for OpenAPI security schemes.
8+
*
9+
* This enum defines the supported security types that can be used
10+
* in OpenAPI security schemes, such as API key and HTTP authentication.
11+
* It provides conversion to the corresponding SecurityScheme.Type enum.
12+
*/
613
enum class Type(
714
private val value: String,
815
) {
916
APIKEY("apikey"),
1017
HTTP("http"),
1118
;
1219

20+
/**
21+
* Returns the string representation of the security type.
22+
*
23+
* @return String value of the security type
24+
*/
1325
override fun toString() = value
1426

27+
/**
28+
* Converts this Type enum to the corresponding SecurityScheme.Type enum.
29+
*
30+
* This method converts the string value of this enum to uppercase and
31+
* uses it to find the corresponding value in the SecurityScheme.Type enum.
32+
*
33+
* @return The corresponding SecurityScheme.Type enum value
34+
*/
1535
fun toEnum() = enumValueOf<SecurityScheme.Type>(value.uppercase(Locale.getDefault()))
1636
}

src/main/kotlin/io/opengood/autoconfig/openapidocs/property/ContactProperty.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
package io.opengood.autoconfig.openapidocs.property
22

3+
/**
4+
* Configuration properties for contact information in OpenAPI documentation.
5+
*
6+
* This class defines the properties for contact information that will be displayed
7+
* in the OpenAPI documentation, including name, URL, and email address.
8+
*/
39
data class ContactProperty(
410
val name: String = "",
511
val url: String = "",

src/main/kotlin/io/opengood/autoconfig/openapidocs/property/LicenseProperty.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
package io.opengood.autoconfig.openapidocs.property
22

3+
/**
4+
* Configuration properties for license information in OpenAPI documentation.
5+
*
6+
* This class defines the properties for license information that will be displayed
7+
* in the OpenAPI documentation, including license name and URL.
8+
*/
39
data class LicenseProperty(
410
val name: String = "",
511
val url: String = "",
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
package io.opengood.autoconfig.openapidocs.property
22

3+
/**
4+
* Configuration properties for OAuth2 client settings in OpenAPI documentation.
5+
*
6+
* This class defines the properties for OAuth2 client settings that will be used
7+
* in the OpenAPI documentation, including the scopes that the client can request.
8+
*/
39
data class Oauth2ClientProperty(
410
val scopes: Map<String, String> = HashMap(),
511
)

src/main/kotlin/io/opengood/autoconfig/openapidocs/property/Oauth2Property.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@ package io.opengood.autoconfig.openapidocs.property
22

33
import io.opengood.autoconfig.openapidocs.enumeration.Oauth2GrantType
44

5+
/**
6+
* Configuration properties for OAuth2 settings in OpenAPI documentation.
7+
*
8+
* This class defines the properties for OAuth2 settings that will be used
9+
* in the OpenAPI documentation, including grant type, resource configuration,
10+
* client configuration, and token URI.
11+
*/
512
data class Oauth2Property(
613
val grantType: Oauth2GrantType = Oauth2GrantType.AUTHORIZATION_CODE,
714
val resource: Oauth2ResourceProperty = Oauth2ResourceProperty(),

0 commit comments

Comments
 (0)