Skip to content

Commit 07e4b97

Browse files
authored
Merge pull request #165 from entur/upgrade-openapi-generator-maven-plugin
Upgrade openapi generator maven plugin
2 parents f0ae622 + cc7a0c7 commit 07e4b97

File tree

4 files changed

+53
-80
lines changed

4 files changed

+53
-80
lines changed

gbfs-validator-java-api/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
<junit.version>6.0.0</junit.version>
4141
<mockito.version>5.11.0</mockito.version>
4242
<junit-platform.version>6.0.0</junit-platform.version>
43-
<openapi-generator-maven-plugin>6.0.0</openapi-generator-maven-plugin>
43+
<openapi-generator-maven-plugin>7.16.0</openapi-generator-maven-plugin>
4444
</properties>
4545

4646
<dependencyManagement>

gbfs-validator-java-api/src/main/java/org/entur/gbfs/validator/api/handler/ValidateApiDelegateHandler.java

Lines changed: 42 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,8 @@
3636
import org.entur.gbfs.validation.model.ValidationResult;
3737
import org.entur.gbfs.validation.model.ValidatorError;
3838
import org.entur.gbfs.validator.api.gen.ValidateApiDelegate;
39-
import org.entur.gbfs.validator.api.model.BasicAuth;
40-
import org.entur.gbfs.validator.api.model.BearerTokenAuth;
4139
import org.entur.gbfs.validator.api.model.FileError;
4240
import org.entur.gbfs.validator.api.model.GbfsFile;
43-
import org.entur.gbfs.validator.api.model.OAuthClientCredentialsGrantAuth;
4441
import org.entur.gbfs.validator.api.model.SystemError;
4542
import org.entur.gbfs.validator.api.model.ValidatePostRequest;
4643
import org.entur.gbfs.validator.api.model.ValidatePostRequestAuth;
@@ -113,40 +110,7 @@ public ResponseEntity<org.entur.gbfs.validator.api.model.ValidationResult> valid
113110
validatePostRequest.getFeedUrl()
114111
);
115112
try {
116-
Authentication loaderAuth = null;
117-
ValidatePostRequestAuth apiAuth = validatePostRequest.getAuth();
118-
119-
if (apiAuth != null) {
120-
if (apiAuth instanceof BasicAuth basic) {
121-
if (basic.getUsername() != null && basic.getPassword() != null) {
122-
loaderAuth =
123-
new org.entur.gbfs.validator.loader.auth.BasicAuth(
124-
basic.getUsername(),
125-
basic.getPassword()
126-
);
127-
}
128-
} else if (apiAuth instanceof BearerTokenAuth bearer) {
129-
if (bearer.getToken() != null) {
130-
loaderAuth =
131-
new org.entur.gbfs.validator.loader.auth.BearerTokenAuth(
132-
bearer.getToken()
133-
);
134-
}
135-
} else if (apiAuth instanceof OAuthClientCredentialsGrantAuth oauth) {
136-
if (
137-
oauth.getClientId() != null &&
138-
oauth.getClientSecret() != null &&
139-
oauth.getTokenUrl() != null
140-
) {
141-
loaderAuth =
142-
new org.entur.gbfs.validator.loader.auth.OAuthClientCredentialsGrantAuth(
143-
oauth.getClientId(),
144-
oauth.getClientSecret(),
145-
oauth.getTokenUrl().toString()
146-
);
147-
}
148-
}
149-
}
113+
Authentication loaderAuth = getAuthentication(validatePostRequest);
150114

151115
List<LoadedFile> allLoadedFiles = loader.load(
152116
validatePostRequest.getFeedUrl(),
@@ -210,6 +174,47 @@ public ResponseEntity<org.entur.gbfs.validator.api.model.ValidationResult> valid
210174
}
211175
}
212176

177+
private static Authentication getAuthentication(
178+
ValidatePostRequest validatePostRequest
179+
) {
180+
Authentication loaderAuth = null;
181+
ValidatePostRequestAuth apiAuth = validatePostRequest.getAuth();
182+
183+
if (apiAuth != null) {
184+
String authType = apiAuth.getAuthType();
185+
if ("basicAuth".equals(authType)) {
186+
if (apiAuth.getUsername() != null && apiAuth.getPassword() != null) {
187+
loaderAuth =
188+
new org.entur.gbfs.validator.loader.auth.BasicAuth(
189+
apiAuth.getUsername(),
190+
apiAuth.getPassword()
191+
);
192+
}
193+
} else if ("bearerToken".equals(authType)) {
194+
if (apiAuth.getToken() != null) {
195+
loaderAuth =
196+
new org.entur.gbfs.validator.loader.auth.BearerTokenAuth(
197+
apiAuth.getToken()
198+
);
199+
}
200+
} else if ("oauthClientCredentialsGrant".equals(authType)) {
201+
if (
202+
apiAuth.getClientId() != null &&
203+
apiAuth.getClientSecret() != null &&
204+
apiAuth.getTokenUrl() != null
205+
) {
206+
loaderAuth =
207+
new org.entur.gbfs.validator.loader.auth.OAuthClientCredentialsGrantAuth(
208+
apiAuth.getClientId(),
209+
apiAuth.getClientSecret(),
210+
apiAuth.getTokenUrl()
211+
);
212+
}
213+
}
214+
}
215+
return loaderAuth;
216+
}
217+
213218
private org.entur.gbfs.validator.api.model.ValidationResult mergeValidationResults(
214219
List<org.entur.gbfs.validator.api.model.ValidationResult> results
215220
) {

gbfs-validator-java-api/src/test/java/org/entur/gbfs/validator/api/TestApplication.java

Lines changed: 0 additions & 32 deletions
This file was deleted.

gbfs-validator-java-api/src/test/java/org/entur/gbfs/validator/api/ValidateIntegrationTest.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
66

77
import com.fasterxml.jackson.databind.ObjectMapper;
8+
import org.entur.gbfs.validator.api.handler.OpenApiGeneratorApplication;
89
import org.entur.gbfs.validator.api.model.*;
910
import org.junit.jupiter.api.Test;
1011
import org.springframework.beans.factory.annotation.Autowired;
@@ -13,7 +14,7 @@
1314
import org.springframework.http.MediaType;
1415
import org.springframework.test.web.servlet.MockMvc;
1516

16-
@SpringBootTest(classes = TestApplication.class)
17+
@SpringBootTest(classes = OpenApiGeneratorApplication.class)
1718
@AutoConfigureMockMvc
1819
public class ValidateIntegrationTest {
1920

@@ -46,8 +47,8 @@ void testValidate_BasicAuth_Success() throws Exception {
4647
ValidatePostRequest request = new ValidatePostRequest();
4748
request.setFeedUrl("http://example.com/gbfs.json");
4849

49-
BasicAuth basicAuth = new BasicAuth();
50-
basicAuth.setAuthType("basic");
50+
ValidatePostRequestAuth basicAuth = new ValidatePostRequestAuth();
51+
basicAuth.setAuthType("basicAuth");
5152
basicAuth.setUsername("user");
5253
basicAuth.setPassword("pass");
5354
request.setAuth(basicAuth);
@@ -69,8 +70,8 @@ void testValidate_BearerTokenAuth_Success() throws Exception {
6970
ValidatePostRequest request = new ValidatePostRequest();
7071
request.setFeedUrl("http://example.com/gbfs.json");
7172

72-
BearerTokenAuth bearerAuth = new BearerTokenAuth();
73-
bearerAuth.setAuthType("bearer");
73+
ValidatePostRequestAuth bearerAuth = new ValidatePostRequestAuth();
74+
bearerAuth.setAuthType("bearerToken");
7475
bearerAuth.setToken("token123");
7576
request.setAuth(bearerAuth);
7677

@@ -91,9 +92,8 @@ void testValidate_OAuthClientCredentials_Success() throws Exception {
9192
ValidatePostRequest request = new ValidatePostRequest();
9293
request.setFeedUrl("http://example.com/gbfs.json");
9394

94-
OAuthClientCredentialsGrantAuth oauthAuth =
95-
new OAuthClientCredentialsGrantAuth();
96-
oauthAuth.setAuthType("oauth");
95+
ValidatePostRequestAuth oauthAuth = new ValidatePostRequestAuth();
96+
oauthAuth.setAuthType("oauthClientCredentialsGrant");
9797
oauthAuth.setTokenUrl("https://auth.example.com/token");
9898
oauthAuth.setClientId("client_id");
9999
oauthAuth.setClientSecret("client_secret");
@@ -116,8 +116,8 @@ void testValidate_AuthFailure() throws Exception {
116116
ValidatePostRequest request = new ValidatePostRequest();
117117
request.setFeedUrl("http://example.com/gbfs.json");
118118

119-
BasicAuth basicAuth = new BasicAuth();
120-
basicAuth.setAuthType("basic");
119+
ValidatePostRequestAuth basicAuth = new ValidatePostRequestAuth();
120+
basicAuth.setAuthType("basicAuth");
121121
basicAuth.setUsername("wrong_user");
122122
basicAuth.setPassword("wrong_password");
123123
request.setAuth(basicAuth);

0 commit comments

Comments
 (0)