io.swagger.v3.oas.models.OpenAPI.getInfo()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(12.2k)|赞(0)|评价(0)|浏览(197)

本文整理了Java中io.swagger.v3.oas.models.OpenAPI.getInfo()方法的一些代码示例,展示了OpenAPI.getInfo()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。OpenAPI.getInfo()方法的具体详情如下:
包路径:io.swagger.v3.oas.models.OpenAPI
类名称:OpenAPI
方法名:getInfo

OpenAPI.getInfo介绍

[英]returns the info property from a OpenAPI instance.
[中]从OpenAPI实例返回info属性。

代码示例

代码示例来源:origin: swagger-api/swagger-core

@Test
public void testExtension() throws Exception {
  OpenAPI swagger = new OpenAPI();
  swagger.addExtension("x-foo-bar", "foo bar");
  swagger.setInfo(new Info());
  swagger.getInfo().addExtension("x-foo-bar", "foo bar");
  String swaggerJson = Json.mapper().writeValueAsString(swagger);
  assertFalse(swaggerJson.contains("extensions"));
  OpenAPI rebuilt = Json.mapper().readValue(swaggerJson, OpenAPI.class);
  assertEquals(rebuilt.getExtensions().values().iterator().next(), "foo bar");
  assertEquals(rebuilt.getInfo().getExtensions().values().iterator().next(), "foo bar");
}

代码示例来源:origin: swagger-api/swagger-core

clone.info(filteredOpenAPI.getInfo());
clone.openapi(filteredOpenAPI.getOpenapi());
clone.setExtensions(openAPI.getExtensions());

代码示例来源:origin: org.openapitools/openapi-generator

/**
 * Parse Markdown to HTML for the main "Description" attribute
 *
 * @param openAPI The base object containing the global description through "Info" class
 */
private void preparHtmlForGlobalDescription(OpenAPI openAPI) {
  if (openAPI.getInfo() == null) {
    return;
  }
  String currentDescription = openAPI.getInfo().getDescription();
  if (currentDescription != null && !currentDescription.isEmpty()) {
    Markdown markInstance = new Markdown();
    openAPI.getInfo().setDescription(markInstance.toHtml(currentDescription));
  } else {
    LOGGER.error("OpenAPI object description is empty [" + openAPI.getInfo().getTitle() + "]");
  }
}

代码示例来源:origin: org.openapitools/openapi-generator

@Override
public void preprocessOpenAPI(OpenAPI openAPI) {
  Info info = openAPI.getInfo();
  List<String> versionComponents = new ArrayList<>(Arrays.asList(info.getVersion().split("[.]")));
  if (versionComponents.size() < 1) {
    versionComponents.add("1");
  }
  while (versionComponents.size() < 3) {
    versionComponents.add("0");
  }
  info.setVersion(StringUtils.join(versionComponents, "."));
  URL url = URLPathUtils.getServerURL(openAPI);
  additionalProperties.put("serverHost", url.getHost());
  additionalProperties.put("serverPort", URLPathUtils.getPort(url, 80));
}

代码示例来源:origin: io.swagger.codegen.v3/swagger-codegen-generators

/**
 * Parse Markdown to HTML for the main "Description" attribute
 *
 * @param openAPI
 *            The base object containing the global description through
 *            "Info" class
 * @return Void
 */
private void preparHtmlForGlobalDescription(OpenAPI openAPI) {
  String currentDescription = openAPI.getInfo().getDescription();
  if (currentDescription != null && !currentDescription.isEmpty()) {
    Markdown markInstance = new Markdown();
    openAPI.getInfo().setDescription(markInstance.toHtml(currentDescription));
  }
  else {
    LOGGER.error("Swagger object description is empty [" + openAPI.getInfo().getTitle() + "]");
  }
}

代码示例来源:origin: io.swagger/swagger-codegen-generators

/**
 * Parse Markdown to HTML for the main "Description" attribute
 *
 * @param openAPI
 *            The base object containing the global description through
 *            "Info" class
 * @return Void
 */
private void preparHtmlForGlobalDescription(OpenAPI openAPI) {
  String currentDescription = openAPI.getInfo().getDescription();
  if (currentDescription != null && !currentDescription.isEmpty()) {
    Markdown markInstance = new Markdown();
    openAPI.getInfo().setDescription(markInstance.toHtml(currentDescription));
  }
  else {
    LOGGER.error("Swagger object description is empty [" + openAPI.getInfo().getTitle() + "]");
  }
}

代码示例来源:origin: org.openapitools/openapi-generator

@Override
public void preprocessOpenAPI(OpenAPI openAPI) {
  Info info = openAPI.getInfo();
  String calloutLabel = info.getTitle();
  additionalProperties.put("calloutLabel", calloutLabel);
  String sanitized = sanitizeName(calloutLabel);
  additionalProperties.put("calloutName", sanitized);
  supportingFiles.add(new SupportingFile("namedCredential.mustache", srcPath + "/namedCredentials",
      sanitized + ".namedCredential-meta.xml"
  ));
  if (additionalProperties.get(BUILD_METHOD).equals("sfdx")) {
    generateSfdxSupportingFiles();
  } else if (additionalProperties.get(BUILD_METHOD).equals("ant")) {
    generateAntSupportingFiles();
  }
}

代码示例来源:origin: com.atlassian.swagger/atlassian-swagger-doclet

public Info info() {
  if (openAPI().getInfo() == null) {
    openAPI().setInfo(new Info());
  }
  return openAPI().getInfo();
}

代码示例来源:origin: org.openapitools/openapi-generator

@Override
public void preprocessOpenAPI(OpenAPI openAPI) {
  super.preprocessOpenAPI(openAPI);
  // add server port from the swagger file, 8080 by default
  URL url = URLPathUtils.getServerURL(openAPI);
  this.additionalProperties.put("serverPort", URLPathUtils.getPort(url, 8080));
  // retrieve api version from swagger file, 1.0.0-SNAPSHOT by default
  if (openAPI.getInfo() != null && openAPI.getInfo().getVersion() != null) {
    artifactVersion = apiVersion = openAPI.getInfo().getVersion();
  } else {
    artifactVersion = apiVersion;
  }
  /*
   * manage operation & custom serviceId because operationId field is not
   * required and may be empty
   */
  Map<String, PathItem> paths = openAPI.getPaths();
  if (paths != null) {
    for (Entry<String, PathItem> entry : paths.entrySet()) {
      manageOperationNames(entry.getValue(), entry.getKey());
    }
  }
  this.additionalProperties.remove("gson");
}

代码示例来源:origin: io.swagger.codegen.v3/swagger-codegen-generators

@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 = "swagger-js-client";
  }
  if (StringUtils.isBlank(jsModuleName)) {
    jsModuleName = camelize(underscore(jsProjectName));
  }
  additionalProperties.put("jsProjectName", jsProjectName);
  additionalProperties.put("jsModuleName", jsModuleName);
  preparHtmlForGlobalDescription(openAPI);
}

代码示例来源:origin: io.swagger/swagger-codegen-generators

@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 = "swagger-js-client";
  }
  if (StringUtils.isBlank(jsModuleName)) {
    jsModuleName = camelize(underscore(jsProjectName));
  }
  additionalProperties.put("jsProjectName", jsProjectName);
  additionalProperties.put("jsModuleName", jsModuleName);
  preparHtmlForGlobalDescription(openAPI);
}

代码示例来源:origin: com.atlassian.swagger/atlassian-swagger-doclet

public OpenAPI defaults(OpenAPI openAPI) {
    Info info = openAPI.getInfo();
    if (info == null) {
      info = new Info();
      openAPI.setInfo(info);
    }
    if (isEmpty(info.getTitle())) {
      info.setTitle("API");
    }
    if (isEmpty(info.getVersion())) {
      info.setTitle("1.0");
    }
    return openAPI;
  }
}

代码示例来源:origin: io.gravitee.management/gravitee-management-api-service

private NewApiEntity mapOpenApiToNewApi(SwaggerParseResult swagger) {
  if (swagger == null || swagger.getOpenAPI() == null || swagger.getOpenAPI().getInfo() == null) {
    return null;
  }
  NewApiEntity apiEntity = new NewApiEntity();
  apiEntity.setName(swagger.getOpenAPI().getInfo().getTitle());
  apiEntity.setDescription(swagger.getOpenAPI().getInfo().getDescription());
  apiEntity.setVersion(swagger.getOpenAPI().getInfo().getVersion());
  if (!swagger.getOpenAPI().getServers().isEmpty()) {
    apiEntity.setEndpoint(swagger.getOpenAPI().getServers().get(0).getUrl());
  }
  apiEntity.setPaths(new ArrayList<>(
      swagger.getOpenAPI().getPaths().keySet()
          .stream()
          .map(path -> path.replaceAll("\\{(.[^/]*)\\}", ":$1"))
          .collect(Collectors.toList())));
  return apiEntity;
}

代码示例来源:origin: gravitee-io/gravitee-management-rest-api

private NewApiEntity mapOpenApiToNewApi(SwaggerParseResult swagger) {
  if (swagger == null || swagger.getOpenAPI() == null || swagger.getOpenAPI().getInfo() == null) {
    return null;
  }
  NewApiEntity apiEntity = new NewApiEntity();
  apiEntity.setName(swagger.getOpenAPI().getInfo().getTitle());
  apiEntity.setDescription(swagger.getOpenAPI().getInfo().getDescription());
  apiEntity.setVersion(swagger.getOpenAPI().getInfo().getVersion());
  if (!swagger.getOpenAPI().getServers().isEmpty()) {
    apiEntity.setEndpoint(swagger.getOpenAPI().getServers().get(0).getUrl());
  }
  apiEntity.setPaths(new ArrayList<>(
      swagger.getOpenAPI().getPaths().keySet()
          .stream()
          .map(path -> path.replaceAll("\\{(.[^/]*)\\}", ":$1"))
          .collect(Collectors.toList())));
  return apiEntity;
}

代码示例来源:origin: org.openapitools/openapi-generator

@Override
public void preprocessOpenAPI(OpenAPI openAPI) {
  Info info = openAPI.getInfo();
  if (moduleName == null) {
    if (info.getTitle() != null) {
      // default to the appName (from title field)
      setModuleName(modulized(escapeText(info.getTitle())));
    } else {
      setModuleName(defaultModuleName);
    }
  }
  additionalProperties.put("moduleName", moduleName);
  if (!additionalProperties.containsKey(CodegenConstants.PACKAGE_NAME)) {
    additionalProperties.put(CodegenConstants.PACKAGE_NAME, underscored(moduleName));
  }
  supportingFiles.add(new SupportingFile("connection.ex.mustache",
      sourceFolder(),
      "connection.ex"));
  supportingFiles.add(new SupportingFile("request_builder.ex.mustache",
      sourceFolder(),
      "request_builder.ex"));
  supportingFiles.add(new SupportingFile("deserializer.ex.mustache",
      sourceFolder(),
      "deserializer.ex"));
}

代码示例来源:origin: apache/cxf

public void customize(io.swagger.v3.oas.models.OpenAPI oas) {
    super.customize(oas);
    oas.getInfo().setDescription("Custom Description");
    oas.getInfo().getLicense().setName("Custom License");
    oas.getComponents().getSecuritySchemes().put("openid", new SecurityScheme());
  }
};

代码示例来源:origin: org.openapitools/openapi-generator

public void preprocessOpenAPI(OpenAPI openAPI) {
  Info info = openAPI.getInfo();
  info.setDescription(toHtml(info.getDescription()));
  info.setTitle(toHtml(info.getTitle()));
  Map<String, Schema> models = openAPI.getComponents().getSchemas();
  for (Schema model : models.values()) {
    model.setDescription(toHtml(model.getDescription()));
    model.setTitle(toHtml(model.getTitle()));
  }
}

代码示例来源:origin: io.swagger/swagger-codegen-generators

public void preprocessOpenAPI(OpenAPI openAPI) {
  Info info = openAPI.getInfo();
  info.setDescription(toHtml(info.getDescription()));
  info.setTitle(toHtml(info.getTitle()));
  if (openAPI.getComponents() == null || openAPI.getComponents().getSchemas() == null) {
    return;
  }
  Map<String, Schema> schemas = openAPI.getComponents().getSchemas();
  for (Schema schema : schemas.values()) {
    schema.setDescription(toHtml(schema.getDescription()));
    schema.setTitle(toHtml(schema.getTitle()));
  }
}

代码示例来源:origin: org.ballerinalang/swagger-to-ballerina-generator

/**
 * Build a {@link BallerinaOpenApi} object from a {@link OpenAPI} object.
 * All non iterable objects using handlebars library is converted into
 * supported iterable object types.
 *
 * @param openAPI {@link OpenAPI} type object to be converted
 * @return Converted {@link BallerinaOpenApi} object
 * @throws BallerinaOpenApiException when OpenAPI to BallerinaOpenApi parsing failed
 */
@Override
public BallerinaOpenApi buildContext(OpenAPI openAPI) throws BallerinaOpenApiException {
  this.openapi = openAPI.getOpenapi();
  this.info = openAPI.getInfo();
  this.externalDocs = openAPI.getExternalDocs();
  this.tags = openAPI.getTags();
  this.components = openAPI.getComponents();
  this.extensions = openAPI.getExtensions();
  setPaths(openAPI);
  setSecurityRequirements(openAPI);
  setServers(openAPI);
  setSchemas(openAPI);
  return this;
}

代码示例来源:origin: io.swagger.codegen.v3/swagger-codegen-generators

public void preprocessOpenAPI(OpenAPI openAPI) {
  super.preprocessOpenAPI(openAPI);
  Info info = openAPI.getInfo();
  info.setDescription(toHtml(info.getDescription()));
  info.setTitle(toHtml(info.getTitle()));
  if (openAPI.getComponents() == null || openAPI.getComponents().getSchemas() == null) {
    return;
  }
  Map<String, Schema> schemas = openAPI.getComponents().getSchemas();
  for (Schema schema : schemas.values()) {
    schema.setDescription(toHtml(schema.getDescription()));
    schema.setTitle(toHtml(schema.getTitle()));
  }
}

相关文章