Skip to content
Permalink
Browse files

feat: Create mocks in API imported from swagger/OAI

  • Loading branch information...
aelamrani committed Feb 14, 2019
1 parent 53c4cc7 commit e91bc27b42d22b2894adc2bafafef5a95babb76c
@@ -15,6 +15,8 @@
*/
package io.gravitee.management.model;

import com.fasterxml.jackson.annotation.JsonProperty;

import javax.validation.constraints.NotNull;

/**
@@ -27,6 +29,14 @@

@NotNull
private String payload;
@JsonProperty("with_documentation")
private boolean withDocumentation;
@JsonProperty("with_path_mapping")
private boolean withPathMapping;
@JsonProperty("with_policy_paths")
private boolean withPolicyPaths;
@JsonProperty("with_policy_mocks")
private boolean withPolicyMocks;

public Type getType() {
return type;
@@ -44,6 +54,38 @@ public void setPayload(String payload) {
this.payload = payload;
}

public boolean isWithDocumentation() {
return withDocumentation;
}

public void setWithDocumentation(boolean withDocumentation) {
this.withDocumentation = withDocumentation;
}

public boolean isWithPathMapping() {
return withPathMapping;
}

public void setWithPathMapping(boolean withPathMapping) {
this.withPathMapping = withPathMapping;
}

public boolean isWithPolicyPaths() {
return withPolicyPaths;
}

public void setWithPolicyPaths(boolean withPolicyPaths) {
this.withPolicyPaths = withPolicyPaths;
}

public boolean isWithPolicyMocks() {
return withPolicyMocks;
}

public void setWithPolicyMocks(boolean withPolicyMocks) {
this.withPolicyMocks = withPolicyMocks;
}

public enum Type {
INLINE,
URL
@@ -0,0 +1,109 @@
/**
* Copyright (C) 2015 The Gravitee team (http://gravitee.io)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.gravitee.management.model.api;

import javax.validation.constraints.NotNull;
import java.util.List;
import java.util.Set;

/**
* @author Azize ELAMRANI (azize.elamrani at graviteesource.com)
* @author GraviteeSource Team
*/
public class NewSwaggerApiEntity {

@NotNull
private String name;
@NotNull
private String version;
@NotNull
private String description;
@NotNull
private String contextPath;
@NotNull
private String endpoint;
private Set<String> groups;
private List<SwaggerPath> paths;

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getVersion() {
return version;
}

public void setVersion(String version) {
this.version = version;
}

public String getDescription() {
return description;
}

public void setDescription(String description) {
this.description = description;
}

public String getContextPath() {
return contextPath;
}

public void setContextPath(String contextPath) {
this.contextPath = contextPath;
}

public String getEndpoint() {
return endpoint;
}

public void setEndpoint(String endpoint) {
this.endpoint = endpoint;
}

public List<SwaggerPath> getPaths() {
return paths;
}

public void setPaths(List<SwaggerPath> paths) {
this.paths = paths;
}

public Set<String> getGroups() {
return groups;
}

public void setGroups(Set<String> groups) {
this.groups = groups;
}

@Override
public String toString() {
return "NewSwaggerApiEntity{" +
"name='" + name + '\'' +
", version='" + version + '\'' +
", description='" + description + '\'' +
", contextPath='" + contextPath + '\'' +
", endpoint='" + endpoint + '\'' +
", groups=" + groups +
", paths=" + paths +
'}';
}
}
@@ -0,0 +1,44 @@
/**
* Copyright (C) 2015 The Gravitee team (http://gravitee.io)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.gravitee.management.model.api;

import java.util.List;

/**
* @author Azize ELAMRANI (azize.elamrani at graviteesource.com)
* @author GraviteeSource Team
*/
public class SwaggerPath {

private String path;
private List<SwaggerVerb> verbs;

public String getPath() {
return path;
}

public void setPath(String path) {
this.path = path;
}

public List<SwaggerVerb> getVerbs() {
return verbs;
}

public void setVerbs(List<SwaggerVerb> verbs) {
this.verbs = verbs;
}
}
@@ -0,0 +1,71 @@
/**
* Copyright (C) 2015 The Gravitee team (http://gravitee.io)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.gravitee.management.model.api;

import java.util.Map;

/**
* @author Azize ELAMRANI (azize.elamrani at graviteesource.com)
* @author GraviteeSource Team
*/
public class SwaggerVerb {

private String verb;
private String description;
private String responseStatus;
private String responseType;
private Map<String, Object> responseProperties;

public String getVerb() {
return verb;
}

public void setVerb(String verb) {
this.verb = verb;
}

public String getDescription() {
return description;
}

public void setDescription(String description) {
this.description = description;
}

public String getResponseStatus() {
return responseStatus;
}

public void setResponseStatus(String responseStatus) {
this.responseStatus = responseStatus;
}

public String getResponseType() {
return responseType;
}

public void setResponseType(String responseType) {
this.responseType = responseType;
}

public Map<String, Object> getResponseProperties() {
return responseProperties;
}

public void setResponseProperties(Map<String, Object> responseProperties) {
this.responseProperties = responseProperties;
}
}
@@ -186,14 +186,18 @@ public Response importDefinition(
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Create an API definition from a Swagger descriptor")
@ApiResponses({
@ApiResponse(code = 200, message = "API definition from Swagger descriptor", response = NewApiEntity.class),
@ApiResponse(code = 200, message = "API definition from Swagger descriptor", response = ApiEntity.class),
@ApiResponse(code = 500, message = "Internal server error")})
@Permissions({
@Permission(value = RolePermission.MANAGEMENT_API, acls = RolePermissionAction.CREATE)
})
public NewApiEntity importSwagger(
public Response importSwagger(
@ApiParam(name = "swagger", required = true) @Valid @NotNull ImportSwaggerDescriptorEntity swaggerDescriptor) {
return swaggerService.prepare(swaggerDescriptor);
final ApiEntity api = apiService.create(swaggerService.prepare(swaggerDescriptor), getAuthenticatedUser(), swaggerDescriptor);
return Response
.created(URI.create("/apis/" + api.getId()))
.entity(api)
.build();
}

@POST
@@ -15,14 +15,8 @@
*/
package io.gravitee.management.service;

import io.gravitee.management.model.ApiModelEntity;
import io.gravitee.management.model.EventType;
import io.gravitee.management.model.InlinePictureEntity;
import io.gravitee.management.model.Visibility;
import io.gravitee.management.model.api.ApiEntity;
import io.gravitee.management.model.api.ApiQuery;
import io.gravitee.management.model.api.NewApiEntity;
import io.gravitee.management.model.api.UpdateApiEntity;
import io.gravitee.management.model.*;
import io.gravitee.management.model.api.*;
import io.gravitee.management.model.api.header.ApiHeaderEntity;
import io.gravitee.repository.exceptions.TechnicalException;

@@ -46,6 +40,7 @@
Set<ApiEntity> findByVisibility(Visibility visibility);

ApiEntity create(NewApiEntity api, String userId);
ApiEntity create(NewSwaggerApiEntity api, String userId, ImportSwaggerDescriptorEntity swaggerDescriptor);

ApiEntity update(String apiId, UpdateApiEntity api);

@@ -16,8 +16,8 @@
package io.gravitee.management.service;

import io.gravitee.management.model.ImportSwaggerDescriptorEntity;
import io.gravitee.management.model.api.NewApiEntity;
import io.gravitee.management.model.PageEntity;
import io.gravitee.management.model.api.NewSwaggerApiEntity;

/**
* @author David BRASSELY (david.brassely at graviteesource.com)
@@ -32,7 +32,7 @@
* @param swaggerDescriptor Swagger descriptor
* @return The API from the Swagger descriptor
*/
NewApiEntity prepare(ImportSwaggerDescriptorEntity swaggerDescriptor);
NewSwaggerApiEntity prepare(ImportSwaggerDescriptorEntity swaggerDescriptor);

void transform(PageEntity page);
}
Oops, something went wrong.

0 comments on commit e91bc27

Please sign in to comment.
You can’t perform that action at this time.