1818 */
1919public final class APIKeySecurityScheme implements SecurityScheme {
2020
21+ /** The security scheme type identifier for API key authentication. */
2122 public static final String API_KEY = "apiKey" ;
2223 private final Location location ;
2324 private final String name ;
@@ -28,8 +29,13 @@ public final class APIKeySecurityScheme implements SecurityScheme {
2829 * Represents the location of the API key.
2930 */
3031 public enum Location {
32+ /** API key sent in a cookie. */
3133 COOKIE ("cookie" ),
34+
35+ /** API key sent in an HTTP header. */
3236 HEADER ("header" ),
37+
38+ /** API key sent as a query parameter. */
3339 QUERY ("query" );
3440
3541 private final String location ;
@@ -38,10 +44,22 @@ public enum Location {
3844 this .location = location ;
3945 }
4046
47+ /**
48+ * Converts this location to its string representation.
49+ *
50+ * @return the string representation of this location
51+ */
4152 public String asString () {
4253 return location ;
4354 }
4455
56+ /**
57+ * Converts a string to a Location enum value.
58+ *
59+ * @param location the string location ("cookie", "header", or "query")
60+ * @return the corresponding Location enum value
61+ * @throws IllegalArgumentException if the location string is invalid
62+ */
4563 public static Location fromString (String location ) {
4664 switch (location ) {
4765 case "cookie" -> {
@@ -58,10 +76,27 @@ public static Location fromString(String location) {
5876 }
5977 }
6078
79+ /**
80+ * Creates a new APIKeySecurityScheme with the specified location, name, and description.
81+ *
82+ * @param location the location where the API key is sent (required)
83+ * @param name the name of the API key parameter (required)
84+ * @param description a human-readable description (optional)
85+ * @throws IllegalArgumentException if location or name is null
86+ */
6187 public APIKeySecurityScheme (Location location , String name , String description ) {
6288 this (location , name , description , API_KEY );
6389 }
6490
91+ /**
92+ * Creates a new APIKeySecurityScheme with explicit type specification.
93+ *
94+ * @param location the location where the API key is sent (required)
95+ * @param name the name of the API key parameter (required)
96+ * @param description a human-readable description (optional)
97+ * @param type the security scheme type (must be "apiKey")
98+ * @throws IllegalArgumentException if location, name, or type is null, or if type is not "apiKey"
99+ */
65100 public APIKeySecurityScheme (Location location , String name ,
66101 String description , String type ) {
67102 Assert .checkNotNullParam ("location" , location );
@@ -76,43 +111,99 @@ public APIKeySecurityScheme(Location location, String name,
76111 this .type = type ;
77112 }
78113
114+ /**
115+ * Gets the human-readable description of this security scheme.
116+ *
117+ * @return the description, or null if not provided
118+ */
79119 @ Override
80120 public String getDescription () {
81121 return description ;
82122 }
83123
124+ /**
125+ * Gets the location where the API key is sent.
126+ *
127+ * @return the API key location
128+ */
84129 public Location getLocation () {
85130 return location ;
86131 }
87132
133+ /**
134+ * Gets the name of the API key parameter.
135+ *
136+ * @return the parameter name
137+ */
88138 public String getName () {
89139 return name ;
90140 }
91141
142+ /**
143+ * Gets the security scheme type.
144+ *
145+ * @return always returns "apiKey"
146+ */
92147 public String getType () {
93148 return type ;
94149 }
95150
151+ /**
152+ * Builder for constructing immutable {@link APIKeySecurityScheme} instances.
153+ * <p>
154+ * Example usage:
155+ * <pre>{@code
156+ * APIKeySecurityScheme scheme = new APIKeySecurityScheme.Builder()
157+ * .location(Location.HEADER)
158+ * .name("X-API-Key")
159+ * .description("API key authentication")
160+ * .build();
161+ * }</pre>
162+ */
96163 public static class Builder {
97164 private Location location ;
98165 private String name ;
99166 private String description ;
100167
168+ /**
169+ * Sets the location where the API key should be sent.
170+ *
171+ * @param location the API key location (header, query, or cookie) (required)
172+ * @return this builder for method chaining
173+ */
101174 public Builder location (Location location ) {
102175 this .location = location ;
103176 return this ;
104177 }
105178
179+ /**
180+ * Sets the name of the API key parameter.
181+ *
182+ * @param name the parameter name (required)
183+ * @return this builder for method chaining
184+ */
106185 public Builder name (String name ) {
107186 this .name = name ;
108187 return this ;
109188 }
110189
190+ /**
191+ * Sets the human-readable description of the security scheme.
192+ *
193+ * @param description the description (optional)
194+ * @return this builder for method chaining
195+ */
111196 public Builder description (String description ) {
112197 this .description = description ;
113198 return this ;
114199 }
115200
201+ /**
202+ * Builds a new immutable {@link APIKeySecurityScheme} from the current builder state.
203+ *
204+ * @return a new APIKeySecurityScheme instance
205+ * @throws IllegalArgumentException if location or name is null
206+ */
116207 public APIKeySecurityScheme build () {
117208 return new APIKeySecurityScheme (location , name , description );
118209 }
0 commit comments