Skip to content

Commit

Permalink
Merge branch 'OpenAPITools:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
MANN3005 authored Nov 19, 2023
2 parents 1076006 + a577db8 commit 50d722a
Show file tree
Hide file tree
Showing 141 changed files with 3,341 additions and 649 deletions.
9 changes: 7 additions & 2 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@
"ghcr.io/devcontainers/features/node:1": {
"version": "lts"
},
"ghcr.io/snebjorn/devcontainer-feature/chromium:latest": {}
"ghcr.io/snebjorn/devcontainer-feature/chromium:latest": {},
"docker-in-docker": {
"version": "latest",
"moby": true,
"dockerDashComposeVersion": "v1"
}
},
// Configure tool-specific properties.
"customizations": {
Expand Down Expand Up @@ -44,4 +49,4 @@
// "postCreateCommand": "mvn clean package -DskipTests",
// Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
"remoteUser": "vscode"
}
}
6 changes: 3 additions & 3 deletions .github/workflows/samples-python-server.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ name: Python Server
on:
push:
paths:
- samples/server/petstore/python-aiohttp/**
- samples/server/petstore/python-aiohttp-srclayout/**
pull_request:
paths:
- samples/server/petstore/python-aiohttp/**
- samples/server/petstore/python-aiohttp-srclayout/**
jobs:
build:
name: Test Python server
Expand All @@ -16,7 +16,7 @@ jobs:
matrix:
sample:
# servers
- samples/server/petstore/python-aiohttp/
- samples/server/petstore/python-aiohttp-srclayout/
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
generatorName: jmeter
outputDir: samples/client/petstore/jmeter
inputSpec: modules/openapi-generator/src/test/resources/2_0/petstore.yaml
inputSpec: modules/openapi-generator/src/test/resources/3_0/jmeter/petstore.yaml
templateDir: modules/openapi-generator/src/main/resources/jmeter-client
Original file line number Diff line number Diff line change
Expand Up @@ -2024,16 +2024,6 @@ private PythonType uuidType(IJsonSchemaValidationProperties cp) {
return new PythonType(cp.getDataType());
}

private PythonType freeFormType(IJsonSchemaValidationProperties cp) {
typingImports.add("Dict");
typingImports.add("Any");
typingImports.add("Union");
PythonType pt = new PythonType("Union");
pt.addTypeParam(new PythonType("str"));
pt.addTypeParam(new PythonType("Any"));
return pt;
}

private PythonType modelType(IJsonSchemaValidationProperties cp) {
// add model prefix
hasModelsToImport = true;
Expand All @@ -2056,7 +2046,7 @@ private PythonType fromCommon(IJsonSchemaValidationProperties cp) {

if (cp.getIsArray()) {
return arrayType(cp);
} else if (cp.getIsMap()) {
} else if (cp.getIsMap() || cp.getIsFreeFormObject()) {
return mapType(cp);
} else if (cp.getIsString()) {
return stringType(cp);
Expand All @@ -2076,8 +2066,6 @@ private PythonType fromCommon(IJsonSchemaValidationProperties cp) {
return dateType(cp);
} else if (cp.getIsUuid()) {
return uuidType(cp);
} else if (cp.getIsFreeFormObject()) { // type: object
return freeFormType(cp);
}

return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,12 @@ public void preprocessOpenAPI(OpenAPI openAPI) {
}
}

@Override
public String toOperationId(String operationId) {
// replace $ with _
return super.toOperationId(operationId.replace("$", "_"));
}

/**
* Escapes a reserved word as defined in the `reservedWords` array. Handle escaping
* those terms here. This logic is only called if a variable matches the reserved words
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ private ModelsMap postProcessModelsMap(ModelsMap objs) {
propType = prop.dataType;
}

if ((!prop.required || prop.isNullable)) { // optional or nullable
if ((!prop.required || prop.isNullable) && propType != "mixed") { // optional or nullable but not mixed
propType = "?" + propType;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ public RustServerCodegen() {
typeMapping.put("ByteArray", bytesType);
typeMapping.put("binary", bytesType);
typeMapping.put("boolean", "bool");
typeMapping.put("date", "chrono::DateTime::<chrono::Utc>");
typeMapping.put("date", "chrono::naive::NaiveDate");
typeMapping.put("DateTime", "chrono::DateTime::<chrono::Utc>");
typeMapping.put("password", "String");
typeMapping.put("File", bytesType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ package {{invokerPackage}}.auth;

import {{invokerPackage}}.Pair;

import java.util.Map;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.function.Supplier;

{{>generatedAnnotation}}
public class HttpBearerAuth implements Authentication {
private final String scheme;
private String bearerToken;
private Supplier<String> tokenSupplier;
public HttpBearerAuth(String scheme) {
this.scheme = scheme;
Expand All @@ -22,7 +24,7 @@ public class HttpBearerAuth implements Authentication {
* @return The bearer token
*/
public String getBearerToken() {
return bearerToken;
return tokenSupplier.get();
}

/**
Expand All @@ -31,12 +33,22 @@ public class HttpBearerAuth implements Authentication {
* @param bearerToken The bearer token to send in the Authorization header
*/
public void setBearerToken(String bearerToken) {
this.bearerToken = bearerToken;
this.tokenSupplier = () -> bearerToken;
}

/**
* Sets the supplier of tokens, which together with the scheme, will be sent as the value of the Authorization header.
*
* @param tokenSupplier The supplier of bearer tokens to send in the Authorization header
*/
public void setBearerToken(Supplier<String> tokenSupplier) {
this.tokenSupplier = tokenSupplier;
}

@Override
public void applyToParams(List<Pair> queryParams, Map<String, String> headerParams, Map<String, String> cookieParams) {
if(bearerToken == null) {
String bearerToken = Optional.ofNullable(tokenSupplier).map(Supplier::get).orElse(null);
if (bearerToken == null) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import java.util.List;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.Date;
import java.util.function.Supplier;
import java.util.TimeZone;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
Expand Down Expand Up @@ -335,6 +336,20 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {
throw new RuntimeException("No Bearer authentication configured!");
}

/**
* Helper method to set the supplier of access tokens for Bearer authentication.
*
* @param tokenSupplier the token supplier function
*/
public void setBearerToken(Supplier<String> tokenSupplier) {
for (Authentication auth : authentications.values()) {
if (auth instanceof HttpBearerAuth) {
((HttpBearerAuth) auth).setBearerToken(tokenSupplier);
return;
}
}
throw new RuntimeException("No Bearer authentication configured!");
}
{{/hasHttpBearerMethods}}

{{#hasHttpBasicMethods}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package {{invokerPackage}};

import java.util.LinkedHashMap;
import java.util.Map;
import java.util.function.Supplier;
import java.util.logging.Level;
import java.util.logging.Logger;

Expand Down Expand Up @@ -265,6 +266,15 @@ public class ApiClient {
apiAuthorization.setBearerToken(bearerToken);
}

/**
* Helper method to configure the supplier of bearer tokens.
* @param tokenSupplier the supplier of bearer tokens.
*/
public void setBearerToken(Supplier<String> tokenSupplier) {
HttpBearerAuth apiAuthorization = getAuthorization(HttpBearerAuth.class);
apiAuthorization.setBearerToken(tokenSupplier);
}

/**
* Helper method to configure the first api key found
* @param apiKey API key
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,51 @@ package {{invokerPackage}}.auth;

import feign.RequestInterceptor;
import feign.RequestTemplate;
import java.util.Optional;
import java.util.function.Supplier;

/**
* An interceptor that adds the request header needed to use HTTP bearer authentication.
*/
public class HttpBearerAuth implements RequestInterceptor {
private final String scheme;
private String bearerToken;
private Supplier<String> tokenSupplier;
public HttpBearerAuth(String scheme) {
this.scheme = scheme;
}

/**
* Gets the token, which together with the scheme, will be sent as the value of the Authorization header.
*
* @return The bearer token
*/
public String getBearerToken() {
return bearerToken;
return tokenSupplier.get();
}

/**
* Sets the token, which together with the scheme, will be sent as the value of the Authorization header.
*
* @param bearerToken The bearer token to send in the Authorization header
*/
public void setBearerToken(String bearerToken) {
this.bearerToken = bearerToken;
this.tokenSupplier = () -> bearerToken;
}

/**
* Sets the supplier of tokens, which together with the scheme, will be sent as the value of the Authorization header.
*
* @param tokenSupplier The supplier of bearer tokens to send in the Authorization header
*/
public void setBearerToken(Supplier<String> tokenSupplier) {
this.tokenSupplier = tokenSupplier;
}

@Override
public void apply(RequestTemplate template) {
if(bearerToken == null) {
String bearerToken = Optional.ofNullable(tokenSupplier).map(Supplier::get).orElse(null);
if (bearerToken == null) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.Map.Entry;
import java.util.concurrent.TimeUnit;
import java.util.function.Supplier;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

Expand Down Expand Up @@ -528,14 +529,23 @@ public class ApiClient {
}

{{#hasHttpBearerMethods}}
/**
* Helper method to set access token for the first Bearer authentication.
* @param bearerToken Bearer token
*/
/**
* Helper method to set access token for the first Bearer authentication.
* @param bearerToken Bearer token
*/
public void setBearerToken(String bearerToken) {
setBearerToken(() -> bearerToken);
}

/**
* Helper method to set the supplier of access tokens for Bearer authentication.
*
* @param tokenSupplier The supplier of bearer tokens
*/
public void setBearerToken(Supplier<String> tokenSupplier) {
for (Authentication auth : authentications.values()) {
if (auth instanceof HttpBearerAuth) {
((HttpBearerAuth) auth).setBearerToken(bearerToken);
((HttpBearerAuth) auth).setBearerToken(tokenSupplier);
return;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ import {{invokerPackage}}.ApiException;
import {{invokerPackage}}.Pair;

import java.net.URI;
import java.util.Map;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.function.Supplier;

{{>generatedAnnotation}}
public class HttpBearerAuth implements Authentication {
private final String scheme;
private String bearerToken;
private Supplier<String> tokenSupplier;
public HttpBearerAuth(String scheme) {
this.scheme = scheme;
Expand All @@ -24,7 +26,7 @@ public class HttpBearerAuth implements Authentication {
* @return The bearer token
*/
public String getBearerToken() {
return bearerToken;
return tokenSupplier.get();
}

/**
Expand All @@ -33,12 +35,22 @@ public class HttpBearerAuth implements Authentication {
* @param bearerToken The bearer token to send in the Authorization header
*/
public void setBearerToken(String bearerToken) {
this.bearerToken = bearerToken;
this.tokenSupplier = () -> bearerToken;
}

/**
* Sets the supplier of tokens, which together with the scheme, will be sent as the value of the Authorization header.
*
* @param tokenSupplier The supplier of bearer tokens to send in the Authorization header
*/
public void setBearerToken(Supplier<String> tokenSupplier) {
this.tokenSupplier = tokenSupplier;
}

@Override
public void applyToParams(List<Pair> queryParams, Map<String, String> headerParams, Map<String, String> cookieParams,
String payload, String method, URI uri) throws ApiException {
String bearerToken = Optional.ofNullable(tokenSupplier).map(Supplier::get).orElse(null);
if (bearerToken == null) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,18 +188,18 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {

{{#hasHttpBearerMethods}}
/**
* Helper method to set token for HTTP bearer authentication.
* Helper method to set access token for the first Bearer authentication.
*
* @param bearerToken the token
* @param bearerToken Bearer token
*/
public void setBearerToken(String bearerToken) {
setBearerToken(() -> bearerToken);
}

/**
* Helper method to set the token supplier for HTTP bearer authentication.
* Helper method to set the supplier of access tokens for Bearer authentication.
*
* @param tokenSupplier the token supplier function
* @param tokenSupplier The supplier of bearer tokens
*/
public void setBearerToken(Supplier<String> tokenSupplier) {
for (Authentication auth : authentications.values()) {
Expand Down
Loading

0 comments on commit 50d722a

Please sign in to comment.