io.swagger.models.Swagger.getBasePath()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(9.4k)|赞(0)|评价(0)|浏览(205)

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

Swagger.getBasePath介绍

暂无

代码示例

代码示例来源:origin: Swagger2Markup/swagger2markup

/**
 * Returns the basePath which should be prepended to the relative path
 *
 * @return either the relative or the full path
 */
private String getBasePath() {
  if (config.isBasePathPrefixEnabled()) {
    return StringUtils.defaultString(context.getSwagger().getBasePath());
  }
  return "";
}

代码示例来源:origin: Swagger2Markup/swagger2markup

@Override
public MarkupDocBuilder apply(MarkupDocBuilder markupDocBuilder, Parameters params) {
  Swagger swagger = params.swagger;
  if (isNotBlank(swagger.getHost()) || isNotBlank(swagger.getBasePath()) || isNotEmpty(swagger.getSchemes())) {
    markupDocBuilder.sectionTitleLevel(params.titleLevel, labels.getLabel(Labels.URI_SCHEME));
    MarkupDocBuilder paragraphBuilder = copyMarkupDocBuilder(markupDocBuilder);
    if (isNotBlank(swagger.getHost())) {
      paragraphBuilder.italicText(labels.getLabel(Labels.HOST))
          .textLine(COLON + swagger.getHost());
    }
    if (isNotBlank(swagger.getBasePath())) {
      paragraphBuilder.italicText(labels.getLabel(Labels.BASE_PATH))
          .textLine(COLON + swagger.getBasePath());
    }
    if (isNotEmpty(swagger.getSchemes())) {
      List<String> schemes = swagger.getSchemes().stream()
          .map(Enum::toString)
          .collect(Collectors.toList());
      paragraphBuilder.italicText(labels.getLabel(Labels.SCHEMES))
          .textLine(COLON + join(schemes, ", "));
    }
    markupDocBuilder.paragraph(paragraphBuilder.toString(), true);
  }
  return markupDocBuilder;
}

代码示例来源:origin: apache/servicecomb-java-chassis

protected void correctBasePath() {
 String basePath = swagger.getBasePath();
 if (StringUtils.isEmpty(basePath)) {
  basePath = "/" + cls.getSimpleName();
 }
 if (!basePath.startsWith("/")) {
  basePath = "/" + basePath;
 }
 swagger.setBasePath(basePath);
}

代码示例来源:origin: apache/servicecomb-java-chassis

protected void checkPath(OperationGenerator operationGenerator) {
  if (StringUtils.isEmpty(operationGenerator.getPath())
    && StringUtils.isEmpty(operationGenerator.getSwagger().getBasePath())) {
   throw new Error("Path must not both be empty in class and method");
  }
 }
}

代码示例来源:origin: apache/servicecomb-java-chassis

@Override
 public void process(Object annotation, SwaggerGenerator swaggerGenerator) {
  Swagger swagger = swaggerGenerator.getSwagger();
  if (StringUtils.isEmpty(swagger.getBasePath())) {
   swagger.setBasePath("/");
  }
 }
}

代码示例来源:origin: kongchen/swagger-maven-plugin

protected Swagger removeBasePathFromEndpoints(Swagger swagger, boolean removeBasePathFromEndpoints) {
  Swagger result = swagger;
  if (!removeBasePathFromEndpoints) {
    return result;
  }
  String basePath = swagger.getBasePath();
  if (isEmpty(basePath)) {
    return result;
  }
  Map<String, Path> oldPathMap = result.getPaths();
  Map<String, Path> newPathMap = new HashMap<String, Path>();
  for (Map.Entry<String, Path> entry: oldPathMap.entrySet()) {
    newPathMap.put(entry.getKey().replace(basePath, ""), entry.getValue());
  }
  result.setPaths(newPathMap);
  return result;
}

代码示例来源:origin: apache/servicecomb-java-chassis

private void initOperations() {
 if (swagger.getPaths() == null) {
  LOGGER.warn(swagger.getInfo().getTitle() + " with path " + swagger.getBasePath()
    + " is an empty interface, please delete it or fill with one method!");
  return;

代码示例来源:origin: apache/servicecomb-java-chassis

if (!StringUtils.isEmpty(urlPrefix) && !swagger.getBasePath().startsWith(urlPrefix)
  && DynamicPropertyFactory.getInstance()
  .getBooleanProperty(REGISTER_URL_PREFIX, false).get()) {
 LOGGER.info("Add swagger base path prefix for {} with {}", swagger.getBasePath(), urlPrefix);
 swagger.setBasePath(urlPrefix + swagger.getBasePath());

代码示例来源:origin: apache/servicecomb-java-chassis

public SchemaMeta registerSchema(MicroserviceMeta microserviceMeta, String schemaId,
  Swagger swagger) {
 String microserviceName = microserviceMeta.getName();
 LOGGER.info("register schema {}/{}/{}", microserviceMeta.getAppId(), microserviceName, schemaId);
 SchemaMeta schemaMeta = new SchemaMeta(swagger, microserviceMeta, schemaId);
 List<Handler> producerHandlerChain = ProducerHandlerManager.INSTANCE.getOrCreate(microserviceName);
 schemaMeta.setProviderHandlerChain(producerHandlerChain);
 List<Handler> consumerHandlerChain = ConsumerHandlerManager.INSTANCE.getOrCreate(microserviceName);
 schemaMeta.setConsumerHandlerChain(consumerHandlerChain);
 microserviceMeta.regSchemaMeta(schemaMeta);
 addSchemaPath2Microservice(microserviceName, swagger.getBasePath());
 return schemaMeta;
}

代码示例来源:origin: apache/servicecomb-java-chassis

public void init(OperationMeta operationMeta) {
 this.operationMeta = operationMeta;
 Swagger swagger = operationMeta.getSchemaMeta().getSwagger();
 Operation operation = operationMeta.getSwaggerOperation();
 this.produces = operation.getProduces();
 if (produces == null) {
  this.produces = swagger.getProduces();
 }
 this.downloadFile = checkDownloadFileFlag();
 this.createProduceProcessors();
 Method method = operationMeta.getMethod();
 Type[] genericParamTypes = method.getGenericParameterTypes();
 if (genericParamTypes.length != operation.getParameters().size()) {
  throw new Error("Param count is not equal between swagger and method, path=" + absolutePath
    + ";operation=" + operationMeta.getMicroserviceQualifiedName());
 }
 // 初始化所有rest param
 for (int idx = 0; idx < genericParamTypes.length; idx++) {
  Parameter parameter = operation.getParameters().get(idx);
  Type genericParamType = genericParamTypes[idx];
  if ("formData".equals(parameter.getIn())) {
   formData = true;
  }
  RestParam param = new RestParam(idx, parameter, genericParamType);
  addParam(param);
 }
 setAbsolutePath(concatPath(swagger.getBasePath(), operationMeta.getOperationPath()));
}

代码示例来源:origin: networknt/light-rest-4j

public String findBasePath() {
  String basePath = SwaggerHelper.swagger.getBasePath();
  if(basePath == null) {
    log.warn("No basePath found in Swagger spec. Using empty base path for API.");
    return "";
  }
  while (basePath.endsWith("/")) {
    basePath = basePath.substring(0, basePath.length() - 1);
  }
  return basePath;
}

代码示例来源:origin: org.apache.servicecomb/swagger-generator-core

protected void correctBasePath() {
 String basePath = swagger.getBasePath();
 if (StringUtils.isEmpty(basePath)) {
  basePath = "/" + cls.getSimpleName();
 }
 if (!basePath.startsWith("/")) {
  basePath = "/" + basePath;
 }
 swagger.setBasePath(basePath);
}

代码示例来源:origin: org.apache.servicecomb/swagger-generator-core

protected void checkPath(OperationGenerator operationGenerator) {
  if (StringUtils.isEmpty(operationGenerator.getPath())
    && StringUtils.isEmpty(operationGenerator.getSwagger().getBasePath())) {
   throw new Error("Path must not both be empty in class and method");
  }
 }
}

代码示例来源:origin: io.github.swagger2markup/swagger2markup

/**
 * Returns the basePath which should be prepended to the relative path
 *
 * @return either the relative or the full path
 */
private String getBasePath() {
  if (config.isBasePathPrefixEnabled()) {
    return StringUtils.defaultString(context.getSwagger().getBasePath());
  }
  return "";
}

代码示例来源:origin: org.apache.servicecomb/swagger-generator-springmvc

@Override
 public void process(Object annotation, SwaggerGenerator swaggerGenerator) {
  Swagger swagger = swaggerGenerator.getSwagger();
  if (StringUtils.isEmpty(swagger.getBasePath())) {
   swagger.setBasePath("/");
  }
 }
}

代码示例来源:origin: RobWin/assertj-swagger

/**
 * Gets the paths from the actual Swagger model. Each path is prefixed with the base path configured in the model.
 *
 * @param actual Swagger model
 * @return paths including base path
 */
protected Map<String, Path> getPathsIncludingBasePath(Swagger actual) {
  String basePath = actual.getBasePath();
  return isBlankOrSlash(basePath) ?
      actual.getPaths() :
      getPathsWithPrefix(actual, basePath);
}

代码示例来源:origin: castlemock/castlemock

private String getApplicationName(final Swagger swagger){
  if(swagger.getInfo() != null &&
      swagger.getInfo().getTitle() != null){
    return swagger.getInfo().getTitle();
  } else if(swagger.getHost() != null){
    return swagger.getHost();
  } else if(swagger.getBasePath() != null){
    return swagger.getBasePath();
  }
  throw new IllegalArgumentException("Unable to extract application name " +
      "from the following swagger config: " + swagger);
}

代码示例来源:origin: amazon-archives/aws-apigateway-importer

@Override
public void updateApi(String apiId, Swagger swagger) {
  this.swagger = swagger;
  this.processedModels.clear();
  RestApi api = getApi(apiId);
  Optional<Resource> rootResource = getRootResource(api);
  updateModels(api, swagger.getDefinitions(), swagger.getProduces());
  updateResources(api, rootResource.get(), swagger.getBasePath(), swagger.getPaths(), swagger.getProduces());
  updateMethods(api, swagger.getBasePath(), swagger.getPaths(), swagger.getProduces());
  cleanupMethods(api, swagger.getBasePath(), swagger.getPaths());
  cleanupResources(api, swagger.getBasePath(), swagger.getPaths());
  cleanupModels(api, this.processedModels);
}

代码示例来源:origin: RobWin/assertj-swagger

@Test
public void shouldReturnPathsPrefixedIfBasePathSet() {
  // given
  Swagger swagger = buildSwaggerFrom("/swagger.json");
  SwaggerAssertionConfig swaggerAssertionConfig = new SwaggerAssertionConfig(new Properties());
  // when
  Map<String, Path> paths = new DummyValidator().findExpectedPaths(swagger, swaggerAssertionConfig);
  // then
  paths.entrySet().forEach(e -> assertThat(e.getKey(), startsWith(swagger.getBasePath())));
}

代码示例来源:origin: RobWin/assertj-swagger

@Test
public void shouldReturnPathsPrefixedIfBasePathSet() {
  // given
  Swagger swagger = buildSwaggerFrom("/swagger.json");
  // when
  Map<String, Path> paths = new DummyValidator().getPathsIncludingBasePath(swagger);
  // then
  paths.entrySet().forEach(e -> assertThat(e.getKey(), startsWith(swagger.getBasePath())));
}

相关文章