Skip to content
This repository has been archived by the owner on Aug 20, 2021. It is now read-only.

Commit

Permalink
feat(api): Define response templates to override policy response
Browse files Browse the repository at this point in the history
  • Loading branch information
brasseld committed Mar 28, 2019
1 parent 942b11c commit 1b8b73f
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import io.gravitee.definition.model.Path;
import io.gravitee.definition.model.Properties;
import io.gravitee.definition.model.Proxy;
import io.gravitee.definition.model.ResponseTemplates;
import io.gravitee.definition.model.plugins.resources.Resource;
import io.gravitee.definition.model.services.Services;
import io.gravitee.management.model.DeploymentRequired;
Expand Down Expand Up @@ -112,6 +113,10 @@ public class ApiEntity implements Indexable {
@JsonIgnore
private Map<String, Object> metadata = new HashMap<>();

@DeploymentRequired
@JsonProperty(value = "response_templates")
private Map<String, ResponseTemplates> responseTemplates;

public String getId() {
return id;
}
Expand Down Expand Up @@ -304,6 +309,14 @@ public void setMetadata(Map<String, Object> metadata) {
this.metadata = metadata;
}

public Map<String, ResponseTemplates> getResponseTemplates() {
return responseTemplates;
}

public void setResponseTemplates(Map<String, ResponseTemplates> responseTemplates) {
this.responseTemplates = responseTemplates;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import io.gravitee.definition.model.Path;
import io.gravitee.definition.model.Properties;
import io.gravitee.definition.model.Proxy;
import io.gravitee.definition.model.ResponseTemplates;
import io.gravitee.definition.model.plugins.resources.Resource;
import io.gravitee.definition.model.services.Services;
import io.gravitee.management.model.Visibility;
Expand Down Expand Up @@ -70,6 +71,9 @@ public class UpdateApiEntity {
@JsonProperty(value = "path_mappings")
private Set<String> pathMappings;

@JsonProperty(value = "response_templates")
private Map<String, ResponseTemplates> responseTemplates;

public Visibility getVisibility() {
return visibility;
}
Expand Down Expand Up @@ -189,4 +193,12 @@ public Set<String> getPathMappings() {
public void setPathMappings(Set<String> pathMappings) {
this.pathMappings = pathMappings;
}

public Map<String, ResponseTemplates> getResponseTemplates() {
return responseTemplates;
}

public void setResponseTemplates(Map<String, ResponseTemplates> responseTemplates) {
this.responseTemplates = responseTemplates;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ public enum ApiPermission implements Permission {
DISCOVERY( "DISCOVERY", 2400),
NOTIFICATION( "NOTIFICATION", 2500),
MESSAGE( "MESSAGE", 2600),
ALERT( "ALERT", 2700);
ALERT( "ALERT", 2700),
RESPONSE_TEMPLATES( "RESPONSE_TEMPLATES", 2800);

String name;
int mask;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public enum RolePermission {
API_NOTIFICATION (RoleScope.API, ApiPermission.NOTIFICATION),
API_MESSAGE (RoleScope.API, ApiPermission.MESSAGE),
API_ALERT (RoleScope.API, ApiPermission.ALERT),
API_RESPONSE_TEMPLATES (RoleScope.API, ApiPermission.RESPONSE_TEMPLATES),

APPLICATION_DEFINITION (RoleScope.APPLICATION, ApplicationPermission.DEFINITION),
APPLICATION_MEMBER (RoleScope.APPLICATION, ApplicationPermission.MEMBER),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1442,6 +1442,7 @@ private ApiEntity convert(Api api, UserEntity primaryOwner) {
if (apiDefinition.getPathMappings() != null) {
apiEntity.setPathMappings(new HashSet<>(apiDefinition.getPathMappings().keySet()));
}
apiEntity.setResponseTemplates(apiDefinition.getResponseTemplates());
} catch (IOException ioe) {
LOGGER.error("Unexpected error while generating API definition", ioe);
}
Expand Down Expand Up @@ -1503,6 +1504,7 @@ private Api convert(String apiId, UpdateApiEntity updateApiEntity) {
apiDefinition.setPathMappings(updateApiEntity.getPathMappings().stream()
.collect(toMap(pathMapping -> pathMapping, pathMapping -> Pattern.compile(""))));
}
apiDefinition.setResponseTemplates(updateApiEntity.getResponseTemplates());

String definition = objectMapper.writeValueAsString(apiDefinition);
api.setDefinition(definition);
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

<properties>
<gravitee-node.version>1.3.0</gravitee-node.version>
<gravitee-definition.version>1.17.0</gravitee-definition.version>
<gravitee-definition.version>1.18.0-SNAPSHOT</gravitee-definition.version>
<gravitee-common.version>1.14.0</gravitee-common.version>
<gravitee-plugin.version>1.7.0</gravitee-plugin.version>
<gravitee-repository.version>1.24.0</gravitee-repository.version>
Expand Down

0 comments on commit 1b8b73f

Please sign in to comment.