io.swagger.models.Contact Java Examples

The following examples show how to use io.swagger.models.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: ApiContextBuilderImpl.java    From dorado with Apache License 2.0 6 votes vote down vote up
@Override
// 这里定制Api全局信息,如文档描述、license,contact等信息
public ApiContext buildApiContext() {
	Info info = new Info()
			.contact(new Contact().email("[email protected]").name("weiping wang")
					.url("http://github.com/javagossip/dorado"))
			.license(new License().name("apache v2.0").url("http://www.apache.org"))
			.termsOfService("http://swagger.io/terms/").description("Dorado服务框架api接口文档")
			.title("dorado demo api接口文档").version("1.0.0");

	//构造api访问授权的apiKey
	ApiKey apiKey = ApiKey.builder().withName("Authorization").withIn("header").build();
	ApiContext apiContext = ApiContext.builder().withApiKey(apiKey)
			.withInfo(info).build();

	return apiContext;
}
 
Example #2
Source File: SwaggerDefinitionProcessor.java    From servicecomb-java-chassis with Apache License 2.0 6 votes vote down vote up
private Contact convertContact(io.swagger.annotations.Contact contactAnnotation) {
  Contact contact = new Contact();

  if (StringUtils.isNotEmpty(contactAnnotation.name())) {
    contact.setName(contactAnnotation.name());
  }
  if (StringUtils.isNotEmpty(contactAnnotation.url())) {
    contact.setUrl(contactAnnotation.url());
  }
  if (StringUtils.isNotEmpty(contactAnnotation.email())) {
    contact.setEmail(contactAnnotation.email());
  }

  if (StringUtils.isEmpty(contact.getName()) &&
      StringUtils.isEmpty(contact.getUrl()) &&
      StringUtils.isEmpty(contact.getEmail())) {
    return null;
  }

  return contact;
}
 
Example #3
Source File: ServiceModelToSwagger2.java    From Resource with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected Contact map(springfox.documentation.service.Contact from)
{
    if (from == null)
    {
        return null;
    }

    Contact contact = new Contact();

    contact.setName(from.getName());
    contact.setUrl(from.getUrl());
    contact.setEmail(from.getEmail());

    return contact;
}
 
Example #4
Source File: ContactInfoComponent.java    From swagger2markup with Apache License 2.0 6 votes vote down vote up
@Override
public MarkupDocBuilder apply(MarkupDocBuilder markupDocBuilder, Parameters params) {
    Contact contact = params.contact;
    if (isNotBlank(contact.getName()) || isNotBlank(contact.getEmail())) {
        markupDocBuilder.sectionTitleLevel(params.titleLevel, labels.getLabel(SwaggerLabels.CONTACT_INFORMATION));
        MarkupDocBuilder paragraphBuilder = copyMarkupDocBuilder(markupDocBuilder);
        if (isNotBlank(contact.getName())) {
            paragraphBuilder.italicText(labels.getLabel(SwaggerLabels.CONTACT_NAME))
                    .textLine(COLON + contact.getName());
        }
        if (isNotBlank(contact.getEmail())) {
            paragraphBuilder.italicText(labels.getLabel(SwaggerLabels.CONTACT_EMAIL))
                    .textLine(COLON + contact.getEmail());
        }
        markupDocBuilder.paragraph(paragraphBuilder.toString(), true);
    }
    return markupDocBuilder;
}
 
Example #5
Source File: Java2SwaggerMojo.java    From cxf with Apache License 2.0 6 votes vote down vote up
private void configureSwagger() {
    swagger = new Swagger();
    mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
    mapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY);
    Info info = new Info();
    Contact swaggerContact = new Contact();
    License swaggerLicense = new License();
    swaggerLicense.name(this.license)
        .url(this.licenseUrl);
    swaggerContact.name(this.contact);
    info.version(this.version)
        .description(this.description)
        .contact(swaggerContact)
        .license(swaggerLicense)
        .title(this.title);
    swagger.setInfo(info);
    if (this.schemes != null) {
        for (String scheme : this.schemes) {
            swagger.scheme(Scheme.forValue(scheme));
        }
    }
    swagger.setHost(this.host);
    swagger.setBasePath(this.basePath);
}
 
Example #6
Source File: JbootSwaggerManager.java    From jboot with Apache License 2.0 5 votes vote down vote up
public void init() {
    if (!config.isConfigOk()) {
        return;
    }

    swagger = new Swagger();
    swagger.setHost(config.getHost());
    swagger.setBasePath("/");
    swagger.addScheme(HTTP);
    swagger.addScheme(HTTPS);


    Info swaggerInfo = new Info();
    swaggerInfo.setDescription(config.getDescription());
    swaggerInfo.setVersion(config.getVersion());
    swaggerInfo.setTitle(config.getTitle());
    swaggerInfo.setTermsOfService(config.getTermsOfService());

    Contact contact = new Contact();
    contact.setName(config.getContactName());
    contact.setEmail(config.getContactEmail());
    contact.setUrl(config.getContactUrl());
    swaggerInfo.setContact(contact);

    License license = new License();
    license.setName(config.getLicenseName());
    license.setUrl(config.getLicenseUrl());
    swaggerInfo.setLicense(license);


    swagger.setInfo(swaggerInfo);

    List<Class> classes = ClassScanner.scanClassByAnnotation(RequestMapping.class, false);

    Reader.read(swagger, classes);

}
 
Example #7
Source File: ContactInfoComponentTest.java    From swagger2markup with Apache License 2.0 5 votes vote down vote up
@Test
public void testVersionInfoComponent() throws URISyntaxException {
    Contact contact = new Contact().name("TestName").email("[email protected]");

    Swagger2MarkupConverter.SwaggerContext context = createContext();
    MarkupDocBuilder markupDocBuilder = context.createMarkupDocBuilder();

    markupDocBuilder = new ContactInfoComponent(context).apply(markupDocBuilder, ContactInfoComponent.parameters(
            contact, OverviewDocument.SECTION_TITLE_LEVEL));
    markupDocBuilder.writeToFileWithoutExtension(outputDirectory, StandardCharsets.UTF_8);

    Path expectedFile = getExpectedFile(COMPONENT_NAME);
    DiffUtils.assertThatFileIsEqual(expectedFile, outputDirectory, getReportName(COMPONENT_NAME));

}
 
Example #8
Source File: MSF4JBeanConfig.java    From msf4j with Apache License 2.0 5 votes vote down vote up
private void updateInfoFromConfig() {
    if (getSwagger().getInfo() == null) {
        setInfo(new Info());
    }

    if (StringUtils.isNotBlank(getDescription())) {
        getSwagger().getInfo().setDescription(getDescription());
    }

    if (StringUtils.isNotBlank(getTitle())) {
        getSwagger().getInfo().setTitle(getTitle());
    }

    if (StringUtils.isNotBlank(getVersion())) {
        getSwagger().getInfo().setVersion(getVersion());
    }

    if (StringUtils.isNotBlank(getTermsOfServiceUrl())) {
        getSwagger().getInfo().setTermsOfService(getTermsOfServiceUrl());
    }

    if (getContact() != null) {
        getSwagger().getInfo().setContact((new Contact()).name(getContact()));
    }

    if (getLicense() != null && getLicenseUrl() != null) {
        getSwagger().getInfo().setLicense((new License()).name(getLicense()).url(getLicenseUrl()));
    }

    if (getSchemes() != null) {
        for (String scheme : getSchemes()) {
            reader.getSwagger().scheme(Scheme.forValue(scheme));
        }
    }

    reader.getSwagger().setInfo(getInfo());
}
 
Example #9
Source File: OAS2Parser.java    From carbon-apimgt with Apache License 2.0 5 votes vote down vote up
/**
 * 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 {
    Swagger swagger = new Swagger();

    //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());
    swagger.setInfo(info);
    updateSwaggerSecurityDefinition(swagger, swaggerData, "https://test.com");
    updateLegacyScopesFromSwagger(swagger, swaggerData);
    for (SwaggerData.Resource resource : swaggerData.getResources()) {
        addOrUpdatePathToSwagger(swagger, resource);
    }

    return getSwaggerJsonString(swagger);
}
 
Example #10
Source File: ApiSource.java    From swagger-maven-plugin with Apache License 2.0 5 votes vote down vote up
private Contact from(io.swagger.annotations.Contact contactAnnotation) {
    Contact contact = new Contact()
            .name(emptyToNull(contactAnnotation.name()))
            .email(emptyToNull(contactAnnotation.email()))
            .url(emptyToNull(contactAnnotation.url()));
    if (contact.getName() == null && contact.getEmail() == null && contact.getUrl() == null) {
        contact = null;
    }
    return contact;
}
 
Example #11
Source File: ClojureClientCodegen.java    From TypeScript-Microservices with MIT License 4 votes vote down vote up
@Override
public void preprocessSwagger(Swagger swagger) {
    super.preprocessSwagger(swagger);

    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 (swagger.getInfo() != null) {
        Info info = swagger.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 = "swagger-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";

    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);

    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 #12
Source File: ContactInfoComponent.java    From swagger2markup with Apache License 2.0 4 votes vote down vote up
public static ContactInfoComponent.Parameters parameters(Contact contact,
                                                         int titleLevel) {
    return new ContactInfoComponent.Parameters(contact, titleLevel);
}
 
Example #13
Source File: ContactInfoComponent.java    From swagger2markup with Apache License 2.0 4 votes vote down vote up
public Parameters(Contact contact,
                  int titleLevel) {
    this.contact = Validate.notNull(contact, "Contact must not be null");
    this.titleLevel = titleLevel;
}