Java Code Examples for io.swagger.v3.oas.models.OpenAPI#setExtensions()
The following examples show how to use
io.swagger.v3.oas.models.OpenAPI#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: OpenAPIBuilder.java From springdoc-openapi with Apache License 2.0 | 6 votes |
/** * Build open api with open api definition. * * @param openAPI the open api * @param apiDef the api def */ private void buildOpenAPIWithOpenAPIDefinition(OpenAPI openAPI, OpenAPIDefinition apiDef) { // info AnnotationsUtils.getInfo(apiDef.info()).map(this::resolveProperties).ifPresent(openAPI::setInfo); // OpenApiDefinition security requirements securityParser.getSecurityRequirements(apiDef.security()).ifPresent(openAPI::setSecurity); // OpenApiDefinition external docs AnnotationsUtils.getExternalDocumentation(apiDef.externalDocs()).ifPresent(openAPI::setExternalDocs); // OpenApiDefinition tags AnnotationsUtils.getTags(apiDef.tags(), false).ifPresent(tags -> openAPI.setTags(new ArrayList<>(tags))); // OpenApiDefinition servers Optional<List<Server>> optionalServers = AnnotationsUtils.getServers(apiDef.servers()); if (optionalServers.isPresent()) { openAPI.setServers(optionalServers.get()); this.isServersPresent = true; } // OpenApiDefinition extensions if (apiDef.extensions().length > 0) { openAPI.setExtensions(AnnotationsUtils.getExtensions(apiDef.extensions())); } }
Example 2
Source File: StaticHtml2Generator.java From openapi-generator with Apache License 2.0 | 4 votes |
@Override public void preprocessOpenAPI(OpenAPI openAPI) { super.preprocessOpenAPI(openAPI); if (openAPI.getInfo() != null) { Info info = openAPI.getInfo(); if (StringUtils.isBlank(jsProjectName) && info.getTitle() != null) { // when jsProjectName is not specified, generate it from info.title jsProjectName = sanitizeName(dashize(info.getTitle())); } } // default values if (StringUtils.isBlank(jsProjectName)) { jsProjectName = "openapi-js-client"; } if (StringUtils.isBlank(jsModuleName)) { jsModuleName = camelize(underscore(jsProjectName)); } additionalProperties.put("jsProjectName", jsProjectName); additionalProperties.put("jsModuleName", jsModuleName); preparHtmlForGlobalDescription(openAPI); Map<String, Object> vendorExtensions = openAPI.getExtensions(); if (vendorExtensions != null) { for (Map.Entry<String, Object> vendorExtension : vendorExtensions.entrySet()) { // Vendor extensions could be Maps (objects). If we wanted to iterate through them in our template files // without knowing the keys beforehand, the default `toString` method renders them unusable. Instead, we // convert them to JSON strings now, which means we can easily use them later. if (vendorExtension.getValue() instanceof Map) { this.vendorExtensions().put(vendorExtension.getKey(), Json.mapper().convertValue(vendorExtension.getValue(), JsonNode.class)); } else { this.vendorExtensions().put(vendorExtension.getKey(), vendorExtension.getValue()); } } } openAPI.setExtensions(this.vendorExtensions); }
Example 3
Source File: OpenAPIDeserializer.java From swagger-parser with Apache License 2.0 | 4 votes |
public OpenAPI parseRoot(JsonNode node, ParseResult result, String path) { String location = ""; OpenAPI openAPI = new OpenAPI(); if (node.getNodeType().equals(JsonNodeType.OBJECT)) { ObjectNode rootNode = (ObjectNode) node; // required String value = getString("openapi", rootNode, true, location, result); // we don't even try if the version isn't there if(value == null || !value.startsWith("3.0")) { return null; } openAPI.setOpenapi(value); ObjectNode obj = getObject("info", rootNode, true, location, result); if (obj != null) { Info info = getInfo(obj, "info", result); openAPI.setInfo(info); } obj = getObject("components", rootNode, false, location, result); if (obj != null) { Components components = getComponents(obj, "components", result); openAPI.setComponents(components); this.components=components; } obj = getObject("paths", rootNode, true, location, result); if (obj != null) { Paths paths = getPaths(obj, "paths", result); openAPI.setPaths(paths); } ArrayNode array = getArray("servers", rootNode, false, location, result); if (array != null && array.size() > 0) { openAPI.setServers(getServersList(array, String.format("%s.%s", location, "servers"), result, path)); }else { Server defaultServer = new Server(); defaultServer.setUrl("/"); List<Server> servers = new ArrayList<>(); servers.add(defaultServer); openAPI.setServers(servers); } obj = getObject("externalDocs", rootNode, false, location, result); if (obj != null) { ExternalDocumentation externalDocs = getExternalDocs(obj, "externalDocs", result); openAPI.setExternalDocs(externalDocs); } array = getArray("tags", rootNode, false, location, result); if (array != null && array.size() > 0) { openAPI.setTags(getTagList(array, "tags", result)); } array = getArray("security", rootNode, false, location, result); if (array != null && array.size() > 0) { List<SecurityRequirement> securityRequirements = getSecurityRequirementsList(array, "security", result); if (securityRequirements != null && securityRequirements. size() > 0) { openAPI.setSecurity(securityRequirements); } } Map <String,Object> extensions = getExtensions(rootNode); if(extensions != null && extensions.size() > 0) { openAPI.setExtensions(extensions); } Set<String> keys = getKeys(rootNode); for(String key : keys) { if(!ROOT_KEYS.contains(key) && !key.startsWith("x-")) { result.extra(location, key, node.get(key)); } } } else { result.invalidType(location, "openapi", "object", node); result.invalid(); return null; } return openAPI; }