use of io.swagger.v3.parser.OpenAPIV3Parser in project swagger-parser by swagger-api.
the class OpenAPIDeserializerTest method testEnumType.
@Test
public void testEnumType() {
ParseOptions options = new ParseOptions();
options.setResolve(true);
SwaggerParseResult result = new OpenAPIV3Parser().readLocation("./src/test/resources/issue-1090.yaml", null, options);
assertNotNull(result.getOpenAPI());
OpenAPI openAPI = result.getOpenAPI();
Schema someObj = openAPI.getComponents().getSchemas().get("SomeObj");
assertNotNull(someObj);
Map<String, Schema> properties = someObj.getProperties();
assertNotNull(properties);
Schema iprop = properties.get("iprop");
assertNotNull(iprop);
assertEquals(iprop.getType(), "integer");
assertEquals(iprop.getFormat(), "int32");
Schema lprop = properties.get("lprop");
assertNotNull(lprop);
assertEquals(lprop.getType(), "integer");
assertEquals(lprop.getFormat(), "int64");
Schema nprop = properties.get("nprop");
assertNotNull(nprop);
assertEquals(nprop.getType(), "number");
}
use of io.swagger.v3.parser.OpenAPIV3Parser in project swagger-parser by swagger-api.
the class OpenAPIDeserializerTest method testIssue204_allOf.
@Test
public void testIssue204_allOf() throws Exception {
String yaml = "openapi: 3.0.0\n" + "servers: []\n" + "info:\n" + " version: 2.0.0\n" + " title: Test allOf API\n" + " description: 'Tests the allOf API for parent, interface and child models.'\n" + "paths:\n" + " /:\n" + " get:\n" + " responses:\n" + " '200':\n" + " description: OK\n" + "components:\n" + " schemas:\n" + " Pet:\n" + " type: object\n" + " required:\n" + " - id\n" + " properties:\n" + " id:\n" + " type: integer\n" + " format: int64\n" + " Furry:\n" + " type: object\n" + " required:\n" + " - coatColour\n" + " properties:\n" + " coatColour:\n" + " type: string\n" + " Dog:\n" + " type: object\n" + " allOf:\n" + " - $ref: '#/components/schemas/Pet'\n" + " - $ref: '#/components/schemas/Furry'\n" + " - required:\n" + " - name\n" + " properties:\n" + " name:\n" + " type: string";
OpenAPIV3Parser parser = new OpenAPIV3Parser();
SwaggerParseResult result = parser.readContents(yaml, null, null);
assertTrue(result.getMessages().isEmpty());
OpenAPI openAPI = result.getOpenAPI();
assertNotNull(openAPI);
Map<String, Schema> definitions = openAPI.getComponents().getSchemas();
assertNotNull(definitions);
assertEquals(3, definitions.size());
Schema pet = definitions.get("Pet");
Schema furry = definitions.get("Furry");
Schema dog = definitions.get("Dog");
assertNotNull(pet);
assertNotNull(furry);
assertNotNull(dog);
assertTrue(dog instanceof ComposedSchema);
ComposedSchema dogComposed = (ComposedSchema) dog;
assertNotNull(dogComposed.getAllOf());
assertEquals(3, dogComposed.getAllOf().size());
Schema dogInterfaceRef = dogComposed.getAllOf().get(0);
Schema dogInterface = definitions.get(dogInterfaceRef.get$ref());
dogInterfaceRef = dogComposed.getAllOf().get(1);
dogInterface = definitions.get(dogInterfaceRef.get$ref());
assertTrue(dogComposed.getAllOf().get(0).get$ref() != null);
}
use of io.swagger.v3.parser.OpenAPIV3Parser 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.parser.OpenAPIV3Parser 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"));
}
use of io.swagger.v3.parser.OpenAPIV3Parser in project swagger-parser by swagger-api.
the class OpenAPIDeserializerTest method testPR246.
@Test
public void testPR246() throws Exception {
String yaml = "openapi: 3.0.0\n" + "servers: []\n" + "info:\n" + " description: 'Tests the allOf API for parent, interface and child models.'\n" + " version: 2.0.0\n" + " title: Test allOf API\n" + "paths:\n" + " /:\n" + " get:\n" + " responses:\n" + " '200':\n" + " description: OK\n" + " parameters: []\n" + "components:\n" + " schemas:\n" + " Pet:\n" + " type: object\n" + " required:\n" + " - id\n" + " properties:\n" + " id:\n" + " type: integer\n" + " format: int64\n" + " Furry:\n" + " type: object\n" + " required:\n" + " - coatColour\n" + " properties:\n" + " coatColour:\n" + " type: string\n" + " Dog:\n" + " allOf:\n" + " - $ref: '#/components/schemas/Pet'\n" + " - $ref: '#/components/schemas/Furry'\n" + " - type: object\n" + " required:\n" + " - name\n" + " properties:\n" + " name:\n" + " type: string";
OpenAPIV3Parser parser = new OpenAPIV3Parser();
SwaggerParseResult result = parser.readContents(yaml, null, null);
OpenAPI openAPI = result.getOpenAPI();
Schema dog = openAPI.getComponents().getSchemas().get("Dog");
assertNotNull(dog);
assertTrue(dog instanceof ComposedSchema);
ComposedSchema composed = (ComposedSchema) dog;
assertTrue(composed.getAllOf().get(0).get$ref() != null);
assertTrue(composed.getAllOf().size() == 3);
}
Aggregations