Skip to content
Merged
Show file tree
Hide file tree
Changes from 76 commits
Commits
Show all changes
80 commits
Select commit Hold shift + click to select a range
ac55b6c
first commit: add cli option for saga and records. Added dummy sagas.…
bflamand-work Sep 29, 2020
61a3033
More progress with default values. First prototype for isEntity and i…
bflamand-work Oct 1, 2020
2e3a04e
record generation complete
bflamand-work Oct 5, 2020
9411143
record generation complete
bflamand-work Oct 5, 2020
6e867ee
progress with saga generation
bflamand-work Oct 9, 2020
3da2805
progress with saga generation
bflamand-work Nov 25, 2020
7b42777
Merge pull request #1 from OpenAPITools/master
bflamand Nov 30, 2020
9a3160c
first fully working saga generation
bflamand-work Nov 30, 2020
84c702c
Merge remote-tracking branch 'origin/master' into typescript-saga-imm…
bflamand-work Nov 30, 2020
5554245
merge with latest master
bflamand-work Nov 30, 2020
f8030fb
removed unneeded "items" properties.
bflamand-work Nov 30, 2020
8f33935
moved global CodegenModel modifications into subclass ExtendedCodegen…
bflamand-work Dec 2, 2020
f387d06
moved global CodegenOperation modifications into subclass ExtendedCod…
bflamand-work Dec 2, 2020
c586da2
moved global CodegenProperty modifications into subclass ExtendedCode…
bflamand-work Dec 2, 2020
b273409
moved global CodegenParameter modifications into subclass ExtendedCod…
bflamand-work Dec 2, 2020
9b48cf2
added the missing "allSagas" export.
bflamand-work Dec 3, 2020
1796282
renamed & reworked "meta data response" flags to a more useful genera…
bflamand-work Dec 4, 2020
a82ff31
added vendor flag keepAsJSObject as escape hatch to support circular …
bflamand-work Dec 4, 2020
549797d
added autodetection for passthrough to simplify standardised specs.
bflamand-work Dec 7, 2020
1706006
fix small issue with passthrough void
bflamand-work Dec 7, 2020
32c97a4
fix small issues with passthrough void and missing passthrough import…
bflamand-work Dec 8, 2020
e6c5ef3
fix small issues with passthrough void and missing passthrough import…
bflamand-work Dec 10, 2020
ea5a5eb
Merge pull request #3 from OpenAPITools/master
bflamand Dec 10, 2020
e86c81f
Merge remote-tracking branch 'origin/master' into typescript-saga-imm…
bflamand-work Dec 10, 2020
9160502
Added "reservedRecordField" feature to support remapping fields names…
bflamand-work Dec 10, 2020
a77f17e
added uniqueId inference. Fix small generation when uniqueId property…
bflamand-work Dec 11, 2020
8925de1
removed feature "reservedRecordField" and replaced it with existing b…
bflamand-work Dec 11, 2020
090150b
Changed api recType names to make them less likely to cause name conf…
bflamand-work Dec 16, 2020
76eef30
Moved location of ApiEntities related files and fix issues with exports.
bflamand-work Dec 17, 2020
47e06dd
Merge pull request #4 from OpenAPITools/master
bflamand Jan 27, 2021
8e2b99c
merge master
bflamand-work Jan 27, 2021
0e2b574
- merge latest master
bflamand-work Jan 29, 2021
1c67357
- missing ganarate sampless
bflamand-work Jan 29, 2021
1fb2e4f
Merge pull request #5 from OpenAPITools/master
bflamand Feb 8, 2021
639d687
Merge remote-tracking branch 'origin/master' into typescript-saga-imm…
bflamand-work Feb 8, 2021
6ab1fba
- Modified way to export apiEntitiesSelectpr to reduce typescript ana…
bflamand-work Feb 8, 2021
bff46e0
- added markErrorsAsHandled property to api sagas. Increased typescri…
bflamand-work Mar 11, 2021
e72f84f
- fix bug in saga interfaces. Upgraded to typescript "strict" mode to…
bflamand-work Mar 11, 2021
b13159b
- added optional id for apiEntity selectors. Added toInlined() suppor…
bflamand-work Mar 12, 2021
33cf0d4
- minor tweak for apiEntitySelector to accept null id
bflamand-work Mar 12, 2021
0389c3a
- minor tweak for apiEntitySelector
bflamand-work Apr 19, 2021
b2bfad9
Merge pull request #6 from OpenAPITools/master
bflamand Apr 20, 2021
d87cff8
Merge remote-tracking branch 'origin/master' into typescript-saga-imm…
bflamand-work Apr 20, 2021
ea9b4ae
- runned ensure up to date.
bflamand-work Apr 20, 2021
ace4139
Revert "- runned ensure up to date."
bflamand-work Apr 20, 2021
bf12bb2
- runned ensure up to date.
bflamand-work Apr 20, 2021
ec78ed9
- runned ensure up to date.
bflamand-work Apr 20, 2021
a73767b
- added more enhancements: New "toInlined" functionality. Support for…
bflamand-work Sep 9, 2021
d593421
Merge pull request #23 from OpenAPITools/master
bflamand Sep 17, 2021
dbfd307
Merge pull request #24 from OpenAPITools/master
bflamand Sep 20, 2021
b3948f7
Merge remote-tracking branch 'origin/master' into typescript-saga-imm…
bflamand-work Sep 20, 2021
f6de53f
- merge master
bflamand-work Sep 20, 2021
520f7c8
- fix generated api bug in some cases for typescript fetch when no re…
bflamand-work Sep 20, 2021
135fdd6
Merge pull request #25 from OpenAPITools/master
bflamand Sep 21, 2021
5de2c43
Merge remote-tracking branch 'origin/master' into typescript-saga-imm…
bflamand-work Sep 21, 2021
79d0ebf
- commented broken tests
bflamand-work Sep 21, 2021
98c8b41
- fix generate samples analysis.
bflamand-work Sep 21, 2021
2cec373
- work in progress for playframework swagger upgrade
bflamand-work Sep 23, 2021
3ec717f
- first working output for playframework with oauth support for acces…
bflamand-work Sep 24, 2021
e5c43ec
update surefire to newer version
wing328 Sep 25, 2021
3db8f8a
Merge pull request #26 from OpenAPITools/surefire-fix
bflamand Sep 27, 2021
e9bfec1
added new sample project "...playframework-with-security.yaml" and im…
bflamand-work Oct 5, 2021
fbf9368
Merge pull request #28 from OpenAPITools/master
bflamand Oct 5, 2021
e32ef68
Merge pull request #29 from OpenAPITools/master
bflamand Nov 19, 2021
ae028f0
Merge remote-tracking branch 'origin/master' into java_playframework_…
bflamand-work Nov 19, 2021
e991817
split SecurityAPIUtil into more granular and useful functions.
bflamand-work Nov 19, 2021
e874d06
minor fix to have tab instead of spaces in securityapiutils mustache …
bflamand-work Nov 19, 2021
6ba1d9f
added missing generated samples.
bflamand-work Nov 19, 2021
7d34d3b
added missing securityAPIUtils injection in generated "Controller" cl…
bflamand-work Nov 22, 2021
85ea0fa
added missing securityAPIUtils import
bflamand-work Nov 22, 2021
4d06d39
added missing securityAPIUtils import for no-interface samples files.
bflamand-work Nov 22, 2021
4676532
minor tweak: changed order of import for securityApiUtils
bflamand-work Nov 22, 2021
2a98f96
minor tweak: changed order of import for securityApiUtils
bflamand-work Nov 22, 2021
2001d0b
fix: securityApiUtils was incorrectly declared with "throws Exception"
bflamand-work Nov 22, 2021
a9a3793
minor code tweak.
bflamand-work Nov 22, 2021
5d1cf9e
fix potential runtime throw in SecurityApiUtils if playframework conf…
bflamand-work Dec 24, 2021
b72ec9a
Merge pull request #34 from OpenAPITools/master
bflamand Dec 24, 2021
ef13b28
Merge remote-tracking branch 'origin/master' into java_playframework_…
bflamand-work Dec 24, 2021
da4d3ac
run ensure-up-to-date and generate-samples
bflamand-work Dec 24, 2021
e781521
Revert "run ensure-up-to-date and generate-samples"
bflamand-work Dec 24, 2021
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
generatorName: java-play-framework
outputDir: samples/server/petstore/java-play-framework-fake-endpoints-with-security
inputSpec: modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-for-testing-playframework-with-security.yaml
templateDir: modules/openapi-generator/src/main/resources/JavaPlayFramework
additionalProperties:
hideGenerationTimestamp: "true"
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@
package org.openapitools.codegen.languages;

import io.swagger.v3.oas.models.media.Schema;
import io.swagger.v3.oas.models.security.SecurityScheme;
import org.openapitools.codegen.*;
import org.openapitools.codegen.languages.features.BeanValidationFeatures;
import org.openapitools.codegen.meta.features.DocumentationFeature;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import static org.openapitools.codegen.utils.StringUtils.camelize;

Expand All @@ -45,6 +45,10 @@ public class JavaPlayFrameworkCodegen extends AbstractJavaCodegen implements Bea
public static final String USE_SWAGGER_UI = "useSwaggerUI";
public static final String SUPPORT_ASYNC = "supportAsync";

private static final String X_JWKS_URL = "x-jwksUrl";
private static final String X_TOKEN_INTROSPECT_URL = "x-tokenIntrospectUrl";


protected String title = "openapi-java-playframework";
protected String configPackage = "org.openapitools.configuration";
protected String basePackage = "org.openapitools";
Expand Down Expand Up @@ -197,6 +201,7 @@ public void processOpts() {
supportingFiles.add(new SupportingFile("module.mustache", "app", "Module.java"));
}
supportingFiles.add(new SupportingFile("openapiUtils.mustache", "app/openapitools", "OpenAPIUtils.java"));
supportingFiles.add(new SupportingFile("securityApiUtils.mustache", "app/openapitools", "SecurityAPIUtils.java"));
if (this.handleExceptions) {
supportingFiles.add(new SupportingFile("errorHandler.mustache", "app/openapitools", "ErrorHandler.java"));
}
Expand Down Expand Up @@ -376,4 +381,98 @@ public Map<String, Object> postProcessSupportingFileData(Map<String, Object> obj
generateJSONSpecFile(objs);
return super.postProcessSupportingFileData(objs);
}

@Override
public List<CodegenSecurity> fromSecurity(Map<String, SecurityScheme> securitySchemeMap) {
List<? extends CodegenSecurity> securities = super.fromSecurity(securitySchemeMap);
List<CodegenSecurity> extendedSecurities = new ArrayList<>();

for (CodegenSecurity codegenSecurity : securities) {
ExtendedCodegenSecurity extendedCodegenSecurity = new ExtendedCodegenSecurity(codegenSecurity);
Object jwksUrl = extendedCodegenSecurity.vendorExtensions.get(X_JWKS_URL);

if (jwksUrl instanceof String) {
extendedCodegenSecurity.jwksUrl = (String) jwksUrl;
}

Object tokenIntrospectUrl = extendedCodegenSecurity.vendorExtensions.get(X_TOKEN_INTROSPECT_URL);

if (tokenIntrospectUrl instanceof String) {
extendedCodegenSecurity.tokenIntrospectUrl = (String) tokenIntrospectUrl;
}
extendedSecurities.add(extendedCodegenSecurity);
}

return extendedSecurities;
}


class ExtendedCodegenSecurity extends CodegenSecurity {
public String jwksUrl;
public String tokenIntrospectUrl;

public ExtendedCodegenSecurity(CodegenSecurity cm) {
super();

this.name = cm.name;
this.type = cm.type;
this.scheme = cm.scheme;
this.isBasic = cm.isBasic;
this.isOAuth = cm.isOAuth;
this.isApiKey = cm.isApiKey;
this.isBasicBasic = cm.isBasicBasic;
this.isBasicBearer = cm.isBasicBearer;
this.isHttpSignature = cm.isHttpSignature;
this.bearerFormat = cm.bearerFormat;
this.vendorExtensions = new HashMap<String, Object>(cm.vendorExtensions);
this.keyParamName = cm.keyParamName;
this.isKeyInQuery = cm.isKeyInQuery;
this.isKeyInHeader = cm.isKeyInHeader;
this.isKeyInCookie = cm.isKeyInCookie;
this.flow = cm.flow;
this.authorizationUrl = cm.authorizationUrl;
this.tokenUrl = cm.tokenUrl;
this.refreshUrl = cm.refreshUrl;
this.scopes = cm.scopes;
this.isCode = cm.isCode;
this.isPassword = cm.isPassword;
this.isApplication = cm.isApplication;
this.isImplicit = cm.isImplicit;
}

@Override
public CodegenSecurity filterByScopeNames(List<String> filterScopes) {
CodegenSecurity codegenSecurity = super.filterByScopeNames(filterScopes);
ExtendedCodegenSecurity extendedCodegenSecurity = new ExtendedCodegenSecurity(codegenSecurity);
extendedCodegenSecurity.jwksUrl = this.jwksUrl;
extendedCodegenSecurity.tokenIntrospectUrl = this.tokenIntrospectUrl;
return extendedCodegenSecurity;
}

@Override
public boolean equals(Object o) {
boolean result = super.equals(o);
JavaPlayFrameworkCodegen.ExtendedCodegenSecurity that = (JavaPlayFrameworkCodegen.ExtendedCodegenSecurity) o;
return result &&
Objects.equals(jwksUrl, that.jwksUrl) &&
Objects.equals(tokenIntrospectUrl, that.tokenIntrospectUrl);

}

@Override
public int hashCode() {
int superHash = super.hashCode();
return Objects.hash(superHash, tokenIntrospectUrl, jwksUrl);
}

@Override
public String toString() {
String superString = super.toString();
final StringBuilder sb = new StringBuilder(superString);
sb.append(", jwksUrl='").append(jwksUrl).append('\'');
sb.append(", tokenIntrospectUrl='").append(tokenIntrospectUrl).append('\'');
return sb.toString();
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ libraryDependencies += "org.webjars" % "swagger-ui" % "3.32.5"
libraryDependencies += "javax.validation" % "validation-api" % "2.0.1.Final"
{{/useBeanValidation}}
libraryDependencies += guice
libraryDependencies += "com.auth0" % "java-jwt" % "3.18.1"
libraryDependencies += "com.auth0" % "jwks-rsa" % "0.19.0"
libraryDependencies += "org.apache.httpcomponents" % "httpclient" % "4.5.6"
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import com.google.inject.AbstractModule;

import {{apiPackage}}.*;
import openapitools.SecurityAPIUtils;

public class Module extends AbstractModule {

Expand All @@ -11,5 +12,6 @@ public class Module extends AbstractModule {
bind({{classname}}ControllerImpInterface.class).to({{classname}}ControllerImp.class);
{{/apis}}
{{/apiInfo}}
bind(SecurityAPIUtils.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ import play.libs.Files.TemporaryFile;
import java.io.IOException;
{{/handleExceptions}}
import openapitools.OpenAPIUtils;
{{^useInterfaces}}
import openapitools.SecurityAPIUtils;
{{/useInterfaces}}
import com.fasterxml.jackson.core.type.TypeReference;
{{#supportAsync}}

Expand All @@ -46,16 +49,22 @@ public class {{classname}}Controller extends Controller {
{{#useBeanValidation}}
private final Config configuration;
{{/useBeanValidation}}
{{^useInterfaces}}
private final SecurityAPIUtils securityAPIUtils;
{{/useInterfaces}}

@Inject
private {{classname}}Controller({{#useBeanValidation}}Config configuration{{^controllerOnly}}, {{/controllerOnly}}{{/useBeanValidation}}{{^controllerOnly}}{{classname}}ControllerImp{{#useInterfaces}}Interface{{/useInterfaces}} imp{{/controllerOnly}}) {
private {{classname}}Controller({{#useBeanValidation}}Config configuration{{^controllerOnly}}, {{/controllerOnly}}{{/useBeanValidation}}{{^controllerOnly}}{{classname}}ControllerImp{{#useInterfaces}}Interface{{/useInterfaces}} imp{{/controllerOnly}}{{^useInterfaces}}, SecurityAPIUtils securityAPIUtils{{/useInterfaces}}) {
{{^controllerOnly}}
this.imp = imp;
{{/controllerOnly}}
mapper = new ObjectMapper();
{{#useBeanValidation}}
this.configuration = configuration;
{{/useBeanValidation}}
{{^useInterfaces}}
this.securityAPIUtils = securityAPIUtils;
{{/useInterfaces}}
}

{{#operation}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ import play.mvc.Result;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.JsonNode;
import openapitools.OpenAPIUtils;
import openapitools.SecurityAPIUtils;
import static play.mvc.Results.ok;
import static play.mvc.Results.unauthorized;
import play.libs.Files.TemporaryFile;
{{#supportAsync}}
import java.util.concurrent.CompletionException;
Expand All @@ -32,11 +34,12 @@ public abstract class {{classname}}ControllerImpInterface {
{{#useBeanValidation}}
@Inject private Config configuration;
{{/useBeanValidation}}
@Inject private SecurityAPIUtils securityAPIUtils;
private ObjectMapper mapper = new ObjectMapper();

{{#operation}}
public {{#supportAsync}}CompletionStage<{{/supportAsync}}Result{{#supportAsync}}>{{/supportAsync}} {{operationId}}Http(Http.Request request{{#hasParams}}, {{/hasParams}}{{#allParams}}{{>pathParams}}{{>queryParams}}{{>bodyParams}}{{>formParams}}{{>headerParams}}{{^-last}}, {{/-last}}{{/allParams}}) {{#handleExceptions}}throws Exception{{/handleExceptions}} {
{{>responseToResult}}
{{>responseToResult}}
}

public abstract {{^returnType}}void{{/returnType}}{{#returnType}}{{#supportAsync}}CompletionStage<{{/supportAsync}}{{>returnTypesNoVoid}}{{#supportAsync}}>{{/supportAsync}}{{/returnType}} {{operationId}}(Http.Request request{{#hasParams}}, {{/hasParams}}{{#allParams}}{{>pathParams}}{{>queryParams}}{{>bodyParams}}{{>formParams}}{{>headerParams}}{{^-last}}, {{/-last}}{{/allParams}}) {{#handleExceptions}}throws Exception{{/handleExceptions}};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,67 +1,60 @@
{{^controllerOnly}}
{{#authMethods.0}}
{{#isOAuth}}
if (!securityAPIUtils.isRequestTokenValid(request, "{{name}}")) {
return {{#supportAsync}}CompletableFuture.supplyAsync(play.mvc.Results::unauthorized){{/supportAsync}}{{^supportAsync}}unauthorized(){{/supportAsync}};
}

{{/isOAuth}}
{{/authMethods.0}}
{{^returnType}}
{{#supportAsync}}
CompletableFuture<Result> result = CompletableFuture.supplyAsync(() -> {
CompletableFuture<Result> result = CompletableFuture.supplyAsync(() -> {
try {
{{/supportAsync}}
{{/returnType}}
{{#returnType}}{{#supportAsync}}CompletionStage<{{>returnTypesNoVoid}}> stage = {{/supportAsync}}{{^supportAsync}}{{>returnTypesNoVoid}} obj = {{/supportAsync}}{{/returnType}}{{^returnType}}{{#supportAsync}} {{/supportAsync}}{{/returnType}}{{^useInterfaces}}imp.{{/useInterfaces}}{{operationId}}(request{{#hasParams}}, {{/hasParams}}{{#allParams}}{{paramName}}{{^-last}}, {{/-last}}{{/allParams}}){{#returnType}}{{#supportAsync}}.thenApply(obj -> { {{/supportAsync}}{{/returnType}}{{^supportAsync}};{{/supportAsync}}{{#supportAsync}}{{^returnType}};{{/returnType}}{{/supportAsync}}
{{#returnType}}{{#supportAsync}}CompletionStage<{{>returnTypesNoVoid}}> stage = {{/supportAsync}}{{^supportAsync}}{{>returnTypesNoVoid}} obj = {{/supportAsync}}{{/returnType}}{{^returnType}}{{#supportAsync}} {{/supportAsync}}{{/returnType}}{{^useInterfaces}}imp.{{/useInterfaces}}{{operationId}}(request{{#hasParams}}, {{/hasParams}}{{#allParams}}{{paramName}}{{^-last}}, {{/-last}}{{/allParams}}){{#returnType}}{{#supportAsync}}.thenApply(obj -> { {{/supportAsync}}{{/returnType}}{{^supportAsync}};{{/supportAsync}}{{#supportAsync}}{{^returnType}};{{/returnType}}{{/supportAsync}}
{{#returnType}}
{{^isResponseFile}}
{{^returnTypeIsPrimitive}}
{{#useBeanValidation}}
{{^supportAsync}}
if (configuration.getBoolean("useOutputBeanValidation")) {
{{#isArray}}
for ({{{returnType}}} curItem : obj) {
OpenAPIUtils.validate(curItem);
}
{{/isArray}}
{{#isMap}}
for (Map.Entry<String, {{{returnType}}}> entry : obj.entrySet()) {
OpenAPIUtils.validate(entry.getValue());
}
{{/isMap}}
{{^returnContainer}}

if (configuration.getBoolean("useOutputBeanValidation")) {
{{#isArray}}
for ({{{returnType}}} curItem : obj) {
OpenAPIUtils.validate(curItem);
}
{{/isArray}}
{{#isMap}}
for (Map.Entry<String, {{{returnType}}}> entry : obj.entrySet()) {
OpenAPIUtils.validate(entry.getValue());
}
{{/isMap}}
{{^returnContainer}}
OpenAPIUtils.validate(obj);
{{/returnContainer}}
}
{{/supportAsync}}
{{#supportAsync}}
if (configuration.getBoolean("useOutputBeanValidation")) {
{{#isArray}}
for ({{{returnType}}} curItem : obj) {
OpenAPIUtils.validate(curItem);
{{/returnContainer}}
}
{{/isArray}}
{{#isMap}}
for (Map.Entry<String, {{{returnType}}}> entry : obj.entrySet()) {
OpenAPIUtils.validate(entry.getValue());
}
{{/isMap}}
{{^returnContainer}}
OpenAPIUtils.validate(obj);
{{/returnContainer}}
}
{{/supportAsync}}

{{/useBeanValidation}}
{{/returnTypeIsPrimitive}}
{{/isResponseFile}}
{{#supportAsync}}
return obj;
});
return obj;
});
{{/supportAsync}}
{{/returnType}}
{{#returnType}}
{{#supportAsync}}
return stage.thenApply(obj -> {
{{/supportAsync}}
{{^isResponseFile}}
{{#supportAsync}} {{/supportAsync}}JsonNode result = mapper.valueToTree(obj);
{{#supportAsync}} {{/supportAsync}}return ok(result);
{{#supportAsync}} {{/supportAsync}} JsonNode result = mapper.valueToTree(obj);

{{#supportAsync}} {{/supportAsync}} return ok(result);
{{/isResponseFile}}
{{#isResponseFile}}
{{#supportAsync}} {{/supportAsync}}return ok(obj);

{{#supportAsync}} {{/supportAsync}} return ok(obj);
{{/isResponseFile}}
{{/returnType}}
{{^returnType}}
Expand All @@ -74,15 +67,15 @@ return stage.thenApply(obj -> {
return result;
{{/supportAsync}}
{{^supportAsync}}
return ok();
return ok();
{{/supportAsync}}
{{/returnType}}
{{#returnType}}
{{#supportAsync}}
});
});
{{/supportAsync}}
{{/returnType}}
{{/controllerOnly}}
{{#controllerOnly}}
return ok();
return ok();
{{/controllerOnly}}
Loading