use of io.swagger.v3.oas.models.Paths in project swagger-parser by swagger-api.
the class OpenAPIDeserializerTest method testIssue161.
@Test
public void testIssue161() {
String yaml = "openapi: 3.0.0\n" + "servers: []\n" + "paths:\n" + " /users:\n" + " get:\n" + " parameters:\n" + " - in: query\n" + " name: name\n" + " required: false\n" + " schema:\n" + " type: string\n" + " minLength: 10\n" + " maxLength: 100\n" + " responses:\n" + " default:\n" + " description: ok\n";
OpenAPIV3Parser parser = new OpenAPIV3Parser();
SwaggerParseResult result = parser.readContents(yaml, null, null);
Set<String> messages = new HashSet<>(result.getMessages());
assertFalse(messages.contains("attribute paths.'/users'(get).[name].maxLength is unexpected"));
}
use of io.swagger.v3.oas.models.Paths in project swagger-parser by swagger-api.
the class OpenAPIDeserializerTest method testStyleInvalid.
@Test
public void testStyleInvalid() {
String json = "{" + " \"openapi\": \"3.0.0\"," + " \"info\": {" + " \"title\": \"realize\"," + " \"version\": \"0.0.0\"" + " }," + " \"paths\": {" + " \"/realize/{param}\": {" + " \"post\": {" + " \"parameters\": [" + " {" + " \"name\": \"param\"," + " \"in\": \"path\"," + "" + " \"style\": \"DERP\"," + " \"required\": true," + "" + " \"schema\": {" + " \"type\": \"string\"," + " \"nullable\": false," + " \"minLength\": 1" + " }" + " }" + " ]," + " \"responses\": {" + " \"200\": {" + " \"description\": \"Success\"," + " \"content\": {" + " \"application/json\": {" + " \"schema\": {" + " \"type\": \"object\"" + " }" + " }" + " }" + " }" + " }" + " }" + " }" + " }" + "}";
OpenAPIV3Parser parser = new OpenAPIV3Parser();
SwaggerParseResult result = parser.readContents(json, null, null);
assertTrue(result.getMessages().size() == 1);
assertEquals(result.getMessages().get(0), "attribute paths.'/realize/{param}'(post).parameters.[param].style is not of type `StyleEnum`");
}
use of io.swagger.v3.oas.models.Paths in project swagger-parser by swagger-api.
the class OpenAPIDeserializerTest method testBodyContent.
@Test
public void testBodyContent() {
String json = "{" + " \"openapi\": \"3.0.0\"," + " \"info\": {" + " \"title\": \"Operations\"," + " \"version\": \"0.0.0\"" + " }," + " \"paths\": {" + " \"/operations\": {" + " \"post\": {" + " \"requestBody\": {" + " \"description\": \"Content empty\"," + " \"content\": {" + " }" + " }," + " \"responses\": {" + " \"default\": {" + " \"description\": \"None\"" + " }" + " }" + " }," + " \"put\": {" + " \"requestBody\": {" + " \"description\": \"Content undefined\"" + " }," + " \"responses\": {" + " \"default\": {" + " \"description\": \"None\"" + " }" + " }" + " }" + " }" + " }" + "}";
OpenAPIV3Parser parser = new OpenAPIV3Parser();
SwaggerParseResult result = parser.readContents(json, null, null);
Operation post = result.getOpenAPI().getPaths().get("/operations").getPost();
assertEquals(post.getRequestBody().getContent(), null, "Empty content");
assertEquals(result.getMessages().contains("attribute paths.'/operations'(post).requestBody.content with no media type is unsupported"), true, "Empty content error reported");
Operation put = result.getOpenAPI().getPaths().get("/operations").getPut();
assertEquals(put.getRequestBody().getContent(), null, "Empty content");
assertEquals(result.getMessages().contains("attribute paths.'/operations'(put).requestBody.content is missing"), true, "Missing content error reported");
assertEquals(result.getMessages().size(), 2, "Messages");
}
use of io.swagger.v3.oas.models.Paths in project swagger-parser by swagger-api.
the class OpenAPIDeserializerTest method testIssue386.
@Test
public void testIssue386() {
String yaml = "openapi: 3.0.0\n" + "servers: []\n" + "info:\n" + " description: bleh\n" + " version: 2.0.0\n" + " title: Test\n" + "paths:\n" + " /foo:\n" + " post:\n" + " responses:\n" + " '200':\n" + " description: OK\n" + " requestBody:\n" + " content:\n" + " application/json:\n" + " schema:\n" + " type: object\n" + " enum:\n" + " - id: fun\n" + " properties:\n" + " id:\n" + " type: string\n" + "components:\n" + " schemas:\n" + " Fun:\n" + " type: object\n" + " properties:\n" + " complex:\n" + " enum:\n" + " - id: 110\n" + " type: object\n" + " properties:\n" + " id:\n" + " type: string\n" + " MyEnum:\n" + " type: integer\n" + " enum:\n" + " - value: 3\n" + " description: Value 1\n" + " - value: 10\n" + " description: Value 2";
OpenAPIV3Parser parser = new OpenAPIV3Parser();
SwaggerParseResult result = parser.readContents(yaml, null, null);
OpenAPI openAPI = result.getOpenAPI();
assertNotNull(openAPI);
}
use of io.swagger.v3.oas.models.Paths in project swagger-parser by swagger-api.
the class OpenAPIDeserializerTest method testPaths.
@Test
public void testPaths() {
String json = "{\n" + " \"openapi\": \"3.0.0\",\n" + " \"paths\": {\n" + " \"/pet\": {\n" + " \"foo\": \"bar\",\n" + " \"get\": {\n" + " \"security\": [\n" + " {\n" + " \"petstore_auth\": [\n" + " \"write:pets\",\n" + " \"read:pets\"\n" + " ]\n" + " }\n" + " ]\n" + " }\n" + " }\n" + " }\n" + "}";
OpenAPIV3Parser parser = new OpenAPIV3Parser();
SwaggerParseResult result = parser.readContents(json, null, null);
List<String> messageList = result.getMessages();
Set<String> messages = new HashSet<>(messageList);
assertTrue(messages.contains("attribute paths.'/pet'.foo is unexpected"));
OpenAPI openAPI = result.getOpenAPI();
PathItem path = openAPI.getPaths().get("/pet");
assertNotNull(path);
Operation operation = path.getGet();
assertNotNull(operation);
List<SecurityRequirement> security = operation.getSecurity();
assertTrue(security.size() == 1);
Map<String, List<String>> requirement = security.get(0);
assertTrue(requirement.containsKey("petstore_auth"));
List<String> scopesList = requirement.get("petstore_auth");
Set<String> scopes = new HashSet<>(scopesList);
assertTrue(scopes.contains("read:pets"));
assertTrue(scopes.contains("write:pets"));
}
Aggregations