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

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

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

Swagger.getVendorExtensions介绍

暂无

代码示例

代码示例来源:origin: com.google.api/api-compiler

private boolean isDeprecated(Swagger swagger) {
 if (swagger.getVendorExtensions() != null
   && swagger.getVendorExtensions().containsKey(ExtensionNames.X_GOOGLE_DEPRECATED)) {
  return VendorExtensionUtils.getExtensionValue(
    swagger.getVendorExtensions(),
    Boolean.class,
    diagCollector,
    ExtensionNames.X_GOOGLE_DEPRECATED);
 }
 return false;
}

代码示例来源:origin: googleapis/api-compiler

private boolean isDeprecated(Swagger swagger) {
 if (swagger.getVendorExtensions() != null
   && swagger.getVendorExtensions().containsKey(ExtensionNames.X_GOOGLE_DEPRECATED)) {
  return VendorExtensionUtils.getExtensionValue(
    swagger.getVendorExtensions(),
    Boolean.class,
    diagCollector,
    ExtensionNames.X_GOOGLE_DEPRECATED);
 }
 return false;
}

代码示例来源:origin: com.google.api/api-compiler

private ServiceManagementExtension readExtension(Swagger swagger) {
 return new Gson()
   .fromJson(
     swagger
       .getVendorExtensions()
       .get(ExtensionNames.MANAGEMENT_SWAGGER_EXTENSION)
       .toString(),
     ServiceManagementExtension.class);
}

代码示例来源:origin: googleapis/api-compiler

private ServiceManagementExtension readExtension(Swagger swagger) {
 return new Gson()
   .fromJson(
     swagger
       .getVendorExtensions()
       .get(ExtensionNames.MANAGEMENT_SWAGGER_EXTENSION)
       .toString(),
     ServiceManagementExtension.class);
}

代码示例来源:origin: io.syndesis.server/server-connector-generator

private static URI specificationUriFrom(final Swagger swagger) {
  final Map<String, Object> vendorExtensions = Optional.ofNullable(swagger.getVendorExtensions()).orElse(Collections.emptyMap());
  return (URI) vendorExtensions.get(BaseSwaggerConnectorGenerator.URL_EXTENSION);
}

代码示例来源:origin: io.syndesis.server/server-api-generator

private static URI specificationUriFrom(final Swagger swagger) {
  final Map<String, Object> vendorExtensions = Optional.ofNullable(swagger.getVendorExtensions()).orElse(Collections.emptyMap());
  return (URI) vendorExtensions.get(BaseSwaggerConnectorGenerator.URL_EXTENSION);
}

代码示例来源:origin: googleapis/api-compiler

public static OpenApiFile create(
   Service.Builder serviceBuilder, Swagger swagger, String filename, String typeNamespace)
   throws OpenApiConversionException {
  String hostname = Strings.nullToEmpty(swagger.getHost());
  String version = Strings.nullToEmpty(swagger.getInfo().getVersion());
  String googleApiName = "";
  if (swagger.getVendorExtensions() != null) {
   googleApiName = Strings.nullToEmpty(
     (String) swagger.getVendorExtensions().get(ExtensionNames.API_NAME));
  }
  String apiName = ApiNameGenerator.generate(hostname, googleApiName, version);
  return new AutoValue_MultiOpenApiParser_OpenApiFile(
    serviceBuilder,
    swagger,
    filename,
    apiName,
    OpenApiConversionResources.create(swagger, filename, apiName, typeNamespace));
 }
}

代码示例来源:origin: com.google.api/api-compiler

public static OpenApiFile create(
   Service.Builder serviceBuilder, Swagger swagger, String filename, String typeNamespace)
   throws OpenApiConversionException {
  String hostname = Strings.nullToEmpty(swagger.getHost());
  String version = Strings.nullToEmpty(swagger.getInfo().getVersion());
  String googleApiName = "";
  if (swagger.getVendorExtensions() != null) {
   googleApiName = Strings.nullToEmpty(
     (String) swagger.getVendorExtensions().get(ExtensionNames.API_NAME));
  }
  String apiName = ApiNameGenerator.generate(hostname, googleApiName, version);
  return new AutoValue_MultiOpenApiParser_OpenApiFile(
    serviceBuilder,
    swagger,
    filename,
    apiName,
    OpenApiConversionResources.create(swagger, filename, apiName, typeNamespace));
 }
}

代码示例来源:origin: com.google.api/api-compiler

/** Returns true if x-google-allow is set to all; false otherwise. */
private static boolean isAllowAllMethodsConfigured(Swagger swagger, DiagCollector diagCollector) {
 String googleAllowExtensionNameUsed =
   VendorExtensionUtils.usedExtension(
     diagCollector, swagger.getVendorExtensions(), ExtensionNames.X_GOOGLE_ALLOW);
 if (!Strings.isNullOrEmpty(googleAllowExtensionNameUsed)) {
  String allowMethodsExtensionValue =
    VendorExtensionUtils.getExtensionValue(
      swagger.getVendorExtensions(),
      String.class,
      diagCollector,
      googleAllowExtensionNameUsed);
  if (!Strings.isNullOrEmpty(allowMethodsExtensionValue)) {
   if (allowMethodsExtensionValue.equalsIgnoreCase("all")) {
    return true;
   } else if (allowMethodsExtensionValue.equalsIgnoreCase("configured")) {
    return false;
   } else {
    diagCollector.addDiag(
      Diag.error(
        new SimpleLocation(ExtensionNames.X_GOOGLE_ALLOW),
        "Only allowed values for %s are %s",
        ExtensionNames.X_GOOGLE_ALLOW,
        "all|configured"));
    return false;
   }
  }
 }
 return false;
}

代码示例来源:origin: io.syndesis.server/server-connector-generator

static String determineHost(final Swagger swagger) {
  final Map<String, Object> vendorExtensions = ofNullable(swagger.getVendorExtensions()).orElse(Collections.emptyMap());
  final URI specificationUrl = (URI) vendorExtensions.get(BaseSwaggerConnectorGenerator.URL_EXTENSION);
  final String schemeToUse = determineSchemeToUse(swagger, specificationUrl);
  if (schemeToUse == null) {
    return null;
  }
  final String specificationHost = swagger.getHost();
  final boolean specificationWithoutHost = StringUtils.isEmpty(specificationHost);
  if (specificationWithoutHost && specificationUrl == null) {
    return null;
  }
  String hostToUse;
  if (specificationWithoutHost && specificationUrl != null) {
    hostToUse = specificationUrl.getHost();
  } else {
    hostToUse = swagger.getHost();
  }
  final int portToUse;
  final int colonIdx = hostToUse.indexOf(':');
  if (colonIdx == -1) {
    portToUse = -1;
  } else {
    portToUse = Integer.parseUnsignedInt(hostToUse.substring(colonIdx + 1));
    hostToUse = hostToUse.substring(0, colonIdx);
  }
  return createHostUri(schemeToUse, hostToUse, portToUse);
}

代码示例来源:origin: io.syndesis.server/server-api-generator

static String determineHost(final Swagger swagger) {
  final Map<String, Object> vendorExtensions = ofNullable(swagger.getVendorExtensions()).orElse(Collections.emptyMap());
  final URI specificationUrl = (URI) vendorExtensions.get(BaseSwaggerConnectorGenerator.URL_EXTENSION);
  final String schemeToUse = determineSchemeToUse(swagger, specificationUrl);
  if (schemeToUse == null) {
    return null;
  }
  final String specificationHost = swagger.getHost();
  final boolean specificationWithoutHost = StringUtils.isEmpty(specificationHost);
  if (specificationWithoutHost && specificationUrl == null) {
    return null;
  }
  String hostToUse;
  if (specificationWithoutHost && specificationUrl != null) {
    hostToUse = specificationUrl.getHost();
  } else {
    hostToUse = swagger.getHost();
  }
  final int portToUse;
  final int colonIdx = hostToUse.indexOf(':');
  if (colonIdx == -1) {
    portToUse = -1;
  } else {
    portToUse = Integer.parseUnsignedInt(hostToUse.substring(colonIdx + 1));
    hostToUse = hostToUse.substring(0, colonIdx);
  }
  return createHostUri(schemeToUse, hostToUse, portToUse);
}

代码示例来源:origin: googleapis/api-compiler

/** Returns true if x-google-allow is set to all; false otherwise. */
private static boolean isAllowAllMethodsConfigured(Swagger swagger, DiagCollector diagCollector) {
 String googleAllowExtensionNameUsed =
   VendorExtensionUtils.usedExtension(
     diagCollector, swagger.getVendorExtensions(), ExtensionNames.X_GOOGLE_ALLOW);
 if (!Strings.isNullOrEmpty(googleAllowExtensionNameUsed)) {
  String allowMethodsExtensionValue =
    VendorExtensionUtils.getExtensionValue(
      swagger.getVendorExtensions(),
      String.class,
      diagCollector,
      googleAllowExtensionNameUsed);
  if (!Strings.isNullOrEmpty(allowMethodsExtensionValue)) {
   if (allowMethodsExtensionValue.equalsIgnoreCase("all")) {
    return true;
   } else if (allowMethodsExtensionValue.equalsIgnoreCase("configured")) {
    return false;
   } else {
    diagCollector.addDiag(
      Diag.error(
        new SimpleLocation(ExtensionNames.X_GOOGLE_ALLOW),
        "Only allowed values for %s are %s",
        ExtensionNames.X_GOOGLE_ALLOW,
        "all|configured"));
    return false;
   }
  }
 }
 return false;
}

代码示例来源:origin: com.google.api/api-compiler

@Override
public void addFromSwagger(Service.Builder serviceBuilder, Swagger swagger) {
 VendorExtensionProtoConverter extensionConverter =
   new VendorExtensionProtoConverter(swagger.getVendorExtensions(), diagCollector);
 if (extensionConverter.hasExtension(ExtensionNames.ENDPOINTS_EXTENSION_NAME)) {
  serviceBuilder.addAllEndpoints(
    extensionConverter.convertExtensionToProtos(
      Endpoint.getDefaultInstance(), ExtensionNames.ENDPOINTS_EXTENSION_NAME));
  validEndpointExtension(serviceBuilder, swagger.getHost());
 }
}

代码示例来源:origin: googleapis/api-compiler

@Override
public void addFromSwagger(Service.Builder serviceBuilder, Swagger swagger) {
 VendorExtensionProtoConverter extensionConverter =
   new VendorExtensionProtoConverter(swagger.getVendorExtensions(), diagCollector);
 if (extensionConverter.hasExtension(ExtensionNames.ENDPOINTS_EXTENSION_NAME)) {
  serviceBuilder.addAllEndpoints(
    extensionConverter.convertExtensionToProtos(
      Endpoint.getDefaultInstance(), ExtensionNames.ENDPOINTS_EXTENSION_NAME));
  validEndpointExtension(serviceBuilder, swagger.getHost());
 }
}

代码示例来源:origin: com.google.api/api-compiler

/** Adds auth security requirement for the entire service. */
public void addSecurityRequirementExtensionForEntireService(
  Service.Builder serviceBuilder, Swagger swagger) {
 AuthenticationRule.Builder builder = AuthenticationRule.newBuilder();
 Map<String, SecurityRequirementModel> authRequirements =
   authRuleGenerator.getSecurityRequirements(
     swagger.getSecurity() != null
       ? Iterables.transform(swagger.getSecurity(), SecurityRequirementsExtractor.INSTANCE)
       : null,
     swagger.getVendorExtensions(),
     new SimpleLocation("OpenAPI"));
 if (authRequirements != null && !authRequirements.isEmpty()) {
  builder.addAllRequirements(SecurityRequirementModel.createAuthRequirements(authRequirements));
  builder.setSelector("*");
  Authentication.Builder authenticationBuilder = serviceBuilder.getAuthenticationBuilder();
  authenticationBuilder.addRules(builder.build());
 }
}

代码示例来源:origin: googleapis/api-compiler

/** Adds auth security requirement for the entire service. */
public void addSecurityRequirementExtensionForEntireService(
  Service.Builder serviceBuilder, Swagger swagger) {
 AuthenticationRule.Builder builder = AuthenticationRule.newBuilder();
 Map<String, SecurityRequirementModel> authRequirements =
   authRuleGenerator.getSecurityRequirements(
     swagger.getSecurity() != null
       ? Iterables.transform(swagger.getSecurity(), SecurityRequirementsExtractor.INSTANCE)
       : null,
     swagger.getVendorExtensions(),
     new SimpleLocation("OpenAPI"));
 if (authRequirements != null && !authRequirements.isEmpty()) {
  builder.addAllRequirements(SecurityRequirementModel.createAuthRequirements(authRequirements));
  builder.setSelector("*");
  Authentication.Builder authenticationBuilder = serviceBuilder.getAuthenticationBuilder();
  authenticationBuilder.addRules(builder.build());
 }
}

代码示例来源:origin: com.google.api/api-compiler

@Override
 public void addFromSwagger(Service.Builder serviceBuilder, Swagger swagger) {
  VendorExtensionProtoConverter extensionConverter =
    new VendorExtensionProtoConverter(swagger.getVendorExtensions(), diagCollector);

  if (extensionConverter.hasExtension(ExtensionNames.AUTHORIZATION_EXTENSION_NAME)) {
   Experimental.Builder eBuilder = serviceBuilder.getExperimentalBuilder();

   AuthorizationConfig config =
     extensionConverter.convertExtensionToProto(
       AuthorizationConfig.getDefaultInstance(),
       ExtensionNames.AUTHORIZATION_EXTENSION_NAME);
   serviceBuilder.setExperimental(eBuilder.setAuthorization(config));
  }
 }
}

代码示例来源:origin: googleapis/api-compiler

@Override
 public void addFromSwagger(Service.Builder serviceBuilder, Swagger swagger) {
  VendorExtensionProtoConverter extensionConverter =
    new VendorExtensionProtoConverter(swagger.getVendorExtensions(), diagCollector);

  if (extensionConverter.hasExtension(ExtensionNames.AUTHORIZATION_EXTENSION_NAME)) {
   Experimental.Builder eBuilder = serviceBuilder.getExperimentalBuilder();

   AuthorizationConfig config =
     extensionConverter.convertExtensionToProto(
       AuthorizationConfig.getDefaultInstance(),
       ExtensionNames.AUTHORIZATION_EXTENSION_NAME);
   serviceBuilder.setExperimental(eBuilder.setAuthorization(config));
  }
 }
}

代码示例来源:origin: com.google.api/api-compiler

@Override
public void addFromSwagger(Service.Builder serviceBuilder, Swagger swagger) {
 VendorExtensionProtoConverter extensionConverter =
   new VendorExtensionProtoConverter(swagger.getVendorExtensions(), diagCollector);
 if (extensionConverter.hasExtension(ExtensionNames.MANAGEMENT_SWAGGER_EXTENSION)) {
  ServiceManagementExtension serviceManagementExtension = readExtension(swagger);
  Quota quota = parseQuota(serviceManagementExtension, extensionConverter);
  if (!quota.equals(Quota.getDefaultInstance())) {
   serviceBuilder.setQuota(quota);
  }
  serviceBuilder.addAllMetrics(parseMetrics(serviceManagementExtension, extensionConverter));
 }
}

代码示例来源:origin: googleapis/api-compiler

@Override
public void addFromSwagger(Service.Builder serviceBuilder, Swagger swagger) {
 VendorExtensionProtoConverter extensionConverter =
   new VendorExtensionProtoConverter(swagger.getVendorExtensions(), diagCollector);
 if (extensionConverter.hasExtension(ExtensionNames.MANAGEMENT_SWAGGER_EXTENSION)) {
  ServiceManagementExtension serviceManagementExtension = readExtension(swagger);
  Quota quota = parseQuota(serviceManagementExtension, extensionConverter);
  if (!quota.equals(Quota.getDefaultInstance())) {
   serviceBuilder.setQuota(quota);
  }
  serviceBuilder.addAllMetrics(parseMetrics(serviceManagementExtension, extensionConverter));
 }
}

相关文章