@Test public void shouldGenerateWarningForDifferingServerBasePaths() { final Oas30Document openApiDoc = new Oas30Document(); openApiDoc.addServer("https: openApiDoc.addServer("https: openApiDoc.addServer("https: final OpenApiModelInfo info = new OpenApiModelInfo.Builder().model(openApiDoc).build(); final OpenApiModelInfo validated = Oas30ValidationRules.validateServerBasePaths(info); assertThat(validated.getErrors()).isEmpty(); assertThat(validated.getWarnings()).containsOnly(new Violation.Builder().error("differing-base-paths") .message("Specified servers do not share the same base path. REST endpoint will use '/development' as base path.").build()); }
static OpenApiModelInfo validateServerBasePaths(OpenApiModelInfo info) { if (info.getModel() == null) { return info; } final Oas30Document openApiDoc = info.getV3Model(); if (openApiDoc.servers == null || openApiDoc.servers.isEmpty()) { return info; } List<String> basePaths = openApiDoc.servers.stream().map(Oas30ModelHelper::getBasePath).collect(Collectors.toList()); if (basePaths.size() > 1 && new HashSet<>(basePaths).size() == basePaths.size()) { return new OpenApiModelInfo.Builder().createFrom(info) .addWarning(new Violation.Builder() .error("differing-base-paths") .message(String.format("Specified servers do not share the same base path. " + "REST endpoint will use '%s' as base path.", Oas30ModelHelper.getBasePath(openApiDoc))) .build()) .build(); } return info; }
Oas30ValidationRules extends OpenApiValidationRules<Oas30Response, Oas30SecurityScheme, Oas30SchemaDefinition> { static OpenApiModelInfo validateServerBasePaths(OpenApiModelInfo info) { if (info.getModel() == null) { return info; } final Oas30Document openApiDoc = info.getV3Model(); if (openApiDoc.servers == null || openApiDoc.servers.isEmpty()) { return info; } List<String> basePaths = openApiDoc.servers.stream().map(Oas30ModelHelper::getBasePath).collect(Collectors.toList()); if (basePaths.size() > 1 && new HashSet<>(basePaths).size() == basePaths.size()) { return new OpenApiModelInfo.Builder().createFrom(info) .addWarning(new Violation.Builder() .error("differing-base-paths") .message(String.format("Specified servers do not share the same base path. " + "REST endpoint will use '%s' as base path.", Oas30ModelHelper.getBasePath(openApiDoc))) .build()) .build(); } return info; } }
Oas30ValidationRules extends OpenApiValidationRules<Oas30Response, Oas30SecurityScheme, Oas30SchemaDefinition> { static OpenApiModelInfo validateServerBasePaths(OpenApiModelInfo info) { if (info.getModel() == null) { return info; } final Oas30Document openApiDoc = info.getV3Model(); if (openApiDoc.servers == null || openApiDoc.servers.isEmpty()) { return info; } List<String> basePaths = openApiDoc.servers.stream().map(Oas30ModelHelper::getBasePath).collect(Collectors.toList()); if (basePaths.size() > 1 && new HashSet<>(basePaths).size() == basePaths.size()) { return new OpenApiModelInfo.Builder().createFrom(info) .addWarning(new Violation.Builder() .error("differing-base-paths") .message(String.format("Specified servers do not share the same base path. " + "REST endpoint will use '%s' as base path.", Oas30ModelHelper.getBasePath(openApiDoc))) .build()) .build(); } return info; } Oas30ValidationRules(APIValidationContext context); }
Oas30ValidationRules extends OpenApiValidationRules<Oas30Response, Oas30SecurityScheme, Oas30SchemaDefinition> { static OpenApiModelInfo validateServerBasePaths(OpenApiModelInfo info) { if (info.getModel() == null) { return info; } final Oas30Document openApiDoc = info.getV3Model(); if (openApiDoc.servers == null || openApiDoc.servers.isEmpty()) { return info; } List<String> basePaths = openApiDoc.servers.stream().map(Oas30ModelHelper::getBasePath).collect(Collectors.toList()); if (basePaths.size() > 1 && new HashSet<>(basePaths).size() == basePaths.size()) { return new OpenApiModelInfo.Builder().createFrom(info) .addWarning(new Violation.Builder() .error("differing-base-paths") .message(String.format("Specified servers do not share the same base path. " + "REST endpoint will use '%s' as base path.", Oas30ModelHelper.getBasePath(openApiDoc))) .build()) .build(); } return info; } Oas30ValidationRules(APIValidationContext context); static Oas30ValidationRules get(final APIValidationContext context); }
Oas30ValidationRules extends OpenApiValidationRules<Oas30Response, Oas30SecurityScheme, Oas30SchemaDefinition> { static OpenApiModelInfo validateServerBasePaths(OpenApiModelInfo info) { if (info.getModel() == null) { return info; } final Oas30Document openApiDoc = info.getV3Model(); if (openApiDoc.servers == null || openApiDoc.servers.isEmpty()) { return info; } List<String> basePaths = openApiDoc.servers.stream().map(Oas30ModelHelper::getBasePath).collect(Collectors.toList()); if (basePaths.size() > 1 && new HashSet<>(basePaths).size() == basePaths.size()) { return new OpenApiModelInfo.Builder().createFrom(info) .addWarning(new Violation.Builder() .error("differing-base-paths") .message(String.format("Specified servers do not share the same base path. " + "REST endpoint will use '%s' as base path.", Oas30ModelHelper.getBasePath(openApiDoc))) .build()) .build(); } return info; } Oas30ValidationRules(APIValidationContext context); static Oas30ValidationRules get(final APIValidationContext context);  }