Skip to content

Commit d9057c7

Browse files
NIFI-14144 Fixed status code and content for success in OpenAPI spec (#9629)
Signed-off-by: David Handermann <[email protected]>
1 parent eb118a8 commit d9057c7

39 files changed

+2398
-3145
lines changed

nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/AccessPolicyResource.java

+28-39
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,11 @@
1616
*/
1717
package org.apache.nifi.web.api;
1818

19-
import java.net.URI;
20-
2119
import io.swagger.v3.oas.annotations.Operation;
2220
import io.swagger.v3.oas.annotations.Parameter;
2321
import io.swagger.v3.oas.annotations.media.Content;
2422
import io.swagger.v3.oas.annotations.media.Schema;
2523
import io.swagger.v3.oas.annotations.responses.ApiResponse;
26-
import io.swagger.v3.oas.annotations.responses.ApiResponses;
2724
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
2825
import io.swagger.v3.oas.annotations.tags.Tag;
2926
import jakarta.ws.rs.Consumes;
@@ -60,6 +57,8 @@
6057
import org.springframework.beans.factory.annotation.Autowired;
6158
import org.springframework.stereotype.Controller;
6259

60+
import java.net.URI;
61+
6362
/**
6463
* RESTful endpoint for managing access policies.
6564
*/
@@ -120,18 +119,16 @@ public AccessPolicyEntity populateRemainingAccessPolicyEntityContent(AccessPolic
120119
+ "have permissions to that policy, the response will not include the policy and the permissions in the response "
121120
+ "will be marked accordingly. If the client does not have permissions to the policy of the desired action and resource "
122121
+ "a 403 response will be returned.",
123-
responses = @ApiResponse(content = @Content(schema = @Schema(implementation = AccessPolicyEntity.class))),
124-
security = {
125-
@SecurityRequirement(name = "Read - /policies/{resource}")
126-
}
127-
)
128-
@ApiResponses(
129-
value = {
122+
responses = {
123+
@ApiResponse(responseCode = "200", content = @Content(schema = @Schema(implementation = AccessPolicyEntity.class))),
130124
@ApiResponse(responseCode = "400", description = "NiFi was unable to complete the request because it was invalid. The request should not be retried without modification."),
131125
@ApiResponse(responseCode = "401", description = "Client could not be authenticated."),
132126
@ApiResponse(responseCode = "403", description = "Client is not authorized to make this request."),
133127
@ApiResponse(responseCode = "404", description = "The specified resource could not be found."),
134128
@ApiResponse(responseCode = "409", description = "The request was valid but NiFi was not in the appropriate state to process it.")
129+
},
130+
security = {
131+
@SecurityRequirement(name = "Read - /policies/{resource}")
135132
}
136133
)
137134
public Response getAccessPolicyForResource(
@@ -187,18 +184,16 @@ public Response getAccessPolicyForResource(
187184
@Produces(MediaType.APPLICATION_JSON)
188185
@Operation(
189186
summary = "Creates an access policy",
190-
responses = @ApiResponse(content = @Content(schema = @Schema(implementation = AccessPolicyEntity.class))),
191-
security = {
192-
@SecurityRequirement(name = "Write - /policies/{resource}")
193-
}
194-
)
195-
@ApiResponses(
196-
value = {
187+
responses = {
188+
@ApiResponse(responseCode = "201", content = @Content(schema = @Schema(implementation = AccessPolicyEntity.class))),
197189
@ApiResponse(responseCode = "400", description = "NiFi was unable to complete the request because it was invalid. The request should not be retried without modification."),
198190
@ApiResponse(responseCode = "401", description = "Client could not be authenticated."),
199191
@ApiResponse(responseCode = "403", description = "Client is not authorized to make this request."),
200192
@ApiResponse(responseCode = "404", description = "The specified resource could not be found."),
201193
@ApiResponse(responseCode = "409", description = "The request was valid but NiFi was not in the appropriate state to process it.")
194+
},
195+
security = {
196+
@SecurityRequirement(name = "Write - /policies/{resource}")
202197
}
203198
)
204199
public Response createAccessPolicy(
@@ -279,18 +274,16 @@ public Response createAccessPolicy(
279274
@Path("{id}")
280275
@Operation(
281276
summary = "Gets an access policy",
282-
responses = @ApiResponse(content = @Content(schema = @Schema(implementation = AccessPolicyEntity.class))),
283-
security = {
284-
@SecurityRequirement(name = "Read - /policies/{resource}")
285-
}
286-
)
287-
@ApiResponses(
288-
value = {
277+
responses = {
278+
@ApiResponse(responseCode = "200", content = @Content(schema = @Schema(implementation = AccessPolicyEntity.class))),
289279
@ApiResponse(responseCode = "400", description = "NiFi was unable to complete the request because it was invalid. The request should not be retried without modification."),
290280
@ApiResponse(responseCode = "401", description = "Client could not be authenticated."),
291281
@ApiResponse(responseCode = "403", description = "Client is not authorized to make this request."),
292282
@ApiResponse(responseCode = "404", description = "The specified resource could not be found."),
293283
@ApiResponse(responseCode = "409", description = "The request was valid but NiFi was not in the appropriate state to process it.")
284+
},
285+
security = {
286+
@SecurityRequirement(name = "Read - /policies/{resource}")
294287
}
295288
)
296289
public Response getAccessPolicy(
@@ -335,18 +328,16 @@ public Response getAccessPolicy(
335328
@Path("{id}")
336329
@Operation(
337330
summary = "Updates a access policy",
338-
responses = @ApiResponse(content = @Content(schema = @Schema(implementation = AccessPolicyEntity.class))),
339-
security = {
340-
@SecurityRequirement(name = "Write - /policies/{resource}")
341-
}
342-
)
343-
@ApiResponses(
344-
value = {
331+
responses = {
332+
@ApiResponse(responseCode = "200", content = @Content(schema = @Schema(implementation = AccessPolicyEntity.class))),
345333
@ApiResponse(responseCode = "400", description = "NiFi was unable to complete the request because it was invalid. The request should not be retried without modification."),
346334
@ApiResponse(responseCode = "401", description = "Client could not be authenticated."),
347335
@ApiResponse(responseCode = "403", description = "Client is not authorized to make this request."),
348336
@ApiResponse(responseCode = "404", description = "The specified resource could not be found."),
349337
@ApiResponse(responseCode = "409", description = "The request was valid but NiFi was not in the appropriate state to process it.")
338+
},
339+
security = {
340+
@SecurityRequirement(name = "Write - /policies/{resource}")
350341
}
351342
)
352343
public Response updateAccessPolicy(
@@ -426,19 +417,17 @@ public Response updateAccessPolicy(
426417
@Path("{id}")
427418
@Operation(
428419
summary = "Deletes an access policy",
429-
responses = @ApiResponse(content = @Content(schema = @Schema(implementation = AccessPolicyEntity.class))),
430-
security = {
431-
@SecurityRequirement(name = "Write - /policies/{resource}"),
432-
@SecurityRequirement(name = "Write - Policy of the parent resource - /policies/{resource}")
433-
}
434-
)
435-
@ApiResponses(
436-
value = {
420+
responses = {
421+
@ApiResponse(responseCode = "200", content = @Content(schema = @Schema(implementation = AccessPolicyEntity.class))),
437422
@ApiResponse(responseCode = "400", description = "NiFi was unable to complete the request because it was invalid. The request should not be retried without modification."),
438423
@ApiResponse(responseCode = "401", description = "Client could not be authenticated."),
439424
@ApiResponse(responseCode = "403", description = "Client is not authorized to make this request."),
440425
@ApiResponse(responseCode = "404", description = "The specified resource could not be found."),
441426
@ApiResponse(responseCode = "409", description = "The request was valid but NiFi was not in the appropriate state to process it.")
427+
},
428+
security = {
429+
@SecurityRequirement(name = "Write - /policies/{resource}"),
430+
@SecurityRequirement(name = "Write - Policy of the parent resource - /policies/{resource}")
442431
}
443432
)
444433
public Response removeAccessPolicy(

nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/AccessResource.java

+13-20
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,10 @@
1616
*/
1717
package org.apache.nifi.web.api;
1818

19-
import java.net.URI;
20-
import java.time.Instant;
21-
import java.util.Collections;
22-
import java.util.Optional;
23-
import java.util.UUID;
24-
2519
import io.swagger.v3.oas.annotations.Operation;
2620
import io.swagger.v3.oas.annotations.media.Content;
2721
import io.swagger.v3.oas.annotations.media.Schema;
2822
import io.swagger.v3.oas.annotations.responses.ApiResponse;
29-
import io.swagger.v3.oas.annotations.responses.ApiResponses;
3023
import io.swagger.v3.oas.annotations.tags.Tag;
3124
import jakarta.servlet.http.HttpServletRequest;
3225
import jakarta.servlet.http.HttpServletResponse;
@@ -63,6 +56,12 @@
6356
import org.springframework.security.oauth2.server.resource.web.BearerTokenResolver;
6457
import org.springframework.stereotype.Controller;
6558

59+
import java.net.URI;
60+
import java.time.Instant;
61+
import java.util.Collections;
62+
import java.util.Optional;
63+
import java.util.UUID;
64+
6665
/**
6766
* RESTful endpoint for managing access.
6867
*/
@@ -97,10 +96,8 @@ public class AccessResource extends ApplicationResource {
9796
description = "The token returned is formatted as a JSON Web Token (JWT). The token is base64 encoded and comprised of three parts. The header, " +
9897
"the body, and the signature. The expiration of the token is a contained within the body. It is stored in the browser as a cookie, but also returned in" +
9998
"the response body to be stored/used by third party client scripts.",
100-
responses = @ApiResponse(content = @Content(schema = @Schema(implementation = String.class)))
101-
)
102-
@ApiResponses(
103-
value = {
99+
responses = {
100+
@ApiResponse(responseCode = "201", content = @Content(schema = @Schema(implementation = String.class))),
104101
@ApiResponse(responseCode = "400", description = "NiFi was unable to complete the request because it was invalid. The request should not be retried without modification."),
105102
@ApiResponse(responseCode = "403", description = "Client is not authorized to make this request."),
106103
@ApiResponse(responseCode = "409", description = "The request was valid but NiFi was not in the appropriate state to process it."),
@@ -158,10 +155,8 @@ public Response createAccessToken(
158155
@Path("/logout")
159156
@Operation(
160157
summary = "Performs a logout for other providers that have been issued a JWT.",
161-
description = NON_GUARANTEED_ENDPOINT
162-
)
163-
@ApiResponses(
164-
value = {
158+
description = NON_GUARANTEED_ENDPOINT,
159+
responses = {
165160
@ApiResponse(responseCode = "200", description = "User was logged out successfully."),
166161
@ApiResponse(responseCode = "401", description = "Authentication token provided was empty or not in the correct JWT format."),
167162
@ApiResponse(responseCode = "500", description = "Client failed to log out."),
@@ -204,11 +199,9 @@ public Response logOut(@Context HttpServletRequest httpServletRequest, @Context
204199
@Path("/logout/complete")
205200
@Operation(
206201
summary = "Completes the logout sequence by removing the cached Logout Request and Cookie if they existed and redirects to /nifi/login.",
207-
description = NON_GUARANTEED_ENDPOINT
208-
)
209-
@ApiResponses(
210-
value = {
211-
@ApiResponse(responseCode = "200", description = "User was logged out successfully."),
202+
description = NON_GUARANTEED_ENDPOINT,
203+
responses = {
204+
@ApiResponse(responseCode = "302", description = "User was logged out successfully."),
212205
@ApiResponse(responseCode = "401", description = "Authentication token provided was empty or not in the correct JWT format."),
213206
@ApiResponse(responseCode = "500", description = "Client failed to log out."),
214207
}

nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/ConnectionResource.java

+24-31
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,11 @@
1616
*/
1717
package org.apache.nifi.web.api;
1818

19-
import java.util.List;
20-
import java.util.Set;
21-
2219
import io.swagger.v3.oas.annotations.Operation;
2320
import io.swagger.v3.oas.annotations.Parameter;
2421
import io.swagger.v3.oas.annotations.media.Content;
2522
import io.swagger.v3.oas.annotations.media.Schema;
2623
import io.swagger.v3.oas.annotations.responses.ApiResponse;
27-
import io.swagger.v3.oas.annotations.responses.ApiResponses;
2824
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
2925
import io.swagger.v3.oas.annotations.tags.Tag;
3026
import jakarta.ws.rs.Consumes;
@@ -57,6 +53,9 @@
5753
import org.springframework.beans.factory.annotation.Autowired;
5854
import org.springframework.stereotype.Controller;
5955

56+
import java.util.List;
57+
import java.util.Set;
58+
6059
/**
6160
* RESTful endpoint for managing a Connection.
6261
*/
@@ -105,19 +104,17 @@ public ConnectionEntity populateRemainingConnectionEntityContent(ConnectionEntit
105104
@Path("/{id}")
106105
@Operation(
107106
summary = "Gets a connection",
108-
responses = @ApiResponse(content = @Content(schema = @Schema(implementation = ConnectionEntity.class))),
109-
security = {
110-
@SecurityRequirement(name = "Read Source - /{component-type}/{uuid}"),
111-
@SecurityRequirement(name = "Read Destination - /{component-type}/{uuid}")
112-
}
113-
)
114-
@ApiResponses(
115-
value = {
107+
responses = {
108+
@ApiResponse(responseCode = "200", content = @Content(schema = @Schema(implementation = ConnectionEntity.class))),
116109
@ApiResponse(responseCode = "400", description = "NiFi was unable to complete the request because it was invalid. The request should not be retried without modification."),
117110
@ApiResponse(responseCode = "401", description = "Client could not be authenticated."),
118111
@ApiResponse(responseCode = "403", description = "Client is not authorized to make this request."),
119112
@ApiResponse(responseCode = "404", description = "The specified resource could not be found."),
120113
@ApiResponse(responseCode = "409", description = "The request was valid but NiFi was not in the appropriate state to process it.")
114+
},
115+
security = {
116+
@SecurityRequirement(name = "Read Source - /{component-type}/{uuid}"),
117+
@SecurityRequirement(name = "Read Destination - /{component-type}/{uuid}")
121118
}
122119
)
123120
public Response getConnection(
@@ -160,21 +157,19 @@ public Response getConnection(
160157
@Path("/{id}")
161158
@Operation(
162159
summary = "Updates a connection",
163-
responses = @ApiResponse(content = @Content(schema = @Schema(implementation = ConnectionEntity.class))),
164-
security = {
165-
@SecurityRequirement(name = "Write Source - /{component-type}/{uuid}"),
166-
@SecurityRequirement(name = "Write Destination - /{component-type}/{uuid}"),
167-
@SecurityRequirement(name = "Write New Destination - /{component-type}/{uuid} - if updating Destination"),
168-
@SecurityRequirement(name = "Write Process Group - /process-groups/{uuid} - if updating Destination")
169-
}
170-
)
171-
@ApiResponses(
172-
value = {
160+
responses = {
161+
@ApiResponse(responseCode = "200", content = @Content(schema = @Schema(implementation = ConnectionEntity.class))),
173162
@ApiResponse(responseCode = "400", description = "NiFi was unable to complete the request because it was invalid. The request should not be retried without modification."),
174163
@ApiResponse(responseCode = "401", description = "Client could not be authenticated."),
175164
@ApiResponse(responseCode = "403", description = "Client is not authorized to make this request."),
176165
@ApiResponse(responseCode = "404", description = "The specified resource could not be found."),
177166
@ApiResponse(responseCode = "409", description = "The request was valid but NiFi was not in the appropriate state to process it.")
167+
},
168+
security = {
169+
@SecurityRequirement(name = "Write Source - /{component-type}/{uuid}"),
170+
@SecurityRequirement(name = "Write Destination - /{component-type}/{uuid}"),
171+
@SecurityRequirement(name = "Write New Destination - /{component-type}/{uuid} - if updating Destination"),
172+
@SecurityRequirement(name = "Write Process Group - /process-groups/{uuid} - if updating Destination")
178173
}
179174
)
180175
public Response updateConnection(
@@ -291,20 +286,18 @@ public Response updateConnection(
291286
@Path("/{id}")
292287
@Operation(
293288
summary = "Deletes a connection",
294-
responses = @ApiResponse(content = @Content(schema = @Schema(implementation = ConnectionEntity.class))),
295-
security = {
296-
@SecurityRequirement(name = "Write Source - /{component-type}/{uuid}"),
297-
@SecurityRequirement(name = "Write - Parent Process Group - /process-groups/{uuid}"),
298-
@SecurityRequirement(name = "Write Destination - /{component-type}/{uuid}")
299-
}
300-
)
301-
@ApiResponses(
302-
value = {
289+
responses = {
290+
@ApiResponse(responseCode = "200", content = @Content(schema = @Schema(implementation = ConnectionEntity.class))),
303291
@ApiResponse(responseCode = "400", description = "NiFi was unable to complete the request because it was invalid. The request should not be retried without modification."),
304292
@ApiResponse(responseCode = "401", description = "Client could not be authenticated."),
305293
@ApiResponse(responseCode = "403", description = "Client is not authorized to make this request."),
306294
@ApiResponse(responseCode = "404", description = "The specified resource could not be found."),
307295
@ApiResponse(responseCode = "409", description = "The request was valid but NiFi was not in the appropriate state to process it.")
296+
},
297+
security = {
298+
@SecurityRequirement(name = "Write Source - /{component-type}/{uuid}"),
299+
@SecurityRequirement(name = "Write - Parent Process Group - /process-groups/{uuid}"),
300+
@SecurityRequirement(name = "Write Destination - /{component-type}/{uuid}")
308301
}
309302
)
310303
public Response deleteConnection(

0 commit comments

Comments
 (0)