This repository has been archived by the owner on Jan 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* #43 added testcase for securedby_with_uses (test will FAIL) TODO implementation needs to be changed to generate constructor with user/password. * #43 forgot to add "securedBy:" (test will still FAIL) TODO implementation needs to be changed to generate constructor with user/password. * #43 find SecurityScheme referenced by SecuredBy as well (e.g. via uses:) TODO implementation needs to be changed to generate constructor with user/password.
- Loading branch information
1 parent
06e2eb2
commit 7b3082a
Showing
17 changed files
with
682 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
raml-client-generator-core/src/test/resources/v1/securedby_with_uses/api.raml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#%RAML 1.0 | ||
version: api | ||
title: BuyosExperienceLayer | ||
baseUri: http://localhost:24045/api | ||
|
||
uses: | ||
candaCommons: canda-commons/1.0.8/canda-commons.raml | ||
|
||
securedBy: [candaCommons.basicAuth] | ||
|
||
# Workaround as https://github.com/mulesoft-labs/raml-java-client-generator | ||
# does not detect securitySchemes placed in the "uses" section. | ||
#securitySchemes: | ||
# clientid: | ||
# description: Client ID Policy | ||
# type: Basic Authentication | ||
|
||
#securedBy: [clientid] | ||
|
||
/users/{id}: | ||
get: | ||
responses: | ||
200: | ||
body: | ||
application/json: | ||
example: | | ||
{ "userId": "foo" } | ||
15 changes: 15 additions & 0 deletions
15
...tor-core/src/test/resources/v1/securedby_with_uses/canda-commons/1.0.8/canda-commons.raml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#%RAML 1.0 Library | ||
|
||
securitySchemes: | ||
basicAuth: | ||
displayName: Basic Authentication | ||
description: This API supports Basic Authentication. The client has to provide an "Authorization" header with valid credentials. | ||
type: Basic Authentication | ||
describedBy: | ||
headers: | ||
Authorization: | ||
description: Used to send valid credentials. | ||
type: string | ||
responses: | ||
401: | ||
description: Credentials are missing or could not be validated by the server. |
44 changes: 44 additions & 0 deletions
44
...ces/v1/securedby_with_uses/output/securedby_with_uses/api/BuyosExperienceLayerClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
|
||
package securedby_with_uses.api; | ||
|
||
import javax.ws.rs.client.ClientBuilder; | ||
import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature; | ||
import securedby_with_uses.resource.users.Users; | ||
|
||
public class BuyosExperienceLayerClient { | ||
|
||
private static java.lang.String username; | ||
private static java.lang.String password; | ||
private java.lang.String _baseUrl; | ||
public final Users users; | ||
|
||
public BuyosExperienceLayerClient(java.lang.String baseUrl, java.lang.String username, java.lang.String password) { | ||
this.username = username; | ||
this.password = password; | ||
_baseUrl = baseUrl; | ||
users = new Users(getBaseUri(), getClient()); | ||
} | ||
|
||
public BuyosExperienceLayerClient(java.lang.String username, java.lang.String password) { | ||
this("http://localhost:24045/api", username, password); | ||
} | ||
|
||
protected javax.ws.rs.client.Client getClient() { | ||
final javax.ws.rs.client.Client _client = ClientBuilder.newClient(); | ||
_client.register(HttpAuthenticationFeature.basic(username, password)); | ||
return _client; | ||
} | ||
|
||
protected java.lang.String getBaseUri() { | ||
return _baseUrl; | ||
} | ||
|
||
public static BuyosExperienceLayerClient create(java.lang.String baseUrl, java.lang.String username, java.lang.String password) { | ||
return new BuyosExperienceLayerClient(baseUrl, username, password); | ||
} | ||
|
||
public static BuyosExperienceLayerClient create(java.lang.String username, java.lang.String password) { | ||
return new BuyosExperienceLayerClient(username, password); | ||
} | ||
|
||
} |
44 changes: 44 additions & 0 deletions
44
...uredby_with_uses/output/securedby_with_uses/exceptions/BuyosExperienceLayerException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
|
||
package securedby_with_uses.exceptions; | ||
|
||
import javax.ws.rs.core.MultivaluedMap; | ||
import javax.ws.rs.core.Response; | ||
|
||
public class BuyosExperienceLayerException | ||
extends RuntimeException | ||
{ | ||
|
||
private int statusCode; | ||
private String reason; | ||
private MultivaluedMap<String, String> headers; | ||
private Response response; | ||
|
||
public BuyosExperienceLayerException(int statusCode, String reason, MultivaluedMap<String, String> headers, Response response) { | ||
super(reason); | ||
this.statusCode = statusCode; | ||
this.reason = reason; | ||
this.headers = headers; | ||
this.response = response; | ||
} | ||
|
||
public BuyosExperienceLayerException(int statusCode, String reason) { | ||
this(statusCode, reason, null, null); | ||
} | ||
|
||
public int getStatusCode() { | ||
return this.statusCode; | ||
} | ||
|
||
public String getReason() { | ||
return this.reason; | ||
} | ||
|
||
public MultivaluedMap<String, String> getHeaders() { | ||
return this.headers; | ||
} | ||
|
||
public Response getResponse() { | ||
return this.response; | ||
} | ||
|
||
} |
34 changes: 34 additions & 0 deletions
34
...est/resources/v1/securedby_with_uses/output/securedby_with_uses/resource/users/Users.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
|
||
package securedby_with_uses.resource.users; | ||
|
||
import javax.ws.rs.client.Client; | ||
import securedby_with_uses.resource.users.id.Id; | ||
|
||
public class Users { | ||
|
||
private String _baseUrl; | ||
private Client _client; | ||
|
||
public Users() { | ||
_baseUrl = null; | ||
_client = null; | ||
} | ||
|
||
public Users(String baseUrl, Client _client) { | ||
_baseUrl = (baseUrl +"/users"); | ||
this._client = _client; | ||
} | ||
|
||
protected Client getClient() { | ||
return this._client; | ||
} | ||
|
||
private String getBaseUri() { | ||
return _baseUrl; | ||
} | ||
|
||
public Id id(String id) { | ||
return new Id(getBaseUri(), getClient(), id); | ||
} | ||
|
||
} |
46 changes: 46 additions & 0 deletions
46
...est/resources/v1/securedby_with_uses/output/securedby_with_uses/resource/users/id/Id.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
|
||
package securedby_with_uses.resource.users.id; | ||
|
||
import java.net.URLEncoder; | ||
import javax.ws.rs.client.Client; | ||
import javax.ws.rs.client.WebTarget; | ||
import javax.ws.rs.core.MediaType; | ||
import javax.ws.rs.core.Response; | ||
import javax.ws.rs.core.Response.Status.Family; | ||
import securedby_with_uses.exceptions.BuyosExperienceLayerException; | ||
|
||
public class Id { | ||
|
||
private String _baseUrl; | ||
private Client _client; | ||
|
||
public Id() { | ||
_baseUrl = null; | ||
_client = null; | ||
} | ||
|
||
public Id(String baseUrl, Client _client, String uriParam) { | ||
_baseUrl = (baseUrl +("/"+ URLEncoder.encode(uriParam))); | ||
this._client = _client; | ||
} | ||
|
||
protected Client getClient() { | ||
return this._client; | ||
} | ||
|
||
private String getBaseUri() { | ||
return _baseUrl; | ||
} | ||
|
||
public securedby_with_uses.resource.users.id.model.IdGETResponse get() { | ||
WebTarget target = this._client.target(getBaseUri()); | ||
final javax.ws.rs.client.Invocation.Builder invocationBuilder = target.request(MediaType.APPLICATION_JSON_TYPE); | ||
Response response = invocationBuilder.get(); | ||
if (response.getStatusInfo().getFamily()!= Family.SUCCESSFUL) { | ||
Response.StatusType statusInfo = response.getStatusInfo(); | ||
throw new BuyosExperienceLayerException(statusInfo.getStatusCode(), statusInfo.getReasonPhrase(), response.getStringHeaders(), response); | ||
} | ||
return response.readEntity(securedby_with_uses.resource.users.id.model.IdGETResponse.class); | ||
} | ||
|
||
} |
110 changes: 110 additions & 0 deletions
110
...securedby_with_uses/output/securedby_with_uses/resource/users/id/model/IdGETResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
|
||
package securedby_with_uses.resource.users.id.model; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import com.fasterxml.jackson.annotation.JsonAnyGetter; | ||
import com.fasterxml.jackson.annotation.JsonAnySetter; | ||
import com.fasterxml.jackson.annotation.JsonIgnore; | ||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.fasterxml.jackson.annotation.JsonPropertyOrder; | ||
|
||
@JsonInclude(JsonInclude.Include.NON_NULL) | ||
@JsonPropertyOrder({ | ||
"userId" | ||
}) | ||
public class IdGETResponse { | ||
|
||
@JsonProperty("userId") | ||
private String userId; | ||
@JsonIgnore | ||
private Map<String, Object> additionalProperties = new HashMap<String, Object>(); | ||
|
||
/** | ||
* No args constructor for use in serialization | ||
* | ||
*/ | ||
public IdGETResponse() { | ||
} | ||
|
||
/** | ||
* | ||
* @param userId | ||
*/ | ||
public IdGETResponse(String userId) { | ||
super(); | ||
this.userId = userId; | ||
} | ||
|
||
@JsonProperty("userId") | ||
public String getUserId() { | ||
return userId; | ||
} | ||
|
||
@JsonProperty("userId") | ||
public void setUserId(String userId) { | ||
this.userId = userId; | ||
} | ||
|
||
public IdGETResponse withUserId(String userId) { | ||
this.userId = userId; | ||
return this; | ||
} | ||
|
||
@JsonAnyGetter | ||
public Map<String, Object> getAdditionalProperties() { | ||
return this.additionalProperties; | ||
} | ||
|
||
@JsonAnySetter | ||
public void setAdditionalProperty(String name, Object value) { | ||
this.additionalProperties.put(name, value); | ||
} | ||
|
||
public IdGETResponse withAdditionalProperty(String name, Object value) { | ||
this.additionalProperties.put(name, value); | ||
return this; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
StringBuilder sb = new StringBuilder(); | ||
sb.append(IdGETResponse.class.getName()).append('@').append(Integer.toHexString(System.identityHashCode(this))).append('['); | ||
sb.append("userId"); | ||
sb.append('='); | ||
sb.append(((this.userId == null)?"<null>":this.userId)); | ||
sb.append(','); | ||
sb.append("additionalProperties"); | ||
sb.append('='); | ||
sb.append(((this.additionalProperties == null)?"<null>":this.additionalProperties)); | ||
sb.append(','); | ||
if (sb.charAt((sb.length()- 1)) == ',') { | ||
sb.setCharAt((sb.length()- 1), ']'); | ||
} else { | ||
sb.append(']'); | ||
} | ||
return sb.toString(); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
int result = 1; | ||
result = ((result* 31)+((this.userId == null)? 0 :this.userId.hashCode())); | ||
result = ((result* 31)+((this.additionalProperties == null)? 0 :this.additionalProperties.hashCode())); | ||
return result; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
if (other == this) { | ||
return true; | ||
} | ||
if ((other instanceof IdGETResponse) == false) { | ||
return false; | ||
} | ||
IdGETResponse rhs = ((IdGETResponse) other); | ||
return (((this.userId == rhs.userId)||((this.userId!= null)&&this.userId.equals(rhs.userId)))&&((this.additionalProperties == rhs.additionalProperties)||((this.additionalProperties!= null)&&this.additionalProperties.equals(rhs.additionalProperties)))); | ||
} | ||
|
||
} |
28 changes: 28 additions & 0 deletions
28
raml-client-generator-core/src/test/resources/v2/securedby_with_uses/api.raml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#%RAML 1.0 | ||
version: api | ||
title: BuyosExperienceLayer | ||
baseUri: http://localhost:24045/api | ||
|
||
uses: | ||
candaCommons: canda-commons/1.0.8/canda-commons.raml | ||
|
||
securedBy: [candaCommons.basicAuth] | ||
|
||
# Workaround as https://github.com/mulesoft-labs/raml-java-client-generator | ||
# does not detect securitySchemes placed in the "uses" section. | ||
#securitySchemes: | ||
# clientid: | ||
# description: Client ID Policy | ||
# type: Basic Authentication | ||
|
||
#securedBy: [clientid] | ||
|
||
/users/{id}: | ||
get: | ||
responses: | ||
200: | ||
body: | ||
application/json: | ||
example: | | ||
{ "userId": "foo" } | ||
15 changes: 15 additions & 0 deletions
15
...tor-core/src/test/resources/v2/securedby_with_uses/canda-commons/1.0.8/canda-commons.raml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#%RAML 1.0 Library | ||
|
||
securitySchemes: | ||
basicAuth: | ||
displayName: Basic Authentication | ||
description: This API supports Basic Authentication. The client has to provide an "Authorization" header with valid credentials. | ||
type: Basic Authentication | ||
describedBy: | ||
headers: | ||
Authorization: | ||
description: Used to send valid credentials. | ||
type: string | ||
responses: | ||
401: | ||
description: Credentials are missing or could not be validated by the server. |
Oops, something went wrong.