Skip to content
This repository was archived by the owner on Dec 25, 2024. It is now read-only.

Commit 7fb5f62

Browse files
authored
Java, adds component SecuritySchemes (#383)
* Adds SecurityScheme * Adds ApiKeySecurityScheme * Adds 3 security schemes * Adds all securityScheme class types, many unimplemented * Updates security scheme files * Improves apikey constructor * Fixes component schema filenames for java * Adds readme links to nonexistent component security scheme docs * Adds component security scheme docs * Samples regen * Fixes java typos
1 parent 8a99120 commit 7fb5f62

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+990
-5
lines changed

docs/generators/java.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
183183
|examples|✗|OAS3
184184
|requestBodies|✗|OAS3
185185
|headers|✗|OAS3
186-
|securitySchemes||OAS3
186+
|securitySchemes||OAS3
187187
|links|✗|OAS3
188188
|callbacks|✗|OAS3
189189
|pathItems|✗|OAS3
@@ -320,10 +320,10 @@ These options may be applied as additional-properties (cli) or configOptions (pl
320320
### Security Feature
321321
| Name | Supported | Defined By |
322322
| ---- | --------- | ---------- |
323-
|HTTP_Basic||OAS2,OAS3
324-
|ApiKey||OAS2,OAS3
323+
|HTTP_Basic||OAS2,OAS3
324+
|ApiKey||OAS2,OAS3
325325
|OpenIDConnect|✗|OAS3
326-
|HTTP_Bearer||OAS2,OAS3
326+
|HTTP_Bearer||OAS2,OAS3
327327
|OAuth2_Implicit|✗|OAS2,OAS3
328328
|OAuth2_Password|✗|OAS2,OAS3
329329
|OAuth2_ClientCredentials|✗|OAS2,OAS3

samples/client/petstore/java/.openapi-generator/FILES

+24
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,13 @@ docs/components/schemas/UUIDString.md
156156
docs/components/schemas/User.md
157157
docs/components/schemas/Whale.md
158158
docs/components/schemas/Zebra.md
159+
docs/components/securityschemes/ApiKey.md
160+
docs/components/securityschemes/ApiKeyQuery.md
161+
docs/components/securityschemes/BearerTest.md
162+
docs/components/securityschemes/HttpBasicTest.md
163+
docs/components/securityschemes/HttpSignatureTest.md
164+
docs/components/securityschemes/OpenIdConnectTest.md
165+
docs/components/securityschemes/PetstoreAuth.md
159166
docs/paths/anotherfakedummy/patch/responses/response200/content/applicationjson/Schema.md
160167
docs/paths/commonparamsubdir/delete/parameters/parameter0/Schema0.md
161168
docs/paths/commonparamsubdir/delete/parameters/parameter1/Schema1.md
@@ -466,6 +473,13 @@ src/main/java/org/openapijsonschematools/client/components/schemas/UUIDString.ja
466473
src/main/java/org/openapijsonschematools/client/components/schemas/User.java
467474
src/main/java/org/openapijsonschematools/client/components/schemas/Whale.java
468475
src/main/java/org/openapijsonschematools/client/components/schemas/Zebra.java
476+
src/main/java/org/openapijsonschematools/client/components/securityschemes/ApiKey.java
477+
src/main/java/org/openapijsonschematools/client/components/securityschemes/ApiKeyQuery.java
478+
src/main/java/org/openapijsonschematools/client/components/securityschemes/BearerTest.java
479+
src/main/java/org/openapijsonschematools/client/components/securityschemes/HttpBasicTest.java
480+
src/main/java/org/openapijsonschematools/client/components/securityschemes/HttpSignatureTest.java
481+
src/main/java/org/openapijsonschematools/client/components/securityschemes/OpenIdConnectTest.java
482+
src/main/java/org/openapijsonschematools/client/components/securityschemes/PetstoreAuth.java
469483
src/main/java/org/openapijsonschematools/client/configurations/ApiConfiguration.java
470484
src/main/java/org/openapijsonschematools/client/configurations/JsonSchemaKeywordFlags.java
471485
src/main/java/org/openapijsonschematools/client/configurations/SchemaConfiguration.java
@@ -759,6 +773,16 @@ src/main/java/org/openapijsonschematools/client/schemas/validation/UniqueItemsVa
759773
src/main/java/org/openapijsonschematools/client/schemas/validation/UnsetAnyTypeJsonSchema.java
760774
src/main/java/org/openapijsonschematools/client/schemas/validation/ValidationData.java
761775
src/main/java/org/openapijsonschematools/client/schemas/validation/ValidationMetadata.java
776+
src/main/java/org/openapijsonschematools/client/securityschemes/ApiKeyInLocation.java
777+
src/main/java/org/openapijsonschematools/client/securityschemes/ApiKeySecurityScheme.java
778+
src/main/java/org/openapijsonschematools/client/securityschemes/HttpBasicSecurityScheme.java
779+
src/main/java/org/openapijsonschematools/client/securityschemes/HttpBearerSecurityScheme.java
780+
src/main/java/org/openapijsonschematools/client/securityschemes/HttpDigestSecurityScheme.java
781+
src/main/java/org/openapijsonschematools/client/securityschemes/HttpSignatureSecurityScheme.java
782+
src/main/java/org/openapijsonschematools/client/securityschemes/MutualTlsSecurityScheme.java
783+
src/main/java/org/openapijsonschematools/client/securityschemes/OAuth2SecurityScheme.java
784+
src/main/java/org/openapijsonschematools/client/securityschemes/OpenIdConnectSecurityScheme.java
785+
src/main/java/org/openapijsonschematools/client/securityschemes/SecurityScheme.java
762786
src/main/java/org/openapijsonschematools/client/servers/Server.java
763787
src/main/java/org/openapijsonschematools/client/servers/Server0.java
764788
src/main/java/org/openapijsonschematools/client/servers/Server1.java

samples/client/petstore/java/README.md

+12
Original file line numberDiff line numberDiff line change
@@ -298,3 +298,15 @@ allowed input and output types.
298298
| [Mammal.Mammal1](docs/components/schemas/Mammal.md#mammal1) | |
299299
| [Whale.Whale1](docs/components/schemas/Whale.md#whale1) | |
300300
| [Zebra.Zebra1](docs/components/schemas/Zebra.md#zebra1) | |
301+
302+
## Component SecuritySchemes
303+
304+
| Class | Description |
305+
| ----- | ----------- |
306+
| [ApiKey](docs/components/securityschemes/ApiKey.md) | apiKey in header |
307+
| [ApiKeyQuery](docs/components/securityschemes/ApiKeyQuery.md) | apiKey in query |
308+
| [BearerTest](docs/components/securityschemes/BearerTest.md) | http bearer with JWT bearer format |
309+
| [HttpBasicTest](docs/components/securityschemes/HttpBasicTest.md) | http basic |
310+
| [HttpSignatureTest](docs/components/securityschemes/HttpSignatureTest.md) | http + signature |
311+
| [OpenIdConnectTest](docs/components/securityschemes/OpenIdConnectTest.md) | openIdConnect |
312+
| [PetstoreAuth](docs/components/securityschemes/PetstoreAuth.md) | oauth2 implicit flow with two scopes |
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
org.openapijsonschematools.client.components.securityschemes.ApiKey
2+
# SecurityScheme ApiKey
3+
4+
public class ApiKey
5+
extends ApiKeySecurityScheme
6+
7+
A class that is used to apply auth to a request
8+
9+
### Description
10+
apiKey in header
11+
12+
### Method Summary
13+
| Modifier and Type | Method and Description |
14+
| ----------------- | ---------------------- |
15+
| void | applyAuth(Map<String, List<String>> headers, String resourcePath, String method, HttpRequest.BodyPublisher bodyPublisher, @Nullable String queryParamsSuffix, List<String> scopeNames) |
16+
17+
### Constructor Summary
18+
| Constructor and Description |
19+
| --------------------------- |
20+
| ApiKey(String apiKey)<br>for header apiKey auth |
21+
22+
[[Back to top]](#top) [[Back to Component Security Schemes]](../../../README.md#Component-SecuritySchemes) [[Back to README]](../../../README.md)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
org.openapijsonschematools.client.components.securityschemes.ApiKeyQuery
2+
# SecurityScheme ApiKeyQuery
3+
4+
public class ApiKeyQuery
5+
extends ApiKeySecurityScheme
6+
7+
A class that is used to apply auth to a request
8+
9+
### Description
10+
apiKey in query
11+
12+
### Method Summary
13+
| Modifier and Type | Method and Description |
14+
| ----------------- | ---------------------- |
15+
| void | applyAuth(Map<String, List<String>> headers, String resourcePath, String method, HttpRequest.BodyPublisher bodyPublisher, @Nullable String queryParamsSuffix, List<String> scopeNames) |
16+
17+
### Constructor Summary
18+
| Constructor and Description |
19+
| --------------------------- |
20+
| ApiKeyQuery(String apiKey)<br>for query apiKey auth |
21+
22+
[[Back to top]](#top) [[Back to Component Security Schemes]](../../../README.md#Component-SecuritySchemes) [[Back to README]](../../../README.md)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
org.openapijsonschematools.client.components.securityschemes.BearerTest
2+
# SecurityScheme BearerTest
3+
4+
public class BearerTest
5+
extends HttpBearerSecurityScheme
6+
7+
A class that is used to apply auth to a request
8+
9+
### Description
10+
http bearer with JWT bearer format
11+
12+
### Method Summary
13+
| Modifier and Type | Method and Description |
14+
| ----------------- | ---------------------- |
15+
| void | applyAuth(Map<String, List<String>> headers, String resourcePath, String method, HttpRequest.BodyPublisher bodyPublisher, @Nullable String queryParamsSuffix, List<String> scopeNames) |
16+
17+
### Constructor Summary
18+
| Constructor and Description |
19+
| --------------------------- |
20+
| BearerTest(String accessToken) |
21+
22+
[[Back to top]](#top) [[Back to Component Security Schemes]](../../../README.md#Component-SecuritySchemes) [[Back to README]](../../../README.md)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
org.openapijsonschematools.client.components.securityschemes.HttpBasicTest
2+
# SecurityScheme HttpBasicTest
3+
4+
public class HttpBasicTest
5+
extends HttpBasicSecurityScheme
6+
7+
A class that is used to apply auth to a request
8+
9+
### Description
10+
http basic
11+
12+
### Method Summary
13+
| Modifier and Type | Method and Description |
14+
| ----------------- | ---------------------- |
15+
| void | applyAuth(Map<String, List<String>> headers, String resourcePath, String method, HttpRequest.BodyPublisher bodyPublisher, @Nullable String queryParamsSuffix, List<String> scopeNames) |
16+
17+
### Constructor Summary
18+
| Constructor and Description |
19+
| --------------------------- |
20+
| HttpBasicTest(String userId, String password) |
21+
22+
[[Back to top]](#top) [[Back to Component Security Schemes]](../../../README.md#Component-SecuritySchemes) [[Back to README]](../../../README.md)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
org.openapijsonschematools.client.components.securityschemes.HttpSignatureTest
2+
# SecurityScheme HttpSignatureTest
3+
4+
public class HttpSignatureTest
5+
extends HttpSignatureSecurityScheme
6+
7+
A class that is used to apply auth to a request
8+
9+
### Description
10+
http + signature
11+
12+
### Method Summary
13+
| Modifier and Type | Method and Description |
14+
| ----------------- | ---------------------- |
15+
| void | applyAuth(Map<String, List<String>> headers, String resourcePath, String method, HttpRequest.BodyPublisher bodyPublisher, @Nullable String queryParamsSuffix, List<String> scopeNames) |
16+
17+
### Constructor Summary
18+
| Constructor and Description |
19+
| --------------------------- |
20+
| todo |
21+
22+
[[Back to top]](#top) [[Back to Component Security Schemes]](../../../README.md#Component-SecuritySchemes) [[Back to README]](../../../README.md)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
org.openapijsonschematools.client.components.securityschemes.OpenIdConnectTest
2+
# SecurityScheme OpenIdConnectTest
3+
4+
public class OpenIdConnectTest
5+
extends OpenIdConnectSecurityScheme
6+
7+
A class that is used to apply auth to a request
8+
9+
### Description
10+
openIdConnect
11+
12+
### Method Summary
13+
| Modifier and Type | Method and Description |
14+
| ----------------- | ---------------------- |
15+
| void | applyAuth(Map<String, List<String>> headers, String resourcePath, String method, HttpRequest.BodyPublisher bodyPublisher, @Nullable String queryParamsSuffix, List<String> scopeNames) |
16+
17+
### Constructor Summary
18+
| Constructor and Description |
19+
| --------------------------- |
20+
| todo |
21+
22+
[[Back to top]](#top) [[Back to Component Security Schemes]](../../../README.md#Component-SecuritySchemes) [[Back to README]](../../../README.md)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
org.openapijsonschematools.client.components.securityschemes.PetstoreAuth
2+
# SecurityScheme PetstoreAuth
3+
4+
public class PetstoreAuth
5+
extends Oauth2SecurityScheme
6+
7+
A class that is used to apply auth to a request
8+
9+
### Description
10+
oauth2 implicit flow with two scopes
11+
12+
### Method Summary
13+
| Modifier and Type | Method and Description |
14+
| ----------------- | ---------------------- |
15+
| void | applyAuth(Map<String, List<String>> headers, String resourcePath, String method, HttpRequest.BodyPublisher bodyPublisher, @Nullable String queryParamsSuffix, List<String> scopeNames) |
16+
17+
### Constructor Summary
18+
| Constructor and Description |
19+
| --------------------------- |
20+
| todo |
21+
22+
[[Back to top]](#top) [[Back to Component Security Schemes]](../../../README.md#Component-SecuritySchemes) [[Back to README]](../../../README.md)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package org.openapijsonschematools.client.components.securityschemes;
2+
3+
import org.openapijsonschematools.client.securityschemes.ApiKeySecurityScheme;
4+
import org.openapijsonschematools.client.securityschemes.ApiKeyInLocation;
5+
6+
public class ApiKey extends ApiKeySecurityScheme {
7+
/*
8+
apiKey in header
9+
*/
10+
public ApiKey(String apiKey) {
11+
super(apiKey, "api_key", ApiKeyInLocation.HEADER);
12+
}
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package org.openapijsonschematools.client.components.securityschemes;
2+
3+
import org.openapijsonschematools.client.securityschemes.ApiKeySecurityScheme;
4+
import org.openapijsonschematools.client.securityschemes.ApiKeyInLocation;
5+
6+
public class ApiKeyQuery extends ApiKeySecurityScheme {
7+
/*
8+
apiKey in query
9+
*/
10+
public ApiKeyQuery(String apiKey) {
11+
super(apiKey, "api_key_query", ApiKeyInLocation.QUERY);
12+
}
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package org.openapijsonschematools.client.components.securityschemes;
2+
3+
import org.openapijsonschematools.client.securityschemes.HttpBearerSecurityScheme;
4+
5+
public class BearerTest extends HttpBearerSecurityScheme {
6+
/*
7+
http bearer with JWT bearer format
8+
*/
9+
public BearerTest(String accessToken) {
10+
super(accessToken, "JWT");
11+
}
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package org.openapijsonschematools.client.components.securityschemes;
2+
3+
import org.openapijsonschematools.client.securityschemes.HttpBasicSecurityScheme;
4+
5+
public class HttpBasicTest extends HttpBasicSecurityScheme {
6+
/*
7+
http basic
8+
*/
9+
public HttpBasicTest(String userId, String password) {
10+
super(userId, password);
11+
}
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package org.openapijsonschematools.client.components.securityschemes;
2+
3+
import org.openapijsonschematools.client.securityschemes.HttpSignatureSecurityScheme;
4+
5+
public class HttpSignatureTest extends HttpSignatureSecurityScheme {
6+
/*
7+
http + signature
8+
*/
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package org.openapijsonschematools.client.components.securityschemes;
2+
3+
import org.openapijsonschematools.client.securityschemes.OpenIdConnectSecurityScheme;
4+
5+
public class OpenIdConnectTest extends OpenIdConnectSecurityScheme {
6+
/*
7+
openIdConnect
8+
*/
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package org.openapijsonschematools.client.components.securityschemes;
2+
3+
import org.openapijsonschematools.client.securityschemes.OAuth2SecurityScheme;
4+
5+
public class PetstoreAuth extends OAuth2SecurityScheme {
6+
/*
7+
oauth2 implicit flow with two scopes
8+
*/
9+
// todo add flows info
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package org.openapijsonschematools.client.securityschemes;
2+
3+
public enum ApiKeyInLocation{
4+
QUERY,
5+
HEADER,
6+
COOKIE
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package org.openapijsonschematools.client.securityschemes;
2+
3+
import org.checkerframework.checker.nullness.qual.Nullable;
4+
5+
import java.net.http.HttpRequest;
6+
import java.util.ArrayList;
7+
import java.util.List;
8+
import java.util.Map;
9+
10+
public class ApiKeySecurityScheme implements SecurityScheme {
11+
private final String apiKey;
12+
private final @Nullable String name;
13+
private final ApiKeyInLocation inLocation;
14+
15+
protected ApiKeySecurityScheme(String apiKey, @Nullable String name, ApiKeyInLocation inLocation) {
16+
this.apiKey = apiKey;
17+
this.name = name;
18+
this.inLocation = inLocation;
19+
}
20+
21+
@Override
22+
public void applyAuth(Map<String, List<String>> headers, String resourcePath, String method, HttpRequest.BodyPublisher bodyPublisher, @Nullable String queryParamsSuffix, List<String> scopeNames) {
23+
switch (inLocation) {
24+
case COOKIE -> {
25+
List<String> cookieValue = headers.getOrDefault("Cookie", new ArrayList<>());
26+
cookieValue.add(apiKey);
27+
}
28+
case HEADER -> {
29+
List<String> headerValue = headers.getOrDefault(name, new ArrayList<>());
30+
headerValue.add(apiKey);
31+
}
32+
case QUERY -> throw new UnsupportedOperationException("If you need this, submit a PR adding this feature");
33+
}
34+
}
35+
}

0 commit comments

Comments
 (0)