io.swagger.models.Operation Java Examples

The following examples show how to use io.swagger.models.Operation. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: OperationsTransformer.java    From spring-openapi with MIT License 6 votes vote down vote up
private Operation mapOperation(String operationName, HttpMethod httpMethod, Method method, String[] produces, String[] consumes, String controllerClassName) {
	Operation operation = new Operation();
	operation.setOperationId(getOperationId(operationName, method, httpMethod));
	operation.setSummary(StringUtils.isBlank(operationName) ? operationName : method.getName());
	operation.setTags(singletonList(classNameToTag(controllerClassName)));

	operation.setResponses(createApiResponses(method));
	operation.setParameters(transformParameters(method));
	if (isNotEmpty(consumes)) {
		operation.setConsumes(asList(consumes));
	}
	if (isNotEmpty(produces)) {
		operation.setProduces(asList(produces));
	}

	if (isHttpMethodWithRequestBody(httpMethod)) {
		io.swagger.models.parameters.Parameter requestBody = createRequestBody(method, getFirstFromArray(consumes));
		if (requestBody != null) {
			operation.getParameters().add(requestBody);
		}
	}

	applyAnnotationsForOperation(operation, method.getAnnotations());
	operationInterceptors.forEach(interceptor -> interceptor.intercept(method, operation));
	return operation;
}
 
Example #2
Source File: SwaggerInventory.java    From swagger-parser with Apache License 2.0 6 votes vote down vote up
public void process(Operation operation) {
    this.operations.add(operation);
    Iterator var2;
    if(operation.getParameters() != null) {
        var2 = operation.getParameters().iterator();

        while(var2.hasNext()) {
            Parameter key = (Parameter)var2.next();
            this.process(key);
        }
    }

    if(operation.getResponses() != null) {
        var2 = operation.getResponses().keySet().iterator();

        while(var2.hasNext()) {
            String key1 = (String)var2.next();
            Response response = (Response)operation.getResponses().get(key1);
            this.process(response);
        }
    }

}
 
Example #3
Source File: SwaggerRouter.java    From vertx-swagger with Apache License 2.0 6 votes vote down vote up
private static AuthHandler getAuthHandler(SwaggerAuthHandlerFactory authHandlerFactory, Swagger swagger, Operation operation) {
    AuthHandler authHandler = null;
    if(authHandlerFactory != null) {
        if(operation.getSecurity() != null) {
        	if(!operation.getSecurity().isEmpty()) {
        		authHandler = authHandlerFactory.createAuthHandler(operation.getSecurity());
        	}
        } else if(swagger.getSecurity() != null && !swagger.getSecurity().isEmpty()) {
            List<Map<String, List<String>>> security = swagger.getSecurity().stream()
                    .map(SecurityRequirement::getRequirements)
                    .collect(Collectors.toList());
            authHandler = authHandlerFactory.createAuthHandler(security);
        }
    }

    return authHandler;
}
 
Example #4
Source File: DocumentationDrivenValidator.java    From assertj-swagger with Apache License 2.0 6 votes vote down vote up
private void validateOperation(Operation actualOperation, Operation expectedOperation, String path, String httpMethod) {
    String message = String.format("Checking '%s' operation of path '%s'", httpMethod, path);
    if (expectedOperation != null) {
        softAssertions.assertThat(actualOperation).as(message).isNotNull();
        if (actualOperation != null) {
            //Validate consumes
            validateList(schemaObjectResolver.getActualConsumes(actualOperation),
                    schemaObjectResolver.getExpectedConsumes(expectedOperation),
                    String.format("Checking '%s' of '%s' operation of path '%s'", "consumes", httpMethod, path));
            //Validate produces
            validateList(schemaObjectResolver.getActualProduces(actualOperation),
                    schemaObjectResolver.getExpectedProduces(expectedOperation),
                    String.format("Checking '%s' of '%s' operation of path '%s'", "produces", httpMethod, path));
            //Validate parameters
            validateParameters(actualOperation.getParameters(), expectedOperation.getParameters(), httpMethod, path);
            //Validate responses
            validateResponses(actualOperation.getResponses(), expectedOperation.getResponses(), httpMethod, path);
        }
    } else {
        softAssertions.assertThat(actualOperation).as(message).isNull();
    }
}
 
Example #5
Source File: TestApiOperation.java    From servicecomb-java-chassis with Apache License 2.0 6 votes vote down vote up
private void testBase(Path path) {
  Assert.assertEquals(1, path.getOperations().size());

  Operation operation = path.getGet();

  Assert.assertEquals("summary", operation.getSummary());
  Assert.assertEquals("notes", operation.getDescription());
  Assert.assertEquals(Arrays.asList("tag1", "tag2"), operation.getTags());
  Assert.assertEquals(Arrays.asList("application/json"), operation.getProduces());
  Assert.assertEquals(Arrays.asList("application/json"), operation.getConsumes());
  Assert.assertEquals(Arrays.asList(Scheme.HTTP, Scheme.HTTPS), operation.getSchemes());

  Map<String, Response> responseMap = operation.getResponses();
  Assert.assertEquals(2, responseMap.size());

  Response response = responseMap.get(SwaggerConst.SUCCESS_KEY);
  Assert.assertNotNull(response);
  Assert.assertEquals(null, response.getResponseSchema());

  response = responseMap.get("202");
  Assert.assertNotNull(response);
  Assert.assertEquals(null, response.getResponseSchema());

  Assert.assertEquals(1, response.getHeaders().size());
  Assert.assertEquals("integer", response.getHeaders().get("h1").getType());
}
 
Example #6
Source File: RestControllerProcessor.java    From herd with Apache License 2.0 6 votes vote down vote up
/**
 * Processes the return value of a RequestMapping annotated method.
 *
 * @param returnType the return type.
 * @param operation the operation.
 * @param returnDescription the description of the return value.
 *
 * @throws MojoExecutionException if the return type isn't an XmlType.
 */
private void processRestMethodReturnValue(Class<?> returnType, Operation operation, String returnDescription) throws MojoExecutionException
{
    log.debug("Processing REST method return value \"" + returnType.getName() + "\".");

    // Add the class name to the list of classes which we will create an example for.
    exampleClassNames.add(returnType.getSimpleName());

    // Add the success response
    operation.response(200, new Response().description(returnDescription == null ? "Success" : returnDescription)
        .schema(new RefProperty(getXmlType(returnType).name().trim())));

    // If we have an error class, add that as the default response.
    if (modelErrorClass != null)
    {
        operation.defaultResponse(new Response().description("General Error").schema(new RefProperty(getXmlType(modelErrorClass).name().trim())));
    }
}
 
Example #7
Source File: PostOperationGenerator.java    From yang2swagger with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public Operation execute(DataSchemaNode node) {
    final Operation post = dropLastSegmentParameters ? listOperation() : defaultOperation();
    final RefModel definition = new RefModel(getDefinitionId(node));
    post.summary("creates " + getName(node));
    String description = node.getDescription() == null ? "creates " + getName(node) :
            node.getDescription();
    post.description(description);
    post.parameter(new BodyParameter()
            .name(getName(node) + ".body-param")
            .schema(definition)
            .description(getName(node) + " to be added to list"));

    post.response(201, new Response().description("Object created"));
    post.response(409, new Response().description("Object already exists"));
    return post;
}
 
Example #8
Source File: SwaggerGeneratorTest.java    From endpoints-java with Apache License 2.0 6 votes vote down vote up
private void checkDuplicateOperations(Swagger actual) {
  Multimap<String, String> operationIds = HashMultimap.create();
  for (Entry<String, Path> pathEntry : actual.getPaths().entrySet()) {
    for (Entry<HttpMethod, Operation> opEntry : pathEntry.getValue().getOperationMap()
        .entrySet()) {
      operationIds
          .put(opEntry.getValue().getOperationId(), pathEntry.getKey() + "|" + opEntry.getKey());
    }
  }
  int duplicateOperationIdCount = 0;
  for (Entry<String, Collection<String>> entry : operationIds.asMap().entrySet()) {
    if (entry.getValue().size() > 1) {
      System.out.println("Duplicate operation id: " + entry);
      duplicateOperationIdCount++;
    }
  }
  assertThat(duplicateOperationIdCount).named("Duplicate operation ids").isEqualTo(0);
}
 
Example #9
Source File: PutOperationGenerator.java    From yang2swagger with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public Operation execute(DataSchemaNode node) {
    final Operation put = defaultOperation();
    final RefModel definition = new RefModel(getDefinitionId(node));
    put.summary("creates or updates " + getName(node));
    String description = node.getDescription() == null ? "creates or updates " + getName(node) :
            node.getDescription();
    put.description(description);
    put.parameter(new BodyParameter()
            .name(getName(node) + ".body-param")
            .schema(definition)
            .description(getName(node) + " to be added or updated"));

    put.response(201, new Response().description("Object created"));
    put.response(204, new Response().description("Object modified"));
    return put;
}
 
Example #10
Source File: TestResponsesMeta.java    From servicecomb-java-chassis with Apache License 2.0 6 votes vote down vote up
@Test
public void test() {
  Swagger swagger = SwaggerGenerator.generate(ResponseMetaImpl.class);
  Operation operation = swagger.getPath("/add").getPost();

  ResponsesMeta meta = new ResponsesMeta();
  meta.init(swagger, operation);

  JavaType resp = meta.findResponseType(200);
  Assert.assertEquals(Integer.class, resp.getRawClass());

  resp = meta.findResponseType(201);
  Assert.assertEquals(Integer.class, resp.getRawClass());

  resp = meta.findResponseType(400);
  Assert.assertEquals(String.class, resp.getRawClass());

  resp = meta.findResponseType(401);
  Assert.assertEquals(Long.class, resp.getRawClass());

  resp = meta.findResponseType(500);
  // changed to Object for new version to keep user defined error data not lose and can be parsed.
  Assert.assertEquals(Object.class, resp.getRawClass());
}
 
Example #11
Source File: ApiGatewaySdkSwaggerApiImporter.java    From aws-apigateway-importer with Apache License 2.0 6 votes vote down vote up
private Boolean isApiKeyRequired(Operation op) {
    Optional<Map.Entry<String, SecuritySchemeDefinition>> apiKeySecurityDefinition = Optional.empty();

    if (swagger.getSecurityDefinitions() != null) {
        apiKeySecurityDefinition = swagger.getSecurityDefinitions().entrySet()
                .stream().filter(p -> p.getValue().getType().equals("apiKey")).findFirst();
    }

    if (!apiKeySecurityDefinition.isPresent()) {
        return false;
    }

    String securityDefinitionName = apiKeySecurityDefinition.get().getKey();

    if (op.getSecurity() != null) {
        return op.getSecurity().stream().anyMatch(s -> s.containsKey(securityDefinitionName));
    }
    if (swagger.getSecurityRequirement() != null) {
        return swagger.getSecurityRequirement().stream().anyMatch(s -> s.getName().equals(securityDefinitionName));
    }
    return false;
}
 
Example #12
Source File: CppRestClientCodegen.java    From TypeScript-Microservices with MIT License 6 votes vote down vote up
@Override
public CodegenOperation fromOperation(String path, String httpMethod, Operation operation,
        Map<String, Model> definitions, Swagger swagger) {
    CodegenOperation op = super.fromOperation(path, httpMethod, operation, definitions, swagger);

    if (operation.getResponses() != null && !operation.getResponses().isEmpty()) {
        Response methodResponse = findMethodResponse(operation.getResponses());

        if (methodResponse != null) {
            if (methodResponse.getSchema() != null) {
                CodegenProperty cm = fromProperty("response", methodResponse.getSchema());
                op.vendorExtensions.put("x-codegen-response", cm);
                if(cm.datatype == "HttpContent")
                {
                    op.vendorExtensions.put("x-codegen-response-ishttpcontent", true);
                }
            }
        }
    }

    return op;
}
 
Example #13
Source File: Reader.java    From dorado with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("deprecation")
private void addResponse(Operation operation, ApiResponse apiResponse, JsonView jsonView) {
	Map<String, Property> responseHeaders = parseResponseHeaders(apiResponse.responseHeaders(), jsonView);
	Map<String, Object> examples = parseExamples(apiResponse.examples());

	Response response = new Response().description(apiResponse.message()).headers(responseHeaders);
	response.setExamples(examples);

	if (apiResponse.code() == 0) {
		operation.defaultResponse(response);
	} else {
		operation.response(apiResponse.code(), response);
	}

	if (StringUtils.isNotEmpty(apiResponse.reference())) {
		response.schema(new RefProperty(apiResponse.reference()));
	} else if (!isVoid(apiResponse.response())) {
		Type responseType = apiResponse.response();
		final Property property = ModelConverters.getInstance().readAsProperty(responseType, jsonView);
		if (property != null) {
			response.schema(ContainerWrapper.wrapContainer(apiResponse.responseContainer(), property));
			appendModels(responseType);
		}
	}
}
 
Example #14
Source File: OperationsTransformer.java    From spring-openapi with MIT License 6 votes vote down vote up
private void mapRequestMapping(RequestMapping requestMapping, Method method, Map<String, Path> operationsMap, String controllerClassName,
							   String baseControllerPath) {
	List<HttpMethod> httpMethods = Arrays.stream(requestMapping.method())
										 .map(this::getSpringMethod)
										 .collect(toList());
	httpMethods.forEach(httpMethod -> {
		Operation operation = mapOperation(requestMapping.name(), httpMethod, method, requestMapping.produces(),
										   requestMapping.consumes(), controllerClassName);

		String path = ObjectUtils.defaultIfNull(getFirstFromArray(requestMapping.value()), getFirstFromArray(requestMapping.path()));
		updateOperationsMap(prepareUrl(baseControllerPath, "/", path), operationsMap,
							pathItem -> setContentBasedOnHttpMethod(pathItem, httpMethod, operation)
		);
	});

}
 
Example #15
Source File: SwaggerCodegen.java    From mdw with Apache License 2.0 6 votes vote down vote up
@Override
public CodegenOperation fromOperation(String path, String httpMethod, Operation operation,
        Map<String, Model> definitions, Swagger swagger) {
    CodegenOperation op = super.fromOperation(path, httpMethod, operation, definitions,
            swagger);
    op.imports.add("Map");
    op.imports.remove("Request");
    op.imports.remove("Response");
    if (validateRequest) {
        op.imports.remove("Result");
    }

    if (generatedFlowBasePackage != null) {
        ProcessNamer processNamer = new ProcessNamer(generatedFlowBasePackage, path);
        String processName = processNamer.getPackage() + "/"
                + processNamer.getName(op.httpMethod);
        op.vendorExtensions.put("generatedFlow", processName);
    }

    return op;
}
 
Example #16
Source File: SwaggerUtils.java    From micro-integrator with Apache License 2.0 6 votes vote down vote up
/**
 * This method will generate path and query parameters in the swagger document.
 *
 * @param method        method of API resource.
 * @param operation     swagger operation object.
 * @param parameterList list of parameters.
 */
private static void generatePathAndQueryParameters(String method, Operation operation,
                                                   List<AxisResourceParameter> parameterList) {

    if (!parameterList.isEmpty()) {
        for (AxisResourceParameter resourceParameter : parameterList) {
            AxisResourceParameter.ParameterType resourceParameterType =
                    resourceParameter.getParameterType();
            if (resourceParameterType.equals(AxisResourceParameter.ParameterType.URL_PARAMETER)) {
                PathParameter pathParameter = new PathParameter();
                pathParameter.setName(resourceParameter.getParameterName());
                pathParameter.setType(resourceParameter.getParameterDataType());
                pathParameter.required(true);
                operation.addParameter(pathParameter);
            } else if (resourceParameterType
                    .equals(AxisResourceParameter.ParameterType.QUERY_PARAMETER) && "GET".equals(method)) {
                //  Currently handling query parameter only for GET requests.
                QueryParameter queryParameter = new QueryParameter();
                queryParameter.setName(resourceParameter.getParameterName());
                queryParameter.setType(resourceParameter.getParameterDataType());
                queryParameter.required(true);
                operation.addParameter(queryParameter);
            }
        }
    }
}
 
Example #17
Source File: PlantUMLCodegen.java    From swagger2puml with Apache License 2.0 5 votes vote down vote up
/**
 * 
 * @param operation
 * @return
 */
private List<MethodDefinitions> getInterfaceMethods(Operation operation) {
	List<MethodDefinitions> interfaceMethods = new ArrayList<MethodDefinitions>();
	MethodDefinitions methodDefinitions = new MethodDefinitions();
	methodDefinitions.setMethodDefinition(new StringBuilder().append(operation.getOperationId()).append("(")
			.append(getMethodParameters(operation)).append(")").toString());
	methodDefinitions.setReturnType(getInterfaceReturnType(operation));

	interfaceMethods.add(methodDefinitions);

	return interfaceMethods;
}
 
Example #18
Source File: ProtoApiFromOpenApi.java    From api-compiler with Apache License 2.0 5 votes vote down vote up
private void createServiceMethodsFromPath(
    Service.Builder serviceBuilder,
    String urlPath,
    Path pathObj,
    Map<String, String> duplicateOperationIdLookup) {
  Map<String, Operation> operations = getOperationsForPath(pathObj);
  for (String operationType : operations.keySet()) {
    Operation operation = operations.get(operationType);
    if (operation == null) {
      continue;
    }
    if (!validateOperationId(
        operation, urlPath, operationType, diagCollector, duplicateOperationIdLookup)) {
      continue;
    }

    addMethodFromOperation(serviceBuilder, operation, pathObj, operationType, urlPath);
    serviceBuilder
        .getHttpBuilder()
        .addRules(httpRuleGenerator.createHttpRule(operation, pathObj, operationType, urlPath));
    AuthenticationRule authRule =
        authRuleGenerator.createAuthRule(operation, operationType, urlPath);
    if (authRule != null) {
      serviceBuilder.getAuthenticationBuilder().addRules(authRule);
    }
    MetricRule metricRule = metricRuleGenerator.createMetricRule(operation);
    if (metricRule != null) {
      checkMatchingMetrics(serviceBuilder, metricRule);
      serviceBuilder.getQuotaBuilder().addMetricRules(metricRule);
    }
    serviceBuilder
        .getUsageBuilder()
        .addRules(authBuilder.createUsageRule(operation, operationType, urlPath));
  }
}
 
Example #19
Source File: ConverterMgrTest.java    From servicecomb-java-chassis with Apache License 2.0 5 votes vote down vote up
@Test
public void should_support_array_model() {
  Operation operation = swagger.getPath("/nestedListString").getPost();
  Model model = operation.getResponses().get("200").getResponseSchema();
  assertThat(SwaggerUtils.getClassName(model.getVendorExtensions())).isNull();
  assertThat(ConverterMgr.findJavaType(swagger, model).getRawClass()).isEqualTo(List.class);
}
 
Example #20
Source File: AbstractOktaJavaClientCodegen.java    From okta-sdk-java with Apache License 2.0 5 votes vote down vote up
@Override
public CodegenOperation fromOperation(String path,
                                      String httpMethod,
                                      Operation operation,
                                      Map<String, Model> definitions,
                                      Swagger swagger) {
    CodegenOperation co = super.fromOperation(path,
            httpMethod,
            operation,
            definitions,
            swagger);

    // scan params for X_OPENAPI_V3_SCHEMA_REF, and _correct_ the param
    co.allParams.forEach(param -> {
        if (param.vendorExtensions.containsKey(X_OPENAPI_V3_SCHEMA_REF)) {
            String enumDef = param.vendorExtensions.get(X_OPENAPI_V3_SCHEMA_REF).toString().replaceFirst(".*/","");
            param.isEnum = true;
            param.enumName = enumDef;
            param.dataType = enumDef;
        }
    });

    // mark the operation as having optional params, so we can take advantage of it in the template
    addOptionalExtensionAndBackwardCompatibleArgs(co, co.allParams);

    // if the body and the return type are the same mark the body param
    co.bodyParams.forEach(bodyParam -> {
        if (bodyParam.dataType.equals(co.returnType)) {
            co.vendorExtensions.put("updateBody", true);
        }
    });

    return co;
}
 
Example #21
Source File: ApiGatewaySdkSwaggerApiImporter.java    From aws-apigateway-importer with Apache License 2.0 5 votes vote down vote up
private Map<String, Operation> getOperations(Path path) {
    final Map<String, Operation> ops = new HashMap<>();

    addOp(ops, "get", path.getGet());
    addOp(ops, "post", path.getPost());
    addOp(ops, "put", path.getPut());
    addOp(ops, "delete", path.getDelete());
    addOp(ops, "options", path.getOptions());
    addOp(ops, "patch", path.getPatch());

    return ops;
}
 
Example #22
Source File: Reader.java    From dorado with Apache License 2.0 5 votes vote down vote up
private void readExternalDocs(Method method, Operation operation) {
	io.swagger.annotations.ExternalDocs externalDocs = ReflectionUtils.getAnnotation(method,
			io.swagger.annotations.ExternalDocs.class);
	if (externalDocs != null) {
		operation.setExternalDocs(new ExternalDocs(externalDocs.value(), externalDocs.url()));
	}
}
 
Example #23
Source File: OperationsFilter.java    From herd with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isOperationAllowed(
        Operation operation,
        ApiDescription api,
        Map<String, List<String>> params,
        Map<String, String> cookies,
        Map<String, List<String>> headers)
{
    return allowedOperations == null ||
            allowedOperations.size() == 0 ||
            allowedOperations.stream().anyMatch(op -> operation.getOperationId().equalsIgnoreCase(op))
            ;
}
 
Example #24
Source File: Reader.java    From dorado with Apache License 2.0 5 votes vote down vote up
private void processImplicitParams(ApiImplicitParams implicitParams, Operation operation) {
	if (implicitParams != null) {
		for (ApiImplicitParam param : implicitParams.value()) {
			Parameter p = readImplicitParam(param);
			if (p != null) {
				operation.addParameter(p);
			}
		}
	}
}
 
Example #25
Source File: ApiOperationProcessor.java    From servicecomb-java-chassis with Apache License 2.0 5 votes vote down vote up
private void convertProtocols(String protocols, Operation operation) {
  if (protocols == null) {
    return;
  }

  for (String protocol : protocols.split(SEPARATOR)) {
    if (StringUtils.isEmpty(protocol)) {
      continue;
    }

    operation.addScheme(Scheme.forValue(protocol));
  }
}
 
Example #26
Source File: SwaggerUtils.java    From servicecomb-java-chassis with Apache License 2.0 5 votes vote down vote up
public static void setCommaProduces(Operation operation, String commaProduces) {
  if (StringUtils.isEmpty(commaProduces)) {
    return;
  }

  setProduces(operation, commaProduces.split(","));
}
 
Example #27
Source File: ResourceReaderExtension.java    From mdw with Apache License 2.0 5 votes vote down vote up
@Override
public void applyTags(ReaderContext context, Operation operation, Method method) {
    super.applyTags(context, operation, method);

    Class<?> declaringClass = method.getDeclaringClass();
    Api apiAnnotation = declaringClass.getAnnotation(Api.class);
    if (apiAnnotation != null && apiAnnotation.value() != null && !apiAnnotation.value().isEmpty()) {
        operation.addTag(apiAnnotation.value());
    }
}
 
Example #28
Source File: PathUtils.java    From swagger2markup with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the operations of a path as a map which preserves the insertion order.
 *
 * @param path the path
 * @return the operations of a path as a map
 */
private static Map<HttpMethod, Operation> getOperationMap(Path path) {
    Map<HttpMethod, Operation> result = new LinkedHashMap<>();

    if (path.getGet() != null) {
        result.put(HttpMethod.GET, path.getGet());
    }
    if (path.getPut() != null) {
        result.put(HttpMethod.PUT, path.getPut());
    }
    if (path.getPost() != null) {
        result.put(HttpMethod.POST, path.getPost());
    }
    if (path.getDelete() != null) {
        result.put(HttpMethod.DELETE, path.getDelete());
    }
    if (path.getPatch() != null) {
        result.put(HttpMethod.PATCH, path.getPatch());
    }
    if (path.getHead() != null) {
        result.put(HttpMethod.HEAD, path.getHead());
    }
    if (path.getOptions() != null) {
        result.put(HttpMethod.OPTIONS, path.getOptions());
    }

    return result;
}
 
Example #29
Source File: PlantUMLCodegen.java    From swagger2puml with Apache License 2.0 5 votes vote down vote up
/**
 * 
 * @param operation
 * @return
 */
private List<ClassRelation> getInterfaceRelations(Operation operation,String errorClassName) {
	List<ClassRelation> relations = new ArrayList<ClassRelation>();
	relations.addAll(getInterfaceRelatedResponses(operation));
	relations.addAll(getInterfaceRelatedInputs(operation));
	if(StringUtils.isNotEmpty(errorClassName))
	{
		relations.add(getErrorClass(errorClassName));
	}
	
	return filterUnique(relations,true);
}
 
Example #30
Source File: JavaInflectorServerCodegen.java    From TypeScript-Microservices with MIT License 5 votes vote down vote up
@Override
public void addOperationToGroup(String tag, String resourcePath, Operation operation, CodegenOperation co, Map<String, List<CodegenOperation>> operations) {
    String basePath = resourcePath;
    if (basePath.startsWith("/")) {
        basePath = basePath.substring(1);
    }
    int pos = basePath.indexOf("/");
    if (pos > 0) {
        basePath = basePath.substring(0, pos);
    }

    if (basePath == "") {
        basePath = "default";
    } else {
        if (co.path.startsWith("/" + basePath)) {
            co.path = co.path.substring(("/" + basePath).length());
        }
        co.subresourceOperation = !co.path.isEmpty();
    }
    List<CodegenOperation> opList = operations.get(basePath);
    if (opList == null) {
        opList = new ArrayList<CodegenOperation>();
        operations.put(basePath, opList);
    }
    opList.add(co);
    co.baseName = basePath;
}