io.swagger.v3.oas.models.info.Contact Java Examples
The following examples show how to use
io.swagger.v3.oas.models.info.Contact.
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: OpenApiFeature.java From cxf with Apache License 2.0 | 7 votes |
/** * The info will be used only if there is no @OpenAPIDefinition annotation is present. */ private Info getInfo(final Properties properties) { final Info info = new Info() .title(getOrFallback(getTitle(), properties, TITLE_PROPERTY)) .version(getOrFallback(getVersion(), properties, VERSION_PROPERTY)) .description(getOrFallback(getDescription(), properties, DESCRIPTION_PROPERTY)) .termsOfService(getOrFallback(getTermsOfServiceUrl(), properties, TERMS_URL_PROPERTY)) .contact(new Contact() .name(getOrFallback(getContactName(), properties, CONTACT_PROPERTY)) .email(getContactEmail()) .url(getContactUrl())) .license(new License() .name(getOrFallback(getLicense(), properties, LICENSE_PROPERTY)) .url(getOrFallback(getLicenseUrl(), properties, LICENSE_URL_PROPERTY))); if (info.getLicense().getName() == null) { info.getLicense().setName(DEFAULT_LICENSE_VALUE); } if (info.getLicense().getUrl() == null && DEFAULT_LICENSE_VALUE.equals(info.getLicense().getName())) { info.getLicense().setUrl(DEFAULT_LICENSE_URL); } return info; }
Example #2
Source File: OpenAPIBuilder.java From springdoc-openapi with Apache License 2.0 | 6 votes |
/** * Resolve properties info. * * @param info the info * @return the info */ private Info resolveProperties(Info info) { PropertyResolverUtils propertyResolverUtils = context.getBean(PropertyResolverUtils.class); resolveProperty(info::getTitle, info::title, propertyResolverUtils); resolveProperty(info::getDescription, info::description, propertyResolverUtils); resolveProperty(info::getVersion, info::version, propertyResolverUtils); resolveProperty(info::getTermsOfService, info::termsOfService, propertyResolverUtils); License license = info.getLicense(); if (license != null) { resolveProperty(license::getName, license::name, propertyResolverUtils); resolveProperty(license::getUrl, license::url, propertyResolverUtils); } Contact contact = info.getContact(); if (contact != null) { resolveProperty(contact::getName, contact::name, propertyResolverUtils); resolveProperty(contact::getEmail, contact::email, propertyResolverUtils); resolveProperty(contact::getUrl, contact::url, propertyResolverUtils); } return info; }
Example #3
Source File: SwaggerContact.java From swagger-maven-plugin with MIT License | 6 votes |
public Contact createContactModel() { Contact contact = new Contact(); if (name != null) { contact.setName(name); } if (url != null) { contact.setUrl(url); } if (email != null) { contact.setEmail(email); } return contact; }
Example #4
Source File: OpenApiTest.java From aries-jax-rs-whiteboard with Apache License 2.0 | 5 votes |
@Test public void testOpenApiEndpoint() { OpenAPI openAPI = new OpenAPI(); openAPI.info( new Info() .title("My Service") .description("Service REST API") .contact( new Contact() .email("[email protected]")) ); ServiceRegistration<OpenAPI> serviceRegistration = bundleContext.registerService( OpenAPI.class, openAPI, new Hashtable<>()); try { WebTarget webTarget = createDefaultTarget(). path("openapi.json"); registerAddon(new TestOpenApiResource()); String response = webTarget.request().get(String.class); assertTrue(response.contains("operation")); } finally { serviceRegistration.unregister(); } }
Example #5
Source File: OverviewDocument.java From swagger2markup with Apache License 2.0 | 5 votes |
private void addAuthorInfo(Document rootDocument, Info info) { Contact contact = info.getContact(); if (null != contact) { String author = Optional.ofNullable(contact.getName()).orElse(""); String email = contact.getEmail(); if (StringUtils.isNotBlank(email)) { rootDocument.setAttribute("email", email, true); } rootDocument.setAttribute("author", author, true); rootDocument.setAttribute("authorcount", 1L, true); } }
Example #6
Source File: SwaggerConverter.java From swagger-parser with Apache License 2.0 | 5 votes |
public Contact convert(io.swagger.models.Contact v2Contact) { if (v2Contact == null) { return null; } Contact contact = new Contact(); contact.setUrl(v2Contact.getUrl()); contact.setName(v2Contact.getName()); contact.setEmail(v2Contact.getEmail()); // TODO - treat this process after adding extensions to v2Contact object return contact; }
Example #7
Source File: OpenAPIDeserializerTest.java From swagger-parser with Apache License 2.0 | 5 votes |
@Test public void testContact() { String yaml = "openapi: 3.0.0\n" + "servers: []\n" + "info:\n" + " title: title\n" + " bad: bad\n" + " x-foo: bar\n" + " description: description\n" + " termsOfService: tos\n" + " contact:\n" + " name: tony\n" + " url: url\n" + " email: email\n" + " invalid: invalid\n" + " x-fun: true\n" + " version: version\n" + "paths: {}"; OpenAPIV3Parser parser = new OpenAPIV3Parser(); SwaggerParseResult result = parser.readContents(yaml, null, null); List<String> messageList = result.getMessages(); Set<String> messages = new HashSet<>(messageList); assertEquals(result.getOpenAPI().getInfo().getTitle(), "title"); assertEquals(result.getOpenAPI().getInfo().getDescription(), "description"); assertEquals(result.getOpenAPI().getInfo().getTermsOfService(), "tos"); assertEquals(result.getOpenAPI().getInfo().getVersion(), "version"); Contact contact = result.getOpenAPI().getInfo().getContact(); assertEquals(contact.getName(), "tony"); assertEquals(contact.getUrl(), "url"); assertEquals(contact.getEmail(), "email"); assertTrue(messages.contains("attribute info.bad is unexpected")); assertTrue(messages.contains("attribute info.contact.invalid is unexpected")); assertEquals(result.getOpenAPI().getInfo().getExtensions().get("x-foo").toString(), "bar"); }
Example #8
Source File: OpenAPIDeserializerTest.java From swagger-parser with Apache License 2.0 | 5 votes |
@Test(dataProvider = "data") public void readInfoObject(JsonNode rootNode) throws Exception { final OpenAPIDeserializer deserializer = new OpenAPIDeserializer(); final SwaggerParseResult result = deserializer.deserialize(rootNode); Assert.assertNotNull(result); final OpenAPI openAPI = result.getOpenAPI(); Assert.assertNotNull(openAPI); Assert.assertEquals(openAPI.getOpenapi(),"3.0.1"); final Info info = openAPI.getInfo(); Assert.assertNotNull(info); Assert.assertEquals(info.getTitle(), "Sample Pet Store App"); Assert.assertEquals(info.getDescription(), "This is a sample server Petstore"); Assert.assertEquals(info.getTermsOfService(), "http://swagger.io/terms/"); Assert.assertNotNull(info.getExtensions().get("x-info")); Assert.assertEquals(info.getExtensions().get("x-info").toString(),"info extension"); final Contact contact = info.getContact(); Assert.assertNotNull(contact); Assert.assertEquals(contact.getName(),"API Support"); Assert.assertEquals(contact.getUrl(),"http://www.example.com/support"); Assert.assertEquals(contact.getEmail(),"[email protected]"); Assert.assertNotNull(contact.getExtensions().get("x-contact")); Assert.assertEquals(contact.getExtensions().get("x-contact").toString(),"contact extension"); final License license = info.getLicense(); Assert.assertNotNull(license); Assert.assertEquals(license.getName(), "Apache 2.0"); Assert.assertEquals(license.getUrl(), "http://www.apache.org/licenses/LICENSE-2.0.html"); Assert.assertNotNull(license.getExtensions()); Assert.assertEquals(info.getVersion(), "1.0.1"); }
Example #9
Source File: Bootstrap.java From submarine with Apache License 2.0 | 5 votes |
@Override public void init(ServletConfig config) throws ServletException { OpenAPI oas = new OpenAPI(); Info info = new Info() .title("Submarine Experiment API") .description("The Submarine REST API allows you to create, list, and get experiments. The\n" + "API is hosted under the /v1/experiment route on the Submarine server. For example,\n" + "to list experiments on a server hosted at http://localhost:8080, access\n" + "http://localhost:8080/api/v1/experiment/") .termsOfService("http://swagger.io/terms/") .contact(new Contact() .email("[email protected]")) .version("0.4.0") .license(new License() .name("Apache 2.0") .url("http://www.apache.org/licenses/LICENSE-2.0.html")); oas.info(info); List<Server> servers = new ArrayList<>(); servers.add(new Server().url("/api")); oas.servers(servers); SwaggerConfiguration oasConfig = new SwaggerConfiguration() .openAPI(oas) .resourcePackages(Stream.of("org.apache.submarine.server.rest").collect(Collectors.toSet())); try { new JaxrsOpenApiContextBuilder() .servletConfig(config) .openApiConfiguration(oasConfig) .buildContext(true); } catch (OpenApiConfigurationException e) { throw new ServletException(e.getMessage(), e); } }
Example #10
Source File: ClojureClientCodegen.java From openapi-generator with Apache License 2.0 | 4 votes |
@Override public void preprocessOpenAPI(OpenAPI openAPI) { super.preprocessOpenAPI(openAPI); if (additionalProperties.containsKey(PROJECT_NAME)) { projectName = ((String) additionalProperties.get(PROJECT_NAME)); } if (additionalProperties.containsKey(PROJECT_DESCRIPTION)) { projectDescription = ((String) additionalProperties.get(PROJECT_DESCRIPTION)); } if (additionalProperties.containsKey(PROJECT_VERSION)) { projectVersion = ((String) additionalProperties.get(PROJECT_VERSION)); } if (additionalProperties.containsKey(BASE_NAMESPACE)) { baseNamespace = ((String) additionalProperties.get(BASE_NAMESPACE)); } if (openAPI.getInfo() != null) { Info info = openAPI.getInfo(); if (projectName == null && info.getTitle() != null) { // when projectName is not specified, generate it from info.title projectName = dashize(info.getTitle()); } if (projectVersion == null) { // when projectVersion is not specified, use info.version projectVersion = info.getVersion(); } if (projectDescription == null) { // when projectDescription is not specified, use info.description projectDescription = info.getDescription(); } if (info.getContact() != null) { Contact contact = info.getContact(); if (additionalProperties.get(PROJECT_URL) == null) { additionalProperties.put(PROJECT_URL, contact.getUrl()); } } if (info.getLicense() != null) { License license = info.getLicense(); if (additionalProperties.get(PROJECT_LICENSE_NAME) == null) { additionalProperties.put(PROJECT_LICENSE_NAME, license.getName()); } if (additionalProperties.get(PROJECT_LICENSE_URL) == null) { additionalProperties.put(PROJECT_LICENSE_URL, license.getUrl()); } } } // default values if (projectName == null) { projectName = "openapi-clj-client"; } if (projectVersion == null) { projectVersion = "1.0.0"; } if (projectDescription == null) { projectDescription = "Client library of " + projectName; } if (baseNamespace == null) { baseNamespace = dashize(projectName); } apiPackage = baseNamespace + ".api"; modelPackage = baseNamespace + ".specs"; additionalProperties.put(PROJECT_NAME, projectName); additionalProperties.put(PROJECT_DESCRIPTION, escapeText(projectDescription)); additionalProperties.put(PROJECT_VERSION, projectVersion); additionalProperties.put(BASE_NAMESPACE, baseNamespace); additionalProperties.put(CodegenConstants.API_PACKAGE, apiPackage); additionalProperties.put(CodegenConstants.MODEL_PACKAGE, modelPackage); final String baseNamespaceFolder = sourceFolder + File.separator + namespaceToFolder(baseNamespace); supportingFiles.add(new SupportingFile("project.mustache", "", "project.clj")); supportingFiles.add(new SupportingFile("core.mustache", baseNamespaceFolder, "core.clj")); supportingFiles.add(new SupportingFile("git_push.sh.mustache", "", "git_push.sh")); supportingFiles.add(new SupportingFile("gitignore.mustache", "", ".gitignore")); }
Example #11
Source File: DefaultGenerator.java From openapi-generator with Apache License 2.0 | 4 votes |
private void configureOpenAPIInfo() { Info info = this.openAPI.getInfo(); if (info == null) { return; } if (info.getTitle() != null) { config.additionalProperties().put("appName", config.escapeText(info.getTitle())); } if (info.getVersion() != null) { config.additionalProperties().put("appVersion", config.escapeText(info.getVersion())); } else { LOGGER.error("Missing required field info version. Default appVersion set to 1.0.0"); config.additionalProperties().put("appVersion", "1.0.0"); } if (StringUtils.isEmpty(info.getDescription())) { // set a default description if none if provided config.additionalProperties().put("appDescription", "No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)"); config.additionalProperties().put("appDescriptionWithNewLines", config.additionalProperties().get("appDescription")); config.additionalProperties().put("unescapedAppDescription", "No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)"); } else { config.additionalProperties().put("appDescription", config.escapeText(info.getDescription())); config.additionalProperties().put("appDescriptionWithNewLines", config.escapeTextWhileAllowingNewLines(info.getDescription())); config.additionalProperties().put("unescapedAppDescription", info.getDescription()); } if (info.getContact() != null) { Contact contact = info.getContact(); if (contact.getEmail() != null) { config.additionalProperties().put("infoEmail", config.escapeText(contact.getEmail())); } if (contact.getName() != null) { config.additionalProperties().put("infoName", config.escapeText(contact.getName())); } if (contact.getUrl() != null) { config.additionalProperties().put("infoUrl", config.escapeText(contact.getUrl())); } } if (info.getLicense() != null) { License license = info.getLicense(); if (license.getName() != null) { config.additionalProperties().put("licenseInfo", config.escapeText(license.getName())); } if (license.getUrl() != null) { config.additionalProperties().put("licenseUrl", config.escapeText(license.getUrl())); } } if (info.getVersion() != null) { config.additionalProperties().put("version", config.escapeText(info.getVersion())); } else { LOGGER.error("Missing required field info version. Default version set to 1.0.0"); config.additionalProperties().put("version", "1.0.0"); } if (info.getTermsOfService() != null) { config.additionalProperties().put("termsOfService", config.escapeText(info.getTermsOfService())); } }
Example #12
Source File: SwaggerConverter.java From raptor with Apache License 2.0 | 4 votes |
/** * https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.1.md#contact-object * * @return */ protected Contact getContact() { Contact contact = new Contact(); // TODO: 2018/5/18 现在proto文件中还没有定义contact return null; }
Example #13
Source File: GenerateRestClients.java From konduit-serving with Apache License 2.0 | 4 votes |
private static void createApiInfo(OpenAPI openAPI) { try (InputStream is = GenerateRestClients.class.getClassLoader().getResourceAsStream("META-INF/konduit-serving-clients-git.properties")) { if (is == null) { throw new IllegalStateException("Cannot find konduit-serving-clients-git.properties on classpath"); } Properties gitProperties = new Properties(); gitProperties.load(is); String projectVersion = gitProperties.getProperty("git.build.version"); String commitId = gitProperties.getProperty("git.commit.id").substring(0, 8); openAPI.info(new Info() .title("Konduit Serving REST API") .version(String.format("%s | Commit: %s", projectVersion, commitId)) .description("RESTful API for various operations inside konduit-serving") .license(new License() .name("Apache 2.0") .url("https://github.com/KonduitAI/konduit-serving/blob/master/LICENSE")) .contact(new Contact() .url("https://konduit.ai/contact") .name("Konduit K.K.") .email("[email protected]"))) .tags(Collections.singletonList( new Tag() .name("inference") .description("Inference server operations"))) .externalDocs(new ExternalDocumentation() .description("Online documentation") .url("https://serving.konduit.ai")) .path("/predict", new PathItem() .summary("Predicts an output based on the given JSON (key/value) or binary string") .description("Takes a JSON string of key value pairs or a binary data string (protobuf) as input " + "and processes it in the pipeline. The output could be json or a binary string based on " + "the accept header value (application/json or application/octet-stream respectively).") .post(new Operation() .operationId("predict") .addTagsItem("inference") .requestBody(new RequestBody() .required(true) .content(new Content() .addMediaType(APPLICATION_JSON.toString(), new MediaType().schema(new MapSchema())) .addMediaType(APPLICATION_OCTET_STREAM.toString(), new MediaType().schema(new BinarySchema())) ) ).responses(new ApiResponses() .addApiResponse("200", new ApiResponse() .description("Successful operation") .content(new Content() .addMediaType(APPLICATION_JSON.toString(), new MediaType().schema(new MapSchema())) .addMediaType(APPLICATION_OCTET_STREAM.toString(), new MediaType().schema(new BinarySchema())) ) ).addApiResponse("500", new ApiResponse() .description("Internal server error") .content(new Content() .addMediaType(APPLICATION_JSON.toString(), new MediaType() .schema(new ObjectSchema().$ref("#/components/schemas/ErrorResponse")) ) ) ) ) ) ); } catch (IOException e) { throw new IllegalStateException(e.getMessage()); } }
Example #14
Source File: OpenApiTest.java From aries-jax-rs-whiteboard with Apache License 2.0 | 4 votes |
@Test public void testIncludeStaticResource() { String applicationSelectFilter = "(" + JAX_RS_APPLICATION_BASE + "=/test-application-a)"; registerAddon( new TestOpenApiResource(), JAX_RS_APPLICATION_SELECT, applicationSelectFilter); OpenAPI openAPI = new OpenAPI(); openAPI.info( new Info() .title("My Service") .description("Service REST API") .contact( new Contact() .email("[email protected]")) ); @SuppressWarnings({ "unchecked", "rawtypes", "serial" }) ServiceRegistration<OpenAPI> serviceRegistration = bundleContext.registerService( OpenAPI.class, openAPI, new Hashtable() {{ put( JAX_RS_APPLICATION_SELECT, "(" + JAX_RS_APPLICATION_BASE + "=/test-application-*)"); }}); registerApplication( new TestApplicationWithClasses(), JAX_RS_APPLICATION_BASE, "/test-application-a"); registerApplication( new TestApplicationWithClasses(), JAX_RS_APPLICATION_BASE, "/test-application-b"); try { WebTarget webTarget = createDefaultTarget(). path("test-application-a").path("openapi.json"); String response = webTarget.request().get(String.class); assertTrue(response.contains("\"/operation\":")); webTarget = createDefaultTarget(). path("test-application-b").path("openapi.json"); response = webTarget.request().get(String.class); assertFalse(response.contains("\"/operation\":")); } finally { serviceRegistration.unregister(); } }
Example #15
Source File: OpenAPIDeserializer.java From swagger-parser with Apache License 2.0 | 4 votes |
public Info getInfo(ObjectNode node, String location, ParseResult result) { if (node == null) return null; Info info = new Info(); String value = getString("title", node, true, location, result); if(StringUtils.isNotBlank(value)) { info.setTitle(value); } value = getString("description", node, false, location, result); if(StringUtils.isNotBlank(value)) { info.setDescription(value); } value = getString("termsOfService", node, false, location, result); if(StringUtils.isNotBlank(value)) { info.setTermsOfService(value); } ObjectNode obj = getObject("contact", node, false, "contact", result); Contact contact = getContact(obj, String.format("%s.%s", location, "contact"), result); if(obj != null) { info.setContact(contact); } obj = getObject("license", node, false, location, result); License license = getLicense(obj, String.format("%s.%s", location, "license"), result); if(obj != null) { info.setLicense(license); } value = getString("version", node, true, location, result); if(StringUtils.isNotBlank(value)) { info.setVersion(value); } Map <String,Object> extensions = getExtensions(node); if(extensions != null && extensions.size() > 0) { info.setExtensions(extensions); } Set<String> keys = getKeys(node); for(String key : keys) { if(!INFO_KEYS.contains(key) && !key.startsWith("x-")) { result.extra(location, key, node.get(key)); } } return info; }
Example #16
Source File: OpenAPIDeserializer.java From swagger-parser with Apache License 2.0 | 4 votes |
public Contact getContact(ObjectNode node, String location, ParseResult result) { if (node == null) return null; Contact contact = new Contact(); String value = getString("name", node, false, location, result); if(StringUtils.isNotBlank(value)) { contact.setName(value); } value = getString("url", node, false, location, result); if(StringUtils.isNotBlank(value)) { try { new URL(value); } catch (Exception e) { result.warning(location,value); } contact.setUrl(value); } value = getString("email", node, false, location, result); if(StringUtils.isNotBlank(value)) { contact.setEmail(value); } Map <String,Object> extensions = getExtensions(node); if(extensions != null && extensions.size() > 0) { contact.setExtensions(extensions); } Set<String> keys = getKeys(node); for(String key : keys) { if(!CONTACT_KEYS.contains(key) && !key.startsWith("x-")) { result.extra(location, key, node.get(key)); } } return contact; }
Example #17
Source File: OAS3Parser.java From carbon-apimgt with Apache License 2.0 | 4 votes |
/** * This method generates API definition to the given api * * @param swaggerData api * @return API definition in string format * @throws APIManagementException */ @Override public String generateAPIDefinition(SwaggerData swaggerData) throws APIManagementException { OpenAPI openAPI = new OpenAPI(); // create path if null if (openAPI.getPaths() == null) { openAPI.setPaths(new Paths()); } //Create info object Info info = new Info(); info.setTitle(swaggerData.getTitle()); if (swaggerData.getDescription() != null) { info.setDescription(swaggerData.getDescription()); } Contact contact = new Contact(); //Create contact object and map business owner info if (swaggerData.getContactName() != null) { contact.setName(swaggerData.getContactName()); } if (swaggerData.getContactEmail() != null) { contact.setEmail(swaggerData.getContactEmail()); } if (swaggerData.getContactName() != null || swaggerData.getContactEmail() != null) { //put contact object to info object info.setContact(contact); } info.setVersion(swaggerData.getVersion()); openAPI.setInfo(info); updateSwaggerSecurityDefinition(openAPI, swaggerData, "https://test.com"); updateLegacyScopesFromSwagger(openAPI, swaggerData); if (APIConstants.GRAPHQL_API.equals(swaggerData.getTransportType())) { modifyGraphQLSwagger(openAPI); } else { for (SwaggerData.Resource resource : swaggerData.getResources()) { addOrUpdatePathToSwagger(openAPI, resource); } } return Json.pretty(openAPI); }