Java Code Examples for io.swagger.v3.oas.models.servers.Server#setUrl()
The following examples show how to use
io.swagger.v3.oas.models.servers.Server#setUrl() .
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: TestUtils.java From openapi-generator with Apache License 2.0 | 6 votes |
public static OpenAPI createOpenAPI() { OpenAPI openAPI = new OpenAPI(); openAPI.setComponents(new Components()); openAPI.setPaths(new Paths()); final Info info = new Info(); info.setDescription("API under test"); info.setVersion("1.0.7"); info.setTitle("My title"); openAPI.setInfo(info); final Server server = new Server(); server.setUrl("https://localhost:9999/root"); openAPI.setServers(Collections.singletonList(server)); return openAPI; }
Example 2
Source File: OpenApiObjectGenerator.java From flow with Apache License 2.0 | 6 votes |
private OpenAPI createBasicModel() { OpenAPI openAPI = new OpenAPI(); Info info = new Info(); info.setTitle(configuration.getApplicationTitle()); info.setVersion(configuration.getApplicationApiVersion()); openAPI.setInfo(info); Paths paths = new Paths(); openAPI.setPaths(paths); Server server = new Server(); server.setUrl(configuration.getServerUrl()); server.setDescription(configuration.getServerDescription()); openAPI.setServers(Collections.singletonList(server)); Components components = new Components(); SecurityScheme vaadinConnectOAuth2Scheme = new SecurityScheme() .type(SecurityScheme.Type.OAUTH2) .flows(new OAuthFlows().password(new OAuthFlow() .tokenUrl(VAADIN_CONNECT_OAUTH2_TOKEN_URL) .scopes(new Scopes()))); components.addSecuritySchemes(VAADIN_CONNECT_OAUTH2_SECURITY_SCHEME, vaadinConnectOAuth2Scheme); openAPI.components(components); return openAPI; }
Example 3
Source File: OpenAPIDeserializer.java From swagger-parser with Apache License 2.0 | 6 votes |
public List<Server> getServersList(ArrayNode obj, String location, ParseResult result, String path) { List<Server> servers = new ArrayList<>(); if (obj == null) { return null; } for (JsonNode item : obj) { if (item.getNodeType().equals(JsonNodeType.OBJECT)) { Server server = getServer((ObjectNode) item, location, result, path); if (server != null) { servers.add(server); }else{ Server defaultServer = new Server(); defaultServer.setUrl("/"); servers.add(defaultServer); } } } return servers; }
Example 4
Source File: TestOpenAPIFilter.java From RestDoc with Apache License 2.0 | 5 votes |
@Override public OpenAPI handle(OpenAPI openAPI) { System.out.println("handle openapi"); Server server = new Server(); server.setDescription("add by extension"); server.setUrl("http://localhost:8084?info=add_by_extension"); openAPI.getServers().add(server); return openAPI; }
Example 5
Source File: ApiDocV3Service.java From api-layer with Eclipse Public License 2.0 | 5 votes |
private void updateServerUrl(OpenAPI openAPI, Server server, String basePath) { if (server != null) { server.setUrl(basePath); openAPI.setServers(Collections.singletonList(server)); } else { openAPI.addServersItem(new Server().url(basePath)); } }
Example 6
Source File: MCRRestV2App.java From mycore with GNU General Public License v3.0 | 5 votes |
private void setupOAS() { OpenAPI oas = new OpenAPI(); Info oasInfo = new Info(); oas.setInfo(oasInfo); oasInfo.setVersion(MCRCoreVersion.getVersion()); oasInfo.setTitle(getApplicationName()); License oasLicense = new License(); oasLicense.setName("GNU General Public License, version 3"); oasLicense.setUrl("http://www.gnu.org/licenses/gpl-3.0.txt"); oasInfo.setLicense(oasLicense); URI baseURI = URI.create(MCRFrontendUtil.getBaseURL()); Server oasServer = new Server(); oasServer.setUrl(baseURI.resolve("api").toString()); oas.addServersItem(oasServer); SwaggerConfiguration oasConfig = new SwaggerConfiguration() .openAPI(oas) .resourcePackages(Stream.of(getRestPackages()).collect(Collectors.toSet())) .ignoredRoutes( MCRConfiguration2.getString("MCR.RestAPI.V2.OpenAPI.IgnoredRoutes") .map(MCRConfiguration2::splitValue) .orElseGet(Stream::empty) .collect(Collectors.toSet())) .prettyPrint(true); try { new JaxrsOpenApiContextBuilder() .application(getApplication()) .openApiConfiguration(oasConfig) .buildContext(true); } catch (OpenApiConfigurationException e) { throw new InternalServerErrorException(e); } }
Example 7
Source File: SwaggerServer.java From swagger-maven-plugin with MIT License | 4 votes |
public Server createServerModel() { Server server = new Server(); server.setUrl(url); server.setDescription(description); return server; }
Example 8
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; }
Example 9
Source File: OpenAPIDeserializer.java From swagger-parser with Apache License 2.0 | 4 votes |
public Server getServer(ObjectNode obj, String location, ParseResult result, String path) { if (obj == null) { return null; } Server server = new Server(); String value = getString("url", obj, true, location, result); if(StringUtils.isNotBlank(value)) { if(!isValidURL(value) && path != null){ try { final URI absURI = new URI(path); if("http".equals(absURI.getScheme()) || "https".equals(absURI.getScheme())){ value = absURI.resolve(new URI(value)).toString(); } } catch (URISyntaxException e) { result.warning(location,"invalid url : "+value); } } server.setUrl(value); } value = getString("description", obj, false, location, result); if(StringUtils.isNotBlank(value)) { server.setDescription(value); } if (obj.get("variables") != null) { ObjectNode variables = getObject("variables", obj, false, location, result); ServerVariables serverVariables = getServerVariables(variables, String.format("%s.%s", location, "variables"), result); if (serverVariables != null && serverVariables.size() > 0) { server.setVariables(serverVariables); } } Map <String,Object> extensions = getExtensions(obj); if(extensions != null && extensions.size() > 0) { server.setExtensions(extensions); } Set<String> keys = getKeys(obj); for(String key : keys) { if(!SERVER_KEYS.contains(key) && !key.startsWith("x-")) { result.extra(location, key, obj.get(key)); } } return server; }