use of io.swagger.v3.parser.OpenAPIV3Parser in project swagger-parser by swagger-api.
the class OAIDeserializationTest method testDeserializeSimpleDefinition.
@Test
public void testDeserializeSimpleDefinition() throws Exception {
String json = "{\n" + " \"openapi\": \"3.0.1\",\n" + " \"info\": {\n" + " \"title\": \"Swagger Petstore\",\n" + " \"description\": \"This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters.\",\n" + " \"termsOfService\": \"http://swagger.io/terms/\",\n" + " \"contact\": {\n" + " \"email\": \"apiteam@swagger.io\"\n" + " },\n" + " \"license\": {\n" + " \"name\": \"Apache 2.0\",\n" + " \"url\": \"http://www.apache.org/licenses/LICENSE-2.0.html\"\n" + " },\n" + " \"version\": \"1.0.0\"\n" + " }\n" + "}";
ParseOptions options = new ParseOptions();
options.setResolve(true);
SwaggerParseResult result = new OpenAPIV3Parser().readContents(json, null, options);
assertNotNull(result.getOpenAPI());
}
use of io.swagger.v3.parser.OpenAPIV3Parser in project swagger-parser by swagger-api.
the class NetworkReferenceTest method testIssue330.
@Test
public void testIssue330() throws Exception {
new Expectations() {
{
remoteUrl.urlToString("http://server1/resources/swagger.yaml", new ArrayList<>());
result = issue_330_yaml;
remoteUrl.urlToString("http://server1/resources/common/paging.yaml", new ArrayList<>());
result = issue_330_paging_yaml;
remoteUrl.urlToString("http://server1/resources/common/users.yaml", new ArrayList<>());
result = issue_330_users_yaml;
remoteUrl.urlToString("http://server2/resources/common/entities.yaml", new ArrayList<>());
result = issue_330_entities_yaml;
}
};
ParseOptions options = new ParseOptions();
options.setResolve(true);
SwaggerParseResult result = new OpenAPIV3Parser().readLocation("http://server1/resources/swagger.yaml", new ArrayList<>(), options);
assertNotNull(result.getOpenAPI());
OpenAPI swagger = result.getOpenAPI();
assertNotNull(swagger.getPaths().get("/events"));
assertNotNull(swagger.getComponents().getSchemas().get("Address"));
assertNotNull(swagger.getComponents().getSchemas().get("Paging"));
assertNotNull(swagger.getComponents().getSchemas().get("users"));
assertNotNull(swagger.getComponents().getSchemas().get("Phone"));
}
use of io.swagger.v3.parser.OpenAPIV3Parser in project swagger-parser by swagger-api.
the class OpenAPIResolverTest method referringSpecWithoutComponentsTag.
@Test
public void referringSpecWithoutComponentsTag() throws Exception {
ParseOptions resolve = new ParseOptions();
resolve.setResolveFully(true);
final OpenAPI openAPI = new OpenAPIV3Parser().read("./ref-without-component/a.yaml", null, resolve);
Map<String, Schema> schemas = openAPI.getComponents().getSchemas();
Assert.assertEquals("Example value", schemas.get("CustomerType").getExample());
}
use of io.swagger.v3.parser.OpenAPIV3Parser in project swagger-parser by swagger-api.
the class OpenAPIResolverTest method testIssue1352.
@Test
public void testIssue1352(@Injectable final List<AuthorizationValue> auths) {
ParseOptions options = new ParseOptions();
options.setResolve(true);
options.setResolveFully(true);
OpenAPI openAPI = new OpenAPIV3Parser().readLocation("issue-1352.json", auths, options).getOpenAPI();
assertNull(openAPI.getPaths().get("/responses").getPatch().getResponses().get("200").getHeaders().get("x-my-secret-header").getSchema().get$ref());
}
use of io.swagger.v3.parser.OpenAPIV3Parser in project swagger-parser by swagger-api.
the class OpenAPIResolverTest method testParameterOnPathLevel.
@Test
public void testParameterOnPathLevel() throws Exception {
String yaml = "openapi: 3.0.1\n" + "info:\n" + " version: '1.0.0'\n" + " title: 'title'\n" + " description: 'description'\n" + "paths:\n" + " /foo:\n" + " parameters:\n" + " - in: query\n" + " name: bar\n" + " schema:\n" + " type: string\n" + " get:\n" + " responses:\n" + " '200':\n" + " description: OK";
ParseOptions options = new ParseOptions();
options.setResolve(true);
OpenAPI openAPI = new OpenAPIV3Parser().readContents(yaml, null, options).getOpenAPI();
assertNotNull(openAPI);
List<Parameter> getParameters = openAPI.getPaths().get("/foo").getGet().getParameters();
assertNotNull(getParameters);
assertEquals(1, getParameters.size());
assertEquals("bar", getParameters.get(0).getName());
}
Aggregations