mirror of
https://github.com/valitydev/openapi-generator.git
synced 2024-11-07 02:55:19 +00:00
better handle of oauth (#1838)
This commit is contained in:
parent
233ce093e5
commit
ed5bd5ffb0
@ -839,6 +839,11 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
|
||||
if (authMethods != null && !authMethods.isEmpty()) {
|
||||
bundle.put("authMethods", authMethods);
|
||||
bundle.put("hasAuthMethods", true);
|
||||
|
||||
if (hasOAuthMethods(authMethods)) {
|
||||
bundle.put("hasOAuthMethods", true);
|
||||
bundle.put("oauthMethods", getOAuthMethods(authMethods));
|
||||
}
|
||||
}
|
||||
|
||||
List<CodegenServer> servers = config.fromServers(openAPI.getServers());
|
||||
@ -1182,4 +1187,26 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
|
||||
}
|
||||
return authMethods;
|
||||
}
|
||||
|
||||
private boolean hasOAuthMethods(List<CodegenSecurity> authMethods) {
|
||||
for (CodegenSecurity cs : authMethods) {
|
||||
if (cs.isOAuth) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private List<CodegenSecurity> getOAuthMethods(List<CodegenSecurity> authMethods) {
|
||||
List<CodegenSecurity> oauthMethods = new ArrayList<>();
|
||||
|
||||
for (CodegenSecurity cs : authMethods) {
|
||||
if (cs.isOAuth) {
|
||||
oauthMethods.add(cs);
|
||||
}
|
||||
}
|
||||
|
||||
return oauthMethods;
|
||||
}
|
||||
}
|
||||
|
@ -18,9 +18,10 @@ import org.threeten.bp.LocalDate;
|
||||
import org.threeten.bp.OffsetDateTime;
|
||||
import org.threeten.bp.format.DateTimeFormatter;
|
||||
{{/threetenbp}}
|
||||
|
||||
{{#hasOAuthMethods}}
|
||||
import org.apache.oltu.oauth2.client.request.OAuthClientRequest.TokenRequestBuilder;
|
||||
import org.apache.oltu.oauth2.common.message.types.GrantType;
|
||||
{{/hasOAuthMethods}}
|
||||
|
||||
import javax.net.ssl.*;
|
||||
import java.io.File;
|
||||
@ -92,7 +93,10 @@ public class ApiClient {
|
||||
// Prevent the authentications from being modified.
|
||||
authentications = Collections.unmodifiableMap(authentications);
|
||||
}
|
||||
{{#authMethods}}{{#isOAuth}}
|
||||
|
||||
{{#hasOAuthMethods}}
|
||||
{{#oauthMethods}}
|
||||
{{#-first}}
|
||||
/*
|
||||
* Constructor for ApiClient to support access token retry on 401/403 configured with client ID
|
||||
*/
|
||||
@ -123,7 +127,10 @@ public class ApiClient {
|
||||
// Prevent the authentications from being modified.
|
||||
authentications = Collections.unmodifiableMap(authentications);
|
||||
}
|
||||
{{/isOAuth}}{{/authMethods}}
|
||||
|
||||
{{/-first}}
|
||||
{{/oauthMethods}}
|
||||
{{/hasOAuthMethods}}
|
||||
private void init() {
|
||||
httpClient = new OkHttpClient();
|
||||
|
||||
|
@ -119,12 +119,14 @@ if(hasProperty('target') && target == 'android') {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile 'io.swagger:swagger-annotations:1.5.17'
|
||||
compile 'io.swagger:swagger-annotations:1.5.21'
|
||||
compile 'com.squareup.okhttp:okhttp:2.7.5'
|
||||
compile 'com.squareup.okhttp:logging-interceptor:2.7.5'
|
||||
compile 'com.google.code.gson:gson:2.8.1'
|
||||
compile 'com.google.code.gson:gson:2.8.5'
|
||||
compile 'io.gsonfire:gson-fire:1.8.0'
|
||||
{{#hasOAuthMethods}}
|
||||
compile group: 'org.apache.oltu.oauth2', name: 'org.apache.oltu.oauth2.client', version: '1.0.1'
|
||||
{{/hasOAuthMethods}}
|
||||
compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.8.1'
|
||||
{{#joda}}
|
||||
compile 'joda-time:joda-time:2.9.9'
|
||||
|
@ -9,11 +9,14 @@ lazy val root = (project in file(".")).
|
||||
publishArtifact in (Compile, packageDoc) := false,
|
||||
resolvers += Resolver.mavenLocal,
|
||||
libraryDependencies ++= Seq(
|
||||
"io.swagger" % "swagger-annotations" % "1.5.17",
|
||||
"io.swagger" % "swagger-annotations" % "1.5.21",
|
||||
"com.squareup.okhttp" % "okhttp" % "2.7.5",
|
||||
"com.squareup.okhttp" % "logging-interceptor" % "2.7.5",
|
||||
"com.google.code.gson" % "gson" % "2.8.1",
|
||||
"com.google.code.gson" % "gson" % "2.8.5",
|
||||
"org.apache.commons" % "commons-lang3" % "3.8.1",
|
||||
{{#hasOAuthMethods}}
|
||||
"org.apache.oltu.oauth2" % "org.apache.oltu.oauth2.client" % "1.0.1",
|
||||
{{/hasOAuthMethods}}
|
||||
{{#joda}}
|
||||
"joda-time" % "joda-time" % "2.9.9" % "compile",
|
||||
{{/joda}}
|
||||
|
@ -220,11 +220,13 @@
|
||||
<artifactId>gson-fire</artifactId>
|
||||
<version>${gson-fire-version}</version>
|
||||
</dependency>
|
||||
{{#hasOAuthMethods}}
|
||||
<dependency>
|
||||
<groupId>org.apache.oltu.oauth2</groupId>
|
||||
<artifactId>org.apache.oltu.oauth2.client</artifactId>
|
||||
<version>1.0.1</version>
|
||||
</dependency>
|
||||
{{/hasOAuthMethods}}
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
@ -288,9 +290,9 @@
|
||||
<maven.compiler.source>${java.version}</maven.compiler.source>
|
||||
<maven.compiler.target>${java.version}</maven.compiler.target>
|
||||
<gson-fire-version>1.8.0</gson-fire-version>
|
||||
<swagger-core-version>1.5.18</swagger-core-version>
|
||||
<swagger-core-version>1.5.21</swagger-core-version>
|
||||
<okhttp-version>2.7.5</okhttp-version>
|
||||
<gson-version>2.8.1</gson-version>
|
||||
<gson-version>2.8.5</gson-version>
|
||||
<commons-lang3-version>3.8.1</commons-lang3-version>
|
||||
{{#joda}}
|
||||
<jodatime-version>2.9.9</jodatime-version>
|
||||
|
@ -95,10 +95,10 @@ if(hasProperty('target') && target == 'android') {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile 'io.swagger:swagger-annotations:1.5.17'
|
||||
compile 'io.swagger:swagger-annotations:1.5.21'
|
||||
compile 'com.squareup.okhttp:okhttp:2.7.5'
|
||||
compile 'com.squareup.okhttp:logging-interceptor:2.7.5'
|
||||
compile 'com.google.code.gson:gson:2.8.1'
|
||||
compile 'com.google.code.gson:gson:2.8.5'
|
||||
compile 'io.gsonfire:gson-fire:1.8.0'
|
||||
compile group: 'org.apache.oltu.oauth2', name: 'org.apache.oltu.oauth2.client', version: '1.0.1'
|
||||
compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.8.1'
|
||||
|
@ -9,11 +9,12 @@ lazy val root = (project in file(".")).
|
||||
publishArtifact in (Compile, packageDoc) := false,
|
||||
resolvers += Resolver.mavenLocal,
|
||||
libraryDependencies ++= Seq(
|
||||
"io.swagger" % "swagger-annotations" % "1.5.17",
|
||||
"io.swagger" % "swagger-annotations" % "1.5.21",
|
||||
"com.squareup.okhttp" % "okhttp" % "2.7.5",
|
||||
"com.squareup.okhttp" % "logging-interceptor" % "2.7.5",
|
||||
"com.google.code.gson" % "gson" % "2.8.1",
|
||||
"com.google.code.gson" % "gson" % "2.8.5",
|
||||
"org.apache.commons" % "commons-lang3" % "3.8.1",
|
||||
"org.apache.oltu.oauth2" % "org.apache.oltu.oauth2.client" % "1.0.1",
|
||||
"org.threeten" % "threetenbp" % "1.3.5" % "compile",
|
||||
"io.gsonfire" % "gson-fire" % "1.8.0" % "compile",
|
||||
"junit" % "junit" % "4.12" % "test",
|
||||
|
@ -248,9 +248,9 @@
|
||||
<maven.compiler.source>${java.version}</maven.compiler.source>
|
||||
<maven.compiler.target>${java.version}</maven.compiler.target>
|
||||
<gson-fire-version>1.8.0</gson-fire-version>
|
||||
<swagger-core-version>1.5.18</swagger-core-version>
|
||||
<swagger-core-version>1.5.21</swagger-core-version>
|
||||
<okhttp-version>2.7.5</okhttp-version>
|
||||
<gson-version>2.8.1</gson-version>
|
||||
<gson-version>2.8.5</gson-version>
|
||||
<commons-lang3-version>3.8.1</commons-lang3-version>
|
||||
<threetenbp-version>1.3.5</threetenbp-version>
|
||||
<maven-plugin-version>1.0.0</maven-plugin-version>
|
||||
|
@ -22,7 +22,6 @@ import okio.Okio;
|
||||
import org.threeten.bp.LocalDate;
|
||||
import org.threeten.bp.OffsetDateTime;
|
||||
import org.threeten.bp.format.DateTimeFormatter;
|
||||
|
||||
import org.apache.oltu.oauth2.client.request.OAuthClientRequest.TokenRequestBuilder;
|
||||
import org.apache.oltu.oauth2.common.message.types.GrantType;
|
||||
|
||||
@ -92,7 +91,7 @@ public class ApiClient {
|
||||
// Prevent the authentications from being modified.
|
||||
authentications = Collections.unmodifiableMap(authentications);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Constructor for ApiClient to support access token retry on 401/403 configured with client ID
|
||||
*/
|
||||
@ -123,7 +122,7 @@ public class ApiClient {
|
||||
// Prevent the authentications from being modified.
|
||||
authentications = Collections.unmodifiableMap(authentications);
|
||||
}
|
||||
|
||||
|
||||
private void init() {
|
||||
httpClient = new OkHttpClient();
|
||||
|
||||
|
@ -95,10 +95,10 @@ if(hasProperty('target') && target == 'android') {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile 'io.swagger:swagger-annotations:1.5.17'
|
||||
compile 'io.swagger:swagger-annotations:1.5.21'
|
||||
compile 'com.squareup.okhttp:okhttp:2.7.5'
|
||||
compile 'com.squareup.okhttp:logging-interceptor:2.7.5'
|
||||
compile 'com.google.code.gson:gson:2.8.1'
|
||||
compile 'com.google.code.gson:gson:2.8.5'
|
||||
compile 'io.gsonfire:gson-fire:1.8.0'
|
||||
compile group: 'org.apache.oltu.oauth2', name: 'org.apache.oltu.oauth2.client', version: '1.0.1'
|
||||
compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.8.1'
|
||||
|
@ -9,11 +9,12 @@ lazy val root = (project in file(".")).
|
||||
publishArtifact in (Compile, packageDoc) := false,
|
||||
resolvers += Resolver.mavenLocal,
|
||||
libraryDependencies ++= Seq(
|
||||
"io.swagger" % "swagger-annotations" % "1.5.17",
|
||||
"io.swagger" % "swagger-annotations" % "1.5.21",
|
||||
"com.squareup.okhttp" % "okhttp" % "2.7.5",
|
||||
"com.squareup.okhttp" % "logging-interceptor" % "2.7.5",
|
||||
"com.google.code.gson" % "gson" % "2.8.1",
|
||||
"com.google.code.gson" % "gson" % "2.8.5",
|
||||
"org.apache.commons" % "commons-lang3" % "3.8.1",
|
||||
"org.apache.oltu.oauth2" % "org.apache.oltu.oauth2.client" % "1.0.1",
|
||||
"org.threeten" % "threetenbp" % "1.3.5" % "compile",
|
||||
"io.gsonfire" % "gson-fire" % "1.8.0" % "compile",
|
||||
"junit" % "junit" % "4.12" % "test",
|
||||
|
@ -241,9 +241,9 @@
|
||||
<maven.compiler.source>${java.version}</maven.compiler.source>
|
||||
<maven.compiler.target>${java.version}</maven.compiler.target>
|
||||
<gson-fire-version>1.8.0</gson-fire-version>
|
||||
<swagger-core-version>1.5.18</swagger-core-version>
|
||||
<swagger-core-version>1.5.21</swagger-core-version>
|
||||
<okhttp-version>2.7.5</okhttp-version>
|
||||
<gson-version>2.8.1</gson-version>
|
||||
<gson-version>2.8.5</gson-version>
|
||||
<commons-lang3-version>3.8.1</commons-lang3-version>
|
||||
<threetenbp-version>1.3.5</threetenbp-version>
|
||||
<maven-plugin-version>1.0.0</maven-plugin-version>
|
||||
|
@ -22,7 +22,6 @@ import okio.Okio;
|
||||
import org.threeten.bp.LocalDate;
|
||||
import org.threeten.bp.OffsetDateTime;
|
||||
import org.threeten.bp.format.DateTimeFormatter;
|
||||
|
||||
import org.apache.oltu.oauth2.client.request.OAuthClientRequest.TokenRequestBuilder;
|
||||
import org.apache.oltu.oauth2.common.message.types.GrantType;
|
||||
|
||||
@ -92,7 +91,7 @@ public class ApiClient {
|
||||
// Prevent the authentications from being modified.
|
||||
authentications = Collections.unmodifiableMap(authentications);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Constructor for ApiClient to support access token retry on 401/403 configured with client ID
|
||||
*/
|
||||
@ -123,7 +122,7 @@ public class ApiClient {
|
||||
// Prevent the authentications from being modified.
|
||||
authentications = Collections.unmodifiableMap(authentications);
|
||||
}
|
||||
|
||||
|
||||
private void init() {
|
||||
httpClient = new OkHttpClient();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user