本文整理了Java中io.swagger.v3.oas.models.OpenAPI.getPaths()
方法的一些代码示例,展示了OpenAPI.getPaths()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。OpenAPI.getPaths()
方法的具体详情如下:
包路径:io.swagger.v3.oas.models.OpenAPI
类名称:OpenAPI
方法名:getPaths
[英]returns the paths property from a OpenAPI instance.
[中]从OpenAPI实例返回paths属性。
代码示例来源:origin: swagger-api/swagger-core
private boolean existOperationId(String operationId) {
if (openAPI == null) {
return false;
}
if (openAPI.getPaths() == null || openAPI.getPaths().isEmpty()) {
return false;
}
for (PathItem path : openAPI.getPaths().values()) {
Set<String> pathOperationIds = extractOperationIdFromPathItem(path);
if (pathOperationIds.contains(operationId)) {
return true;
}
}
return false;
}
代码示例来源:origin: swagger-api/swagger-core
protected OpenAPI removeBrokenReferenceDefinitions(OpenAPI openApi) {
if (openApi == null || openApi.getComponents() == null || openApi.getComponents().getSchemas() == null) {
return openApi;
}
Set<String> referencedDefinitions = new TreeSet<>();
if (openApi.getPaths() != null) {
for (String resourcePath : openApi.getPaths().keySet()) {
PathItem pathItem = openApi.getPaths().get(resourcePath);
addPathItemSchemaRef(pathItem, referencedDefinitions);
}
}
Set<String> nestedReferencedDefinitions = new TreeSet<>();
for (String ref : referencedDefinitions) {
locateReferencedDefinitions(ref, nestedReferencedDefinitions, openApi);
}
referencedDefinitions.addAll(nestedReferencedDefinitions);
openApi.getComponents().getSchemas().keySet().retainAll(referencedDefinitions.stream().map(s -> (String) RefUtils.extractSimpleName(s).getLeft()).collect(Collectors.toSet()));
return openApi;
}
代码示例来源:origin: swagger-api/swagger-core
private void assertOperations(OpenAPI filtered, String operationId, String description) {
if (filtered.getPaths() != null) {
for (Map.Entry<String, PathItem> entry : filtered.getPaths().entrySet()) {
Operation get = entry.getValue().getGet();
if (get != null) {
assertEquals(get.getOperationId(), operationId);
assertEquals(get.getDescription(), description);
}
}
} else {
fail("paths should not be null");
}
}
代码示例来源:origin: swagger-api/swagger-core
@Test
public void testDeserializeAPathRef() throws Exception {
final OpenAPI oas = TestUtils.deserializeJsonFileFromClasspath("specFiles/pathRef.json", OpenAPI.class);
final PathItem petPath = oas.getPaths().get("/pet");
assertNotNull(petPath.get$ref());
assertEquals(petPath.get$ref(), "http://my.company.com/paths/health.json");
assertTrue(oas.getPaths().get("/user") instanceof PathItem);
}
代码示例来源:origin: swagger-api/swagger-core
@Test(description = "it should filter away get operations in a resource")
public void filterAwayGetOperations() throws IOException {
final OpenAPI openAPI = getOpenAPI(RESOURCE_PATH);
final NoGetOperationsFilter filter = new NoGetOperationsFilter();
final OpenAPI filtered = new SpecFilter().filter(openAPI, filter, null, null, null);
if (filtered.getPaths() != null) {
for (Map.Entry<String, PathItem> entry : filtered.getPaths().entrySet()) {
assertNull(entry.getValue().getGet());
}
} else {
fail("paths should not be null");
}
}
代码示例来源:origin: swagger-api/swagger-core
@Test(description = "it should desserialize Long schema correctly")
public void deserializeLongSchema() throws IOException {
final String jsonString = ResourceUtils.loadClassResource(getClass(), "specFiles/oas3_2.yaml");
final OpenAPI swagger = Yaml.mapper().readValue(jsonString, OpenAPI.class);
assertNotNull(swagger);
Schema s = swagger.getPaths().get("/withIntegerEnum/{stage}").getGet().getParameters().get(0).getSchema();
assertEquals(s.getEnum().get(0), 2147483647);
assertEquals(s.getEnum().get(1), 3147483647L);
assertEquals(s.getEnum().get(2), 31474836475505055L);
}
代码示例来源:origin: swagger-api/swagger-core
@Test(description = "it should filter away the pet resource")
public void filterAwayPetResource() throws IOException {
final OpenAPI openAPI = getOpenAPI(RESOURCE_PATH);
final NoPetOperationsFilter filter = new NoPetOperationsFilter();
final OpenAPI filtered = new SpecFilter().filter(openAPI, filter, null, null, null);
if (filtered.getPaths() != null) {
for (Map.Entry<String, PathItem> entry : filtered.getPaths().entrySet()) {
assertNull(entry.getValue().getDelete());
assertNull(entry.getValue().getPost());
assertNull(entry.getValue().getPut());
assertNull(entry.getValue().getGet());
assertNull(entry.getValue().getHead());
assertNull(entry.getValue().getOptions());
}
} else {
fail("paths should not be null");
}
}
代码示例来源:origin: swagger-api/swagger-core
@Test(description = "it should filter any PathItem objects without Ref")
public void filterAwayPathItemWithoutRef() throws IOException {
final OpenAPI openAPI = getOpenAPI(RESOURCE_PATH);
final OpenAPI filtered = new SpecFilter().filter(openAPI, new NoPathItemFilter(), null, null, null);
assertEquals(0, filtered.getPaths().size());
}
代码示例来源:origin: swagger-api/swagger-core
@Test(description = "it should filter away secret parameters")
public void filterAwaySecretParameters() throws IOException {
final OpenAPI openAPI = getOpenAPI(RESOURCE_PATH);
final RemoveInternalParamsFilter filter = new RemoveInternalParamsFilter();
final OpenAPI filtered = new SpecFilter().filter(openAPI, filter, null, null, null);
if (filtered.getPaths() != null) {
for (Map.Entry<String, PathItem> entry : filtered.getPaths().entrySet()) {
final Operation get = entry.getValue().getGet();
if (get != null) {
for (Parameter param : get.getParameters()) {
final String description = param.getDescription();
if (StringUtils.isNotBlank(description)) {
assertFalse(description.startsWith("secret"));
}
}
}
}
} else {
fail("paths should not be null");
}
}
代码示例来源:origin: swagger-api/swagger-core
@Test(description = "Clone should retain any 'deperecated' flags present on operations")
public void cloneRetainDeperecatedFlags() throws IOException {
final OpenAPI openAPI = getOpenAPI(RESOURCE_DEPRECATED_OPERATIONS);
final RemoveUnreferencedDefinitionsFilter remover = new RemoveUnreferencedDefinitionsFilter();
final OpenAPI filtered = new SpecFilter().filter(openAPI, remover, null, null, null);
Operation operation = filtered.getPaths().get("/test").getGet();
Boolean deprectedFlag = operation.getDeprecated();
assertNotNull(deprectedFlag);
assertEquals(deprectedFlag, Boolean.TRUE);
}
代码示例来源:origin: swagger-api/swagger-core
@Test
public void shouldRemoveBrokenRefs() throws IOException {
final OpenAPI openAPI = getOpenAPI(RESOURCE_PATH);
openAPI.getPaths().get("/pet/{petId}").getGet().getResponses().getDefault().getHeaders().remove("X-Rate-Limit-Limit");
assertNotNull(openAPI.getComponents().getSchemas().get("PetHeader"));
final RemoveUnreferencedDefinitionsFilter remover = new RemoveUnreferencedDefinitionsFilter();
final OpenAPI filtered = new SpecFilter().filter(openAPI, remover, null, null, null);
assertNull(filtered.getComponents().getSchemas().get("PetHeader"));
assertNotNull(filtered.getComponents().getSchemas().get("Category"));
assertNotNull(filtered.getComponents().getSchemas().get("Pet"));
}
代码示例来源:origin: swagger-api/swagger-core
@Test(description = "Deserialize ref callback")
public void testDeserializeRefCallback() throws Exception {
String yaml = "openapi: 3.0.1\n" +
"info:\n" +
" description: info\n" +
"paths:\n" +
" /simplecallback:\n" +
" get:\n" +
" summary: Simple get operation\n" +
" operationId: getWithNoParameters\n" +
" responses:\n" +
" 200:\n" +
" description: voila!\n" +
" callbacks:\n" +
" testCallback1:\n" +
" $ref: '#/components/callbacks/Callback'\n" +
" callbacks:\n" +
" testCallback1:\n" +
" $ref: '#/components/callbacks/Callback'\n" +
"components:\n" +
" callbacks:\n" +
" Callback:\n" +
" /post:\n" +
" description: Post Path Item\n";
OpenAPI oas = Yaml.mapper().readValue(yaml, OpenAPI.class);
assertEquals(oas.getPaths().get("/simplecallback").getGet().getCallbacks().get("testCallback1").get$ref(), "#/components/callbacks/Callback");
}
}
代码示例来源:origin: swagger-api/swagger-core
@Test
public void testSerializeASpecWithPathReferences() throws Exception {
OpenAPI swagger = new OpenAPI()
.addServersItem(new Server().url("http://petstore.swagger.io"));
PathItem expectedPath = new PathItem().$ref("http://my.company.com/paths/health.json");
swagger.path("/health", expectedPath);
String swaggerJson = Json.mapper().writeValueAsString(swagger);
OpenAPI rebuilt = Json.mapper().readValue(swaggerJson, OpenAPI.class);
final PathItem path = rebuilt.getPaths().get("/health");
assertEquals(path, expectedPath);
}
代码示例来源:origin: swagger-api/swagger-core
@Test(description = "it should filter any query parameter")
public void filterAwayQueryParameters() throws IOException {
final OpenAPI openAPI = getOpenAPI(RESOURCE_PATH);
final OpenAPI filtered = new SpecFilter().filter(openAPI, new NoParametersWithoutQueryInFilter(), null, null, null);
if (filtered.getPaths() != null) {
for (Map.Entry<String, PathItem> entry : filtered.getPaths().entrySet()) {
validateParameters(entry.getValue().getGet());
validateParameters(entry.getValue().getPost());
validateParameters(entry.getValue().getPut());
validateParameters(entry.getValue().getPatch());
validateParameters(entry.getValue().getHead());
validateParameters(entry.getValue().getDelete());
validateParameters(entry.getValue().getOptions());
}
}
}
代码示例来源:origin: swagger-api/swagger-core
@Test
public void testDeserializeAResponseRef() throws Exception {
final OpenAPI oas = TestUtils.deserializeJsonFileFromClasspath("specFiles/responseRef.json", OpenAPI.class);
final ApiResponses responseMap = oas.getPaths().get("/pet").getPut().getResponses();
// TODO: missing response ref
assertIsRefResponse(responseMap.get("405"), "http://my.company.com/responses/errors.json#/method-not-allowed");
assertIsRefResponse(responseMap.get("404"), "http://my.company.com/responses/errors.json#/not-found");
assertTrue(responseMap.get("400") instanceof ApiResponse);
}
代码示例来源:origin: swagger-api/swagger-core
if (openAPI.getPaths() != null && openAPI.getPaths().get(operationPath) != null) {
pathItemObject = openAPI.getPaths().get(operationPath);
} else {
pathItemObject = new PathItem();
if (openAPI.getPaths() != null) {
this.paths.putAll(openAPI.getPaths());
代码示例来源:origin: swagger-api/swagger-core
@Test
public void testSerializeASpecWithResponseReferences() throws Exception {
OpenAPI swagger = new OpenAPI()
.addServersItem(new Server().url("http://petstore.swagger.io"));
ApiResponse expectedResponse = new ApiResponse().$ref("http://my.company.com/paths/health.json");
PathItem expectedPath = new PathItem()
.get(
new Operation().responses(
new ApiResponses()
.addApiResponse("200", expectedResponse)));
swagger.path("/health", expectedPath);
String swaggerJson = Json.mapper().writeValueAsString(swagger);
OpenAPI rebuilt = Json.mapper().readValue(swaggerJson, OpenAPI.class);
assertEquals(rebuilt.getPaths().get("/health").getGet().getResponses().get("200"), expectedResponse);
}
}
代码示例来源:origin: swagger-api/swagger-core
for (String resourcePath : openAPI.getPaths().keySet()) {
PathItem pathItem = openAPI.getPaths().get(resourcePath);
代码示例来源:origin: com.atlassian.swagger/atlassian-swagger-doclet
public void injectApiVersion(OpenAPI swagger, String configuredApiVersion) {
if (configuredApiVersion != null) {
apiVersion = Optional.of(configuredApiVersion);
} else {
apiVersion = Optional.ofNullable(getApiVersionFromPaths(swagger.getPaths()));
}
apiVersion.ifPresent(version -> {
BiFunction<String, String, String> replacer = getVersionReplaceFunc();
injectApiVersionToPaths(swagger.getPaths(), replacer);
injectApiVersionToDefinitions(swagger.getComponents().getSchemas(), replacer);
injectApiVersionToSecurityDefinitions(swagger.getComponents().getSecuritySchemes(), replacer);
});
}
代码示例来源:origin: org.tomitribe/swagger2markup
private MarkupDocBuilder applyPathsDocument() {
return pathsDocument.apply(
context.createMarkupDocBuilder(),
PathsDocument.parameters(context.getSwagger().getPaths()));
}
内容来源于网络,如有侵权,请联系作者删除!