Skip to content

Commit 4f03e4f

Browse files
committed
Fix test case
# Conflicts: # modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaJAXRSSpecServerCodegen.java # modules/openapi-generator/src/main/resources/JavaJaxRS/spec/libraries/quarkus/apiInterface.mustache # modules/openapi-generator/src/test/java/org/openapitools/codegen/java/jaxrs/JavaJAXRSSpecServerCodegenTest.java
1 parent af3dd8c commit 4f03e4f

9 files changed

Lines changed: 801 additions & 0 deletions

File tree

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaJAXRSSpecServerCodegen.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,13 @@ public OperationsMap postProcessOperationsWithModels(OperationsMap objs, List<Mo
360360
additionalProperties.put("hasResponseStatusAnnotations", true);
361361
}
362362
}
363+
if (QUARKUS_LIBRARY.equals(getLibrary())) {
364+
for (CodegenOperation op : objs.getOperations().getOperation()) {
365+
if (shouldAddAuthenticatedAnnotation(op)){
366+
op.vendorExtensions.put("x-quarkus-authenticated", true);
367+
}
368+
}
369+
}
363370
return objs;
364371
}
365372

@@ -384,4 +391,16 @@ public Map<String, ModelsMap> postProcessAllModels(Map<String, ModelsMap> objs)
384391
}
385392
return result;
386393
}
394+
395+
protected boolean shouldAddAuthenticatedAnnotation(CodegenOperation op) {
396+
if (!op.hasAuthMethods) {
397+
return false;
398+
}
399+
return op.authMethods.stream().anyMatch(m ->
400+
(Boolean.TRUE.equals(m.isOAuth) && (m.scopes == null || m.scopes.isEmpty())) ||
401+
(Boolean.TRUE.equals(m.isOpenId) && (m.scopes == null || m.scopes.isEmpty())) ||
402+
Boolean.TRUE.equals(m.isBasicBasic) ||
403+
Boolean.TRUE.equals(m.isApiKey)
404+
);
405+
}
387406
}

modules/openapi-generator/src/main/resources/JavaJaxRS/spec/libraries/quarkus/apiInterface.mustache

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,7 @@
5353
{{#vendorExtensions.x-java-success-response-code}}
5454
@ResponseStatus({{{vendorExtensions.x-java-success-response-code}}})
5555
{{/vendorExtensions.x-java-success-response-code}}
56+
{{#vendorExtensions.x-quarkus-authenticated}}
57+
@io.quarkus.security.Authenticated
58+
{{/vendorExtensions.x-quarkus-authenticated}}
5659
{{#supportAsync}}{{>returnAsyncTypeInterface}}{{/supportAsync}}{{^supportAsync}}{{#returnJBossResponse}}{{>returnResponseTypeInterface}}{{/returnJBossResponse}}{{^returnJBossResponse}}{{#returnResponse}}Response{{/returnResponse}}{{^returnResponse}}{{>returnTypeInterface}}{{/returnResponse}}{{/returnJBossResponse}}{{/supportAsync}} {{nickname}}({{#allParams}}{{>queryParams}}{{>pathParams}}{{>cookieParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}}{{^-last}},{{/-last}}{{/allParams}});

modules/openapi-generator/src/main/resources/JavaJaxRS/spec/libraries/quarkus/apiMethod.mustache

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@
4747
{{^vendorExtensions.x-java-is-response-void}}@org.eclipse.microprofile.openapi.annotations.media.Content(schema = @org.eclipse.microprofile.openapi.annotations.media.Schema(implementation = {{{baseType}}}.class{{#vendorExtensions.x-microprofile-open-api-return-schema-container}}, type = {{{.}}} {{/vendorExtensions.x-microprofile-open-api-return-schema-container}}{{#vendorExtensions.x-microprofile-open-api-return-unique-items}}, uniqueItems = true {{/vendorExtensions.x-microprofile-open-api-return-unique-items}})){{/vendorExtensions.x-java-is-response-void}}
4848
}){{^-last}},{{/-last}}{{/responses}}
4949
}){{/hasProduces}}{{/useMicroProfileOpenAPIAnnotations}}
50+
{{#vendorExtensions.x-quarkus-authenticated}}
51+
@io.quarkus.security.Authenticated
52+
{{/vendorExtensions.x-quarkus-authenticated}}
5053
public {{#supportAsync}}{{#useMutiny}}Uni{{/useMutiny}}{{^useMutiny}}CompletionStage{{/useMutiny}}<{{/supportAsync}}{{#returnJBossResponse}}{{>returnResponseTypeInterface}}{{/returnJBossResponse}}{{^returnJBossResponse}}Response{{/returnJBossResponse}}{{#supportAsync}}>{{/supportAsync}} {{nickname}}({{#allParams}}{{>queryParams}}{{>pathParams}}{{>cookieParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}}{{^-last}},{{/-last}}{{/allParams}}) {
5154
return {{#supportAsync}}{{#useMutiny}}Uni.createFrom().item({{/useMutiny}}{{^useMutiny}}CompletableFuture.supplyAsync(() -> {{/useMutiny}}{{/supportAsync}}Response.ok().entity("magic!").build(){{#supportAsync}}){{/supportAsync}};
5255
}

modules/openapi-generator/src/test/java/org/openapitools/codegen/java/jaxrs/JavaJAXRSSpecServerCodegenTest.java

Lines changed: 425 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
openapi: 3.0.1
2+
info:
3+
title: Quarkus OAuth2 multi-flow no scopes test
4+
version: '1.0'
5+
servers:
6+
- url: 'http://localhost:8080/'
7+
paths:
8+
/items:
9+
get:
10+
operationId: getItems
11+
summary: Get items
12+
security:
13+
- oauth2_scheme: []
14+
responses:
15+
'200':
16+
description: OK
17+
post:
18+
operationId: createItem
19+
summary: Create item
20+
responses:
21+
'201':
22+
description: Created
23+
components:
24+
securitySchemes:
25+
oauth2_scheme:
26+
type: oauth2
27+
flows:
28+
authorizationCode:
29+
authorizationUrl: https://example.com/oauth/authorize
30+
tokenUrl: https://example.com/oauth/token
31+
scopes: {}
32+
implicit:
33+
authorizationUrl: https://example.com/api/oauth/dialog
34+
scopes: {}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
openapi: 3.0.1
2+
info:
3+
title: Quarkus OAuth2 no scopes test
4+
version: '1.0'
5+
servers:
6+
- url: 'http://localhost:8080/'
7+
paths:
8+
/items:
9+
get:
10+
operationId: getItems
11+
summary: Get items
12+
security:
13+
- oauth2_scheme: []
14+
responses:
15+
'200':
16+
description: OK
17+
post:
18+
operationId: createItem
19+
summary: Create item
20+
responses:
21+
'201':
22+
description: Created
23+
components:
24+
securitySchemes:
25+
oauth2_scheme:
26+
type: oauth2
27+
flows:
28+
clientCredentials:
29+
tokenUrl: https://example.com/oauth/token
30+
scopes: {}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
openapi: 3.0.1
2+
info:
3+
title: Quarkus OAuth2 OR empty-and-scoped test
4+
version: '1.0'
5+
servers:
6+
- url: 'http://localhost:8080/'
7+
paths:
8+
/items:
9+
get:
10+
operationId: getItems
11+
summary: Get items — OR any-authenticated OR scoped
12+
security:
13+
- oauth2_no_scope: []
14+
- oauth2_with_scope:
15+
- admin
16+
responses:
17+
'200':
18+
description: OK
19+
post:
20+
operationId: createItem
21+
summary: Create item — scoped only
22+
security:
23+
- oauth2_with_scope:
24+
- admin
25+
responses:
26+
'201':
27+
description: Created
28+
components:
29+
securitySchemes:
30+
oauth2_no_scope:
31+
type: oauth2
32+
flows:
33+
clientCredentials:
34+
tokenUrl: https://example.com/oauth/token
35+
scopes: {}
36+
oauth2_with_scope:
37+
type: oauth2
38+
flows:
39+
clientCredentials:
40+
tokenUrl: https://example.com/oauth/token
41+
scopes:
42+
admin: Admin access
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
openapi: 3.0.1
2+
info:
3+
title: Quarkus OAuth2 with scopes test
4+
version: '1.0'
5+
servers:
6+
- url: 'http://localhost:8080/'
7+
paths:
8+
/items:
9+
get:
10+
operationId: getItems
11+
summary: Get items
12+
security:
13+
- oauth2_scheme:
14+
- read:items
15+
responses:
16+
'200':
17+
description: OK
18+
post:
19+
operationId: createItem
20+
summary: Create item
21+
security:
22+
- oauth2_scheme:
23+
- write:items
24+
responses:
25+
'201':
26+
description: Created
27+
components:
28+
securitySchemes:
29+
oauth2_scheme:
30+
type: oauth2
31+
flows:
32+
clientCredentials:
33+
tokenUrl: https://example.com/oauth/token
34+
scopes:
35+
read:items: Read items
36+
write:items: Write items

0 commit comments

Comments
 (0)