Java Code Examples for io.swagger.v3.oas.models.Operation#setExtensions()
The following examples show how to use
io.swagger.v3.oas.models.Operation#setExtensions() .
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: PhpZendExpressivePathHandlerServerCodegen.java From openapi-generator with Apache License 2.0 | 5 votes |
protected void addInternalExtensionToOperation(Operation operation, String name, Object value) { //Add internal extension directly, because addExtension filters extension names if (operation.getExtensions() == null) { operation.setExtensions(new HashMap<>()); } operation.getExtensions().put(name, value); }
Example 2
Source File: OASMergeUtilTest.java From crnk-framework with Apache License 2.0 | 5 votes |
@Test public void testMergeOperations() { Operation thatOperation = new Operation(); Operation thisOperation = new Operation(); thisOperation.setOperationId("new id"); thisOperation.setSummary("new summary"); thisOperation.setDescription("new description"); Map<String, Object> extensions = new HashMap<>(); extensions.put("new schema", new Schema()); thisOperation.setExtensions(extensions); Assert.assertSame(thisOperation, OASMergeUtil.mergeOperations(thisOperation, null)); Operation afterMerge = OASMergeUtil.mergeOperations(thatOperation, thisOperation); Assert.assertEquals("new id", afterMerge.getOperationId()); Assert.assertEquals("new summary", afterMerge.getSummary()); Assert.assertEquals("new description", afterMerge.getDescription()); Assert.assertSame(extensions, afterMerge.getExtensions()); thatOperation.setOperationId("existing id"); thatOperation.setSummary("existing summary"); thatOperation.setDescription("existing description"); Map<String, Object> existingExtensions = new HashMap<>(); extensions.put("existing schema", new Schema()); thisOperation.setExtensions(extensions); afterMerge = OASMergeUtil.mergeOperations(thisOperation, thatOperation); Assert.assertEquals("existing id", afterMerge.getOperationId()); Assert.assertEquals("existing summary", afterMerge.getSummary()); Assert.assertEquals("existing description", afterMerge.getDescription()); Assert.assertSame(extensions, afterMerge.getExtensions()); }
Example 3
Source File: ScalaGatlingCodegen.java From openapi-generator with Apache License 2.0 | 4 votes |
/** * Modifies the openapi doc to make mustache easier to use * * @param openAPI input openapi document */ @Override public void preprocessOpenAPI(OpenAPI openAPI) { for (String pathname : openAPI.getPaths().keySet()) { PathItem path = openAPI.getPaths().get(pathname); if (path.readOperations() == null) { continue; } for (Operation operation : path.readOperations()) { if (operation.getExtensions() == null) { operation.setExtensions(new HashMap()); } if (!operation.getExtensions().keySet().contains("x-gatling-path")) { if (pathname.contains("{")) { String gatlingPath = pathname.replaceAll("\\{", "\\$\\{"); operation.addExtension("x-gatling-path", gatlingPath); } else { operation.addExtension("x-gatling-path", pathname); } } Set<Parameter> headerParameters = new HashSet<>(); Set<Parameter> formParameters = new HashSet<>(); Set<Parameter> queryParameters = new HashSet<>(); Set<Parameter> pathParameters = new HashSet<>(); if (operation.getParameters() != null) { for (Parameter parameter : operation.getParameters()) { if (parameter.getIn().equalsIgnoreCase("header")) { headerParameters.add(parameter); } /* need to revise below as form parameter is no longer in the parameter list if (parameter.getIn().equalsIgnoreCase("formData")) { formParameters.add(parameter); } */ if (parameter.getIn().equalsIgnoreCase("query")) { queryParameters.add(parameter); } if (parameter.getIn().equalsIgnoreCase("path")) { pathParameters.add(parameter); } /* TODO need to revise below as body is no longer in the parameter if (parameter.getIn().equalsIgnoreCase("body")) { BodyParameter bodyParameter = (BodyParameter) parameter; Model model = bodyParameter.getSchema(); if (model instanceof RefModel) { String[] refArray = model.getReference().split("\\/"); operation.setVendorExtension("x-gatling-body-object", refArray[refArray.length - 1] + ".toStringBody"); Set<String> bodyFeederParams = new HashSet<>(); Set<String> sessionBodyVars = new HashSet<>(); for (Map.Entry<String, Model> modelEntry : swagger.getDefinitions().entrySet()) { if (refArray[refArray.length - 1].equalsIgnoreCase(modelEntry.getKey())) { for (Map.Entry<String, Property> propertyEntry : modelEntry.getValue().getProperties().entrySet()) { bodyFeederParams.add(propertyEntry.getKey()); sessionBodyVars.add("\"${" + propertyEntry.getKey() + "}\""); } } } operation.setVendorExtension("x-gatling-body-feeder", operation.getOperationId() + "BodyFeeder"); operation.setVendorExtension("x-gatling-body-feeder-params", StringUtils.join(sessionBodyVars, ",")); try { FileUtils.writeStringToFile( new File(outputFolder + File.separator + dataFolder + File.separator + operation.getOperationId() + "-" + "bodyParams.csv"), StringUtils.join(bodyFeederParams, ","), StandardCharsets.UTF_8 ); } catch (IOException ioe) { LOGGER.error("Could not create feeder file for operationId" + operation.getOperationId(), ioe); } } else if (model instanceof ArrayModel) { operation.setVendorExtension("x-gatling-body-object", "StringBody(\"[]\")"); } else { operation.setVendorExtension("x-gatling-body-object", "StringBody(\"{}\")"); } } */ } } prepareGatlingData(operation, headerParameters, "header"); prepareGatlingData(operation, formParameters, "form"); prepareGatlingData(operation, queryParameters, "query"); prepareGatlingData(operation, pathParameters, "path"); } } }
Example 4
Source File: OASMergeUtil.java From crnk-framework with Apache License 2.0 | 4 votes |
public static Operation mergeOperations(Operation thisOperation, Operation thatOperation) { if (thatOperation == null) { return thisOperation; } if (thatOperation.getTags() != null) { thisOperation.setTags( mergeTags(thisOperation.getTags(), thatOperation.getTags()) ); } if (thatOperation.getExternalDocs() != null) { thisOperation.setExternalDocs( mergeExternalDocumentation(thisOperation.getExternalDocs(), thatOperation.getExternalDocs()) ); } if (thatOperation.getParameters() != null) { thisOperation.setParameters( mergeParameters(thisOperation.getParameters(), thatOperation.getParameters()) ); } if (thatOperation.getRequestBody() != null) { thisOperation.setRequestBody(thatOperation.getRequestBody()); } if (thatOperation.getResponses() != null) { thisOperation.setResponses(thatOperation.getResponses()); } if (thatOperation.getCallbacks() != null) { thisOperation.setCallbacks(thatOperation.getCallbacks()); } if (thatOperation.getDeprecated() != null) { thisOperation.setDeprecated(thatOperation.getDeprecated()); } if (thatOperation.getSecurity() != null) { thisOperation.setSecurity(thatOperation.getSecurity()); } if (thatOperation.getServers() != null) { thisOperation.setServers(thatOperation.getServers()); } if (thatOperation.getExtensions() != null) { thisOperation.setExtensions(thatOperation.getExtensions()); } if (thatOperation.getOperationId() != null) { thisOperation.setOperationId(thatOperation.getOperationId()); } if (thatOperation.getSummary() != null) { thisOperation.setSummary(thatOperation.getSummary()); } if (thatOperation.getDescription() != null) { thisOperation.setDescription(thatOperation.getDescription()); } if (thatOperation.getExtensions() != null) { thisOperation.setExtensions(thatOperation.getExtensions()); } return thisOperation; }
Example 5
Source File: OpenAPIDeserializer.java From swagger-parser with Apache License 2.0 | 4 votes |
public Operation getOperation(ObjectNode obj, String location, ParseResult result) { if (obj == null) { return null; } Operation operation = new Operation(); ArrayNode array = getArray("tags", obj, false, location, result); List<String> tags = getTagsStrings(array, String.format("%s.%s", location, "tags"), result); if (tags != null) { operation.setTags(tags); } String value = getString("summary", obj, false, location, result); if (StringUtils.isNotBlank(value)) { operation.setSummary(value); } value = getString("description", obj, false, location, result); if (StringUtils.isNotBlank(value)) { operation.setDescription(value); } ObjectNode externalDocs = getObject("externalDocs", obj, false, location, result); ExternalDocumentation docs = getExternalDocs(externalDocs, String.format("%s.%s", location, "externalDocs"), result); if(docs != null) { operation.setExternalDocs(docs); } value = getString("operationId", obj, false, location, result, operationIDs); if (StringUtils.isNotBlank(value)) { operation.operationId(value); } ArrayNode parameters = getArray("parameters", obj, false, location, result); if (parameters != null){ operation.setParameters(getParameterList(parameters, String.format("%s.%s", location, "parameters"), result)); } final ObjectNode requestObjectNode = getObject("requestBody", obj, false, location, result); if (requestObjectNode != null){ operation.setRequestBody(getRequestBody(requestObjectNode, String.format("%s.%s", location, "requestBody"), result)); } ObjectNode responsesNode = getObject("responses", obj, true, location, result); ApiResponses responses = getResponses(responsesNode, String.format("%s.%s", location, "responses"), result, false); if(responses != null) { operation.setResponses(responses); } ObjectNode callbacksNode = getObject("callbacks", obj, false, location, result); Map<String,Callback> callbacks = getCallbacks(callbacksNode, String.format("%s.%s", location, "callbacks"), result, false); if(callbacks != null){ operation.setCallbacks(callbacks); } Boolean deprecated = getBoolean("deprecated", obj, false, location, result); if (deprecated != null) { operation.setDeprecated(deprecated); } array = getArray("servers", obj, false, location, result); if (array != null && array.size() > 0) { operation.setServers(getServersList(array, String.format("%s.%s", location, "servers"), result)); } array = getArray("security", obj, false, location, result); if (array != null) { operation.setSecurity(getSecurityRequirementsList(array, String.format("%s.%s", location, "security"), result)); } Map <String,Object> extensions = getExtensions(obj); if(extensions != null && extensions.size() > 0) { operation.setExtensions(extensions); } Set<String> keys = getKeys(obj); for(String key : keys) { if(!OPERATION_KEYS.contains(key) && !key.startsWith("x-")) { result.extra(location, key, obj.get(key)); } } return operation; }