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

Java, adds component SecuritySchemes #383

Merged
merged 11 commits into from
Jan 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions docs/generators/java.md
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|examples|✗|OAS3
|requestBodies|✗|OAS3
|headers|✗|OAS3
|securitySchemes||OAS3
|securitySchemes||OAS3
|links|✗|OAS3
|callbacks|✗|OAS3
|pathItems|✗|OAS3
Expand Down Expand Up @@ -320,10 +320,10 @@ These options may be applied as additional-properties (cli) or configOptions (pl
### Security Feature
| Name | Supported | Defined By |
| ---- | --------- | ---------- |
|HTTP_Basic||OAS2,OAS3
|ApiKey||OAS2,OAS3
|HTTP_Basic||OAS2,OAS3
|ApiKey||OAS2,OAS3
|OpenIDConnect|✗|OAS3
|HTTP_Bearer||OAS2,OAS3
|HTTP_Bearer||OAS2,OAS3
|OAuth2_Implicit|✗|OAS2,OAS3
|OAuth2_Password|✗|OAS2,OAS3
|OAuth2_ClientCredentials|✗|OAS2,OAS3
Expand Down
24 changes: 24 additions & 0 deletions samples/client/petstore/java/.openapi-generator/FILES
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,13 @@ docs/components/schemas/UUIDString.md
docs/components/schemas/User.md
docs/components/schemas/Whale.md
docs/components/schemas/Zebra.md
docs/components/securityschemes/ApiKey.md
docs/components/securityschemes/ApiKeyQuery.md
docs/components/securityschemes/BearerTest.md
docs/components/securityschemes/HttpBasicTest.md
docs/components/securityschemes/HttpSignatureTest.md
docs/components/securityschemes/OpenIdConnectTest.md
docs/components/securityschemes/PetstoreAuth.md
docs/paths/anotherfakedummy/patch/responses/response200/content/applicationjson/Schema.md
docs/paths/commonparamsubdir/delete/parameters/parameter0/Schema0.md
docs/paths/commonparamsubdir/delete/parameters/parameter1/Schema1.md
Expand Down Expand Up @@ -466,6 +473,13 @@ src/main/java/org/openapijsonschematools/client/components/schemas/UUIDString.ja
src/main/java/org/openapijsonschematools/client/components/schemas/User.java
src/main/java/org/openapijsonschematools/client/components/schemas/Whale.java
src/main/java/org/openapijsonschematools/client/components/schemas/Zebra.java
src/main/java/org/openapijsonschematools/client/components/securityschemes/ApiKey.java
src/main/java/org/openapijsonschematools/client/components/securityschemes/ApiKeyQuery.java
src/main/java/org/openapijsonschematools/client/components/securityschemes/BearerTest.java
src/main/java/org/openapijsonschematools/client/components/securityschemes/HttpBasicTest.java
src/main/java/org/openapijsonschematools/client/components/securityschemes/HttpSignatureTest.java
src/main/java/org/openapijsonschematools/client/components/securityschemes/OpenIdConnectTest.java
src/main/java/org/openapijsonschematools/client/components/securityschemes/PetstoreAuth.java
src/main/java/org/openapijsonschematools/client/configurations/ApiConfiguration.java
src/main/java/org/openapijsonschematools/client/configurations/JsonSchemaKeywordFlags.java
src/main/java/org/openapijsonschematools/client/configurations/SchemaConfiguration.java
Expand Down Expand Up @@ -759,6 +773,16 @@ src/main/java/org/openapijsonschematools/client/schemas/validation/UniqueItemsVa
src/main/java/org/openapijsonschematools/client/schemas/validation/UnsetAnyTypeJsonSchema.java
src/main/java/org/openapijsonschematools/client/schemas/validation/ValidationData.java
src/main/java/org/openapijsonschematools/client/schemas/validation/ValidationMetadata.java
src/main/java/org/openapijsonschematools/client/securityschemes/ApiKeyInLocation.java
src/main/java/org/openapijsonschematools/client/securityschemes/ApiKeySecurityScheme.java
src/main/java/org/openapijsonschematools/client/securityschemes/HttpBasicSecurityScheme.java
src/main/java/org/openapijsonschematools/client/securityschemes/HttpBearerSecurityScheme.java
src/main/java/org/openapijsonschematools/client/securityschemes/HttpDigestSecurityScheme.java
src/main/java/org/openapijsonschematools/client/securityschemes/HttpSignatureSecurityScheme.java
src/main/java/org/openapijsonschematools/client/securityschemes/MutualTlsSecurityScheme.java
src/main/java/org/openapijsonschematools/client/securityschemes/OAuth2SecurityScheme.java
src/main/java/org/openapijsonschematools/client/securityschemes/OpenIdConnectSecurityScheme.java
src/main/java/org/openapijsonschematools/client/securityschemes/SecurityScheme.java
src/main/java/org/openapijsonschematools/client/servers/Server.java
src/main/java/org/openapijsonschematools/client/servers/Server0.java
src/main/java/org/openapijsonschematools/client/servers/Server1.java
Expand Down
12 changes: 12 additions & 0 deletions samples/client/petstore/java/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -298,3 +298,15 @@ allowed input and output types.
| [Mammal.Mammal1](docs/components/schemas/Mammal.md#mammal1) | |
| [Whale.Whale1](docs/components/schemas/Whale.md#whale1) | |
| [Zebra.Zebra1](docs/components/schemas/Zebra.md#zebra1) | |

## Component SecuritySchemes

| Class | Description |
| ----- | ----------- |
| [ApiKey](docs/components/securityschemes/ApiKey.md) | apiKey in header |
| [ApiKeyQuery](docs/components/securityschemes/ApiKeyQuery.md) | apiKey in query |
| [BearerTest](docs/components/securityschemes/BearerTest.md) | http bearer with JWT bearer format |
| [HttpBasicTest](docs/components/securityschemes/HttpBasicTest.md) | http basic |
| [HttpSignatureTest](docs/components/securityschemes/HttpSignatureTest.md) | http + signature |
| [OpenIdConnectTest](docs/components/securityschemes/OpenIdConnectTest.md) | openIdConnect |
| [PetstoreAuth](docs/components/securityschemes/PetstoreAuth.md) | oauth2 implicit flow with two scopes |
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
org.openapijsonschematools.client.components.securityschemes.ApiKey
# SecurityScheme ApiKey

public class ApiKey
extends ApiKeySecurityScheme

A class that is used to apply auth to a request

### Description
apiKey in header

### Method Summary
| Modifier and Type | Method and Description |
| ----------------- | ---------------------- |
| void | applyAuth(Map<String, List<String>> headers, String resourcePath, String method, HttpRequest.BodyPublisher bodyPublisher, @Nullable String queryParamsSuffix, List<String> scopeNames) |

### Constructor Summary
| Constructor and Description |
| --------------------------- |
| ApiKey(String apiKey)<br>for header apiKey auth |

[[Back to top]](#top) [[Back to Component Security Schemes]](../../../README.md#Component-SecuritySchemes) [[Back to README]](../../../README.md)
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
org.openapijsonschematools.client.components.securityschemes.ApiKeyQuery
# SecurityScheme ApiKeyQuery

public class ApiKeyQuery
extends ApiKeySecurityScheme

A class that is used to apply auth to a request

### Description
apiKey in query

### Method Summary
| Modifier and Type | Method and Description |
| ----------------- | ---------------------- |
| void | applyAuth(Map<String, List<String>> headers, String resourcePath, String method, HttpRequest.BodyPublisher bodyPublisher, @Nullable String queryParamsSuffix, List<String> scopeNames) |

### Constructor Summary
| Constructor and Description |
| --------------------------- |
| ApiKeyQuery(String apiKey)<br>for query apiKey auth |

[[Back to top]](#top) [[Back to Component Security Schemes]](../../../README.md#Component-SecuritySchemes) [[Back to README]](../../../README.md)
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
org.openapijsonschematools.client.components.securityschemes.BearerTest
# SecurityScheme BearerTest

public class BearerTest
extends HttpBearerSecurityScheme

A class that is used to apply auth to a request

### Description
http bearer with JWT bearer format

### Method Summary
| Modifier and Type | Method and Description |
| ----------------- | ---------------------- |
| void | applyAuth(Map<String, List<String>> headers, String resourcePath, String method, HttpRequest.BodyPublisher bodyPublisher, @Nullable String queryParamsSuffix, List<String> scopeNames) |

### Constructor Summary
| Constructor and Description |
| --------------------------- |
| BearerTest(String accessToken) |

[[Back to top]](#top) [[Back to Component Security Schemes]](../../../README.md#Component-SecuritySchemes) [[Back to README]](../../../README.md)
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
org.openapijsonschematools.client.components.securityschemes.HttpBasicTest
# SecurityScheme HttpBasicTest

public class HttpBasicTest
extends HttpBasicSecurityScheme

A class that is used to apply auth to a request

### Description
http basic

### Method Summary
| Modifier and Type | Method and Description |
| ----------------- | ---------------------- |
| void | applyAuth(Map<String, List<String>> headers, String resourcePath, String method, HttpRequest.BodyPublisher bodyPublisher, @Nullable String queryParamsSuffix, List<String> scopeNames) |

### Constructor Summary
| Constructor and Description |
| --------------------------- |
| HttpBasicTest(String userId, String password) |

[[Back to top]](#top) [[Back to Component Security Schemes]](../../../README.md#Component-SecuritySchemes) [[Back to README]](../../../README.md)
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
org.openapijsonschematools.client.components.securityschemes.HttpSignatureTest
# SecurityScheme HttpSignatureTest

public class HttpSignatureTest
extends HttpSignatureSecurityScheme

A class that is used to apply auth to a request

### Description
http + signature

### Method Summary
| Modifier and Type | Method and Description |
| ----------------- | ---------------------- |
| void | applyAuth(Map<String, List<String>> headers, String resourcePath, String method, HttpRequest.BodyPublisher bodyPublisher, @Nullable String queryParamsSuffix, List<String> scopeNames) |

### Constructor Summary
| Constructor and Description |
| --------------------------- |
| todo |

[[Back to top]](#top) [[Back to Component Security Schemes]](../../../README.md#Component-SecuritySchemes) [[Back to README]](../../../README.md)
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
org.openapijsonschematools.client.components.securityschemes.OpenIdConnectTest
# SecurityScheme OpenIdConnectTest

public class OpenIdConnectTest
extends OpenIdConnectSecurityScheme

A class that is used to apply auth to a request

### Description
openIdConnect

### Method Summary
| Modifier and Type | Method and Description |
| ----------------- | ---------------------- |
| void | applyAuth(Map<String, List<String>> headers, String resourcePath, String method, HttpRequest.BodyPublisher bodyPublisher, @Nullable String queryParamsSuffix, List<String> scopeNames) |

### Constructor Summary
| Constructor and Description |
| --------------------------- |
| todo |

[[Back to top]](#top) [[Back to Component Security Schemes]](../../../README.md#Component-SecuritySchemes) [[Back to README]](../../../README.md)
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
org.openapijsonschematools.client.components.securityschemes.PetstoreAuth
# SecurityScheme PetstoreAuth

public class PetstoreAuth
extends Oauth2SecurityScheme

A class that is used to apply auth to a request

### Description
oauth2 implicit flow with two scopes

### Method Summary
| Modifier and Type | Method and Description |
| ----------------- | ---------------------- |
| void | applyAuth(Map<String, List<String>> headers, String resourcePath, String method, HttpRequest.BodyPublisher bodyPublisher, @Nullable String queryParamsSuffix, List<String> scopeNames) |

### Constructor Summary
| Constructor and Description |
| --------------------------- |
| todo |

[[Back to top]](#top) [[Back to Component Security Schemes]](../../../README.md#Component-SecuritySchemes) [[Back to README]](../../../README.md)
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.openapijsonschematools.client.components.securityschemes;

import org.openapijsonschematools.client.securityschemes.ApiKeySecurityScheme;
import org.openapijsonschematools.client.securityschemes.ApiKeyInLocation;

public class ApiKey extends ApiKeySecurityScheme {
/*
apiKey in header
*/
public ApiKey(String apiKey) {
super(apiKey, "api_key", ApiKeyInLocation.HEADER);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.openapijsonschematools.client.components.securityschemes;

import org.openapijsonschematools.client.securityschemes.ApiKeySecurityScheme;
import org.openapijsonschematools.client.securityschemes.ApiKeyInLocation;

public class ApiKeyQuery extends ApiKeySecurityScheme {
/*
apiKey in query
*/
public ApiKeyQuery(String apiKey) {
super(apiKey, "api_key_query", ApiKeyInLocation.QUERY);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.openapijsonschematools.client.components.securityschemes;

import org.openapijsonschematools.client.securityschemes.HttpBearerSecurityScheme;

public class BearerTest extends HttpBearerSecurityScheme {
/*
http bearer with JWT bearer format
*/
public BearerTest(String accessToken) {
super(accessToken, "JWT");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.openapijsonschematools.client.components.securityschemes;

import org.openapijsonschematools.client.securityschemes.HttpBasicSecurityScheme;

public class HttpBasicTest extends HttpBasicSecurityScheme {
/*
http basic
*/
public HttpBasicTest(String userId, String password) {
super(userId, password);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.openapijsonschematools.client.components.securityschemes;

import org.openapijsonschematools.client.securityschemes.HttpSignatureSecurityScheme;

public class HttpSignatureTest extends HttpSignatureSecurityScheme {
/*
http + signature
*/
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.openapijsonschematools.client.components.securityschemes;

import org.openapijsonschematools.client.securityschemes.OpenIdConnectSecurityScheme;

public class OpenIdConnectTest extends OpenIdConnectSecurityScheme {
/*
openIdConnect
*/
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.openapijsonschematools.client.components.securityschemes;

import org.openapijsonschematools.client.securityschemes.OAuth2SecurityScheme;

public class PetstoreAuth extends OAuth2SecurityScheme {
/*
oauth2 implicit flow with two scopes
*/
// todo add flows info
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.openapijsonschematools.client.securityschemes;

public enum ApiKeyInLocation{
QUERY,
HEADER,
COOKIE
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package org.openapijsonschematools.client.securityschemes;

import org.checkerframework.checker.nullness.qual.Nullable;

import java.net.http.HttpRequest;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class ApiKeySecurityScheme implements SecurityScheme {
private final String apiKey;
private final @Nullable String name;
private final ApiKeyInLocation inLocation;

protected ApiKeySecurityScheme(String apiKey, @Nullable String name, ApiKeyInLocation inLocation) {
this.apiKey = apiKey;
this.name = name;
this.inLocation = inLocation;
}

@Override
public void applyAuth(Map<String, List<String>> headers, String resourcePath, String method, HttpRequest.BodyPublisher bodyPublisher, @Nullable String queryParamsSuffix, List<String> scopeNames) {
switch (inLocation) {
case COOKIE -> {
List<String> cookieValue = headers.getOrDefault("Cookie", new ArrayList<>());
cookieValue.add(apiKey);
}
case HEADER -> {
List<String> headerValue = headers.getOrDefault(name, new ArrayList<>());
headerValue.add(apiKey);
}
case QUERY -> throw new UnsupportedOperationException("If you need this, submit a PR adding this feature");
}
}
}
Loading