本文整理了Java中io.swagger.models.Swagger.getHost()
方法的一些代码示例,展示了Swagger.getHost()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Swagger.getHost()
方法的具体详情如下:
包路径:io.swagger.models.Swagger
类名称:Swagger
方法名:getHost
暂无
代码示例来源: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: AresS31/swurg
public int getPort(
Swagger swagger, Scheme scheme
) {
int port;
if (swagger.getHost().split(":").length > 1) {
port = Integer.valueOf(swagger.getHost().split(":")[1]);
} else {
if (scheme.toValue().toUpperCase().equals("HTTPS")) {
port = 443;
} else {
port = 80;
}
}
return port;
}
代码示例来源:origin: googleapis/api-compiler
private static Set<String> getHosts(List<OpenApiFile> openApiFiles) {
ImmutableSet.Builder<String> hostNames = ImmutableSet.builder();
for (OpenApiFile openApiFile : openApiFiles) {
String hostname = openApiFile.swagger().getHost();
if (!StringUtils.isBlank(hostname)) {
hostNames.add(hostname.trim());
}
}
return hostNames.build();
}
代码示例来源:origin: com.google.api/api-compiler
private static Set<String> getHosts(List<OpenApiFile> openApiFiles) {
ImmutableSet.Builder<String> hostNames = ImmutableSet.builder();
for (OpenApiFile openApiFile : openApiFiles) {
String hostname = openApiFile.swagger().getHost();
if (!StringUtils.isBlank(hostname)) {
hostNames.add(hostname.trim());
}
}
return hostNames.build();
}
代码示例来源:origin: AresS31/swurg
private void validateSpecification(Swagger swagger, String resource) {
if (Strings.isNullOrEmpty(swagger.getHost())) {
throw new IllegalArgumentException(
String.format(
"The OpenAPI specification contained in %s is missing the mandatory field: 'host'",
resource));
}
if (CollectionUtils.isEmpty(swagger.getSchemes())) {
throw new IllegalArgumentException(
String.format(
"The OpenAPI specification contained in %s is missing the mandatory field: 'schemes'",
resource));
}
if (MapUtils.isEmpty(swagger.getPaths())) {
throw new IllegalArgumentException(
String.format(
"The OpenAPI specification contained in %s is missing the mandatory field: 'paths'",
resource));
}
}
}
代码示例来源:origin: AresS31/swurg
private List<String> buildHeaders(
Swagger swagger, Map.Entry<String, Path> path, Map.Entry<HttpMethod, Operation> operation
) {
List<String> headers = new ArrayList<>();
headers.add(
operation.getKey().toString() + " " + swagger.getBasePath() + path.getKey() + " HTTP/1.1");
headers.add("Host: " + swagger.getHost().split(":")[0]);
if (CollectionUtils.isNotEmpty(operation.getValue().getProduces())) {
headers.add("Accept: " + String.join(",", operation.getValue().getProduces()));
} else if (CollectionUtils.isNotEmpty(swagger.getProduces())) {
headers.add("Accept: " + String.join(",", swagger.getProduces()));
}
if (CollectionUtils.isNotEmpty(operation.getValue().getConsumes())) {
headers.add("Content-Type: " + String.join(",", operation.getValue().getConsumes()));
} else if (CollectionUtils.isNotEmpty(swagger.getConsumes())) {
headers.add("Content-Type: " + String.join(",", swagger.getConsumes()));
}
return headers;
}
代码示例来源: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: io.syndesis.rest/rest-connector-generator
final String host = swagger.getHost();
String hostToUse;
if (StringUtils.isEmpty(host)) {
+ "and the Swagger specification was uploaded so it is impossible to determine the originating URL").getHost();
} else {
hostToUse = swagger.getHost();
代码示例来源: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: castlemock/castlemock
/**
* The method extracts the forward address from the {@link Swagger} model.
* @param swagger The {@link Swagger} model contains information about the source address.
* @return The extracted source address configured in {@link Swagger}.
*/
private String getForwardAddress(final Swagger swagger){
String schemas = "http";
if(swagger.getSchemes() != null && !swagger.getSchemes().isEmpty()){
schemas = swagger.getSchemes().get(0).toValue();
}
return schemas + "://" + swagger.getHost() + swagger.getBasePath();
}
代码示例来源: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: io.github.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: io.gravitee.management/gravitee-management-api-service
private NewApiEntity mapSwagger12ToNewApi(Swagger swagger) {
if (swagger == null || swagger.getInfo() == null) {
return null;
}
NewApiEntity apiEntity = new NewApiEntity();
apiEntity.setName(swagger.getInfo().getTitle());
apiEntity.setDescription(swagger.getInfo().getDescription());
apiEntity.setVersion(swagger.getInfo().getVersion());
String scheme = (swagger.getSchemes() == null || swagger.getSchemes().isEmpty()) ? defaultScheme :
swagger.getSchemes().iterator().next().toValue();
apiEntity.setEndpoint(scheme + "://" + swagger.getHost() + swagger.getBasePath());
apiEntity.setPaths(new ArrayList<>(
swagger.getPaths().keySet()
.stream()
.map(path -> path.replaceAll("\\{(.[^/]*)\\}", ":$1"))
.collect(Collectors.toList())));
return apiEntity;
}
代码示例来源:origin: phiz71/vertx-swagger
@Override
public void preprocessSwagger(Swagger swagger) {
super.preprocessSwagger(swagger);
// add full swagger definition in a mustache parameter
String swaggerDef = Json.pretty(swagger);
this.additionalProperties.put("fullSwagger", swaggerDef);
// add server port from the swagger file, 8080 by default
String host = swagger.getHost();
String port = extractPortFromHost(host);
this.additionalProperties.put("serverPort", port);
// retrieve api version from swagger file, 1.0.0-SNAPSHOT by default
if (swagger.getInfo() != null && swagger.getInfo().getVersion() != null)
artifactVersion = apiVersion = swagger.getInfo().getVersion();
else
artifactVersion = apiVersion;
// manage operation & custom serviceId
Map<String, Path> paths = swagger.getPaths();
if (paths != null) {
for (Entry<String, Path> entry : paths.entrySet()) {
manageOperationNames(entry.getValue(), entry.getKey());
}
}
}
代码示例来源:origin: gravitee-io/gravitee-management-rest-api
private NewApiEntity mapSwagger12ToNewApi(Swagger swagger) {
if (swagger == null || swagger.getInfo() == null) {
return null;
}
NewApiEntity apiEntity = new NewApiEntity();
apiEntity.setName(swagger.getInfo().getTitle());
apiEntity.setDescription(swagger.getInfo().getDescription());
apiEntity.setVersion(swagger.getInfo().getVersion());
String scheme = (swagger.getSchemes() == null || swagger.getSchemes().isEmpty()) ? defaultScheme :
swagger.getSchemes().iterator().next().toValue();
apiEntity.setEndpoint(scheme + "://" + swagger.getHost() + swagger.getBasePath());
apiEntity.setPaths(new ArrayList<>(
swagger.getPaths().keySet()
.stream()
.map(path -> path.replaceAll("\\{(.[^/]*)\\}", ":$1"))
.collect(Collectors.toList())));
return apiEntity;
}
代码示例来源: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.reprezen.genflow/swagger-doc
private CharSequence getBaseUri(final Swagger swagger) {
StringConcatenation _builder = new StringConcatenation();
_builder.append("<small>(");
Object _scheme = this.getScheme(swagger);
_builder.append(_scheme);
_builder.append("://");
String _host = swagger.getHost();
_builder.append(_host);
String _basePath = swagger.getBasePath();
_builder.append(_basePath);
_builder.append(")</small>");
return _builder;
}
内容来源于网络,如有侵权,请联系作者删除!