use of io.swagger.v3.parser.core.models.AuthorizationValue in project swagger-parser by swagger-api.
the class NetworkReferenceTest method testIssue742.
@Test
public void testIssue742() throws Exception {
final List<AuthorizationValue> auths = new ArrayList<>();
new Expectations() {
{
remoteUrl.urlToString("http://www.example.io/one/two/swagger.json", auths);
result = issue_742_json;
}
};
OpenAPIV3Parser parser = new OpenAPIV3Parser();
ParseOptions options = new ParseOptions();
options.setResolve(true);
SwaggerParseResult result = parser.readLocation("http://www.example.io/one/two/swagger.json", auths, options);
Assert.assertNotNull(result.getOpenAPI());
Assert.assertNotNull(result.getOpenAPI().getServers());
Assert.assertEquals(result.getOpenAPI().getServers().size(), 4);
Assert.assertEquals(result.getOpenAPI().getServers().get(0).getDescription(), "An absolute path");
Assert.assertEquals(result.getOpenAPI().getServers().get(0).getUrl(), "https://api.absolute.org/v2");
Assert.assertEquals(result.getOpenAPI().getServers().get(1).getDescription(), "Server relative to root path");
Assert.assertEquals(result.getOpenAPI().getServers().get(1).getUrl(), "http://www.example.io/api/v2");
Assert.assertEquals(result.getOpenAPI().getServers().get(2).getDescription(), "Server relative path 1");
Assert.assertEquals(result.getOpenAPI().getServers().get(2).getUrl(), "http://www.example.io/one/two/path/v2");
Assert.assertEquals(result.getOpenAPI().getServers().get(3).getDescription(), "Server relative path 2");
Assert.assertEquals(result.getOpenAPI().getServers().get(3).getUrl(), "http://www.example.io/one/v2");
}
use of io.swagger.v3.parser.core.models.AuthorizationValue in project swagger-parser by swagger-api.
the class OpenAPIResolverTest method allOfExampleGeneration.
@Test
public void allOfExampleGeneration(@Injectable final List<AuthorizationValue> auths) throws JsonProcessingException {
ParseOptions options = new ParseOptions();
options.setResolve(true);
options.setResolveFully(true);
OpenAPI openAPI = new OpenAPIV3Parser().read("src/test/resources/simpleAllOf.yaml", null, options);
Assert.assertNotNull(openAPI);
Object withoutExample = openAPI.getPaths().get("/foo").getGet().getResponses().get("200").getContent().get("application/json").getSchema().getExample();
Assert.assertNull(withoutExample);
Object withExample = openAPI.getPaths().get("/bar").getGet().getResponses().get("200").getContent().get("application/json").getSchema().getExample();
Assert.assertEquals("{\"someProperty\":\"ABC\",\"someOtherProperty\":42}", Json.mapper().writeValueAsString(withExample));
}
use of io.swagger.v3.parser.core.models.AuthorizationValue in project swagger-parser by swagger-api.
the class OpenAPIResolverTest method testIssue85.
@Test
public void testIssue85(@Injectable final List<AuthorizationValue> auths) {
String yaml = "openapi: '3.0.1'\n" + "paths: \n" + " /test/method: \n" + " post: \n" + " parameters: \n" + " - \n" + " in: \"path\"\n" + " name: \"body\"\n" + " required: false\n" + " schema: \n" + " $ref: '#/components/Schemas/StructureA'\n" + "components: \n" + " schemas:\n" + " StructureA: \n" + " type: object\n" + " properties: \n" + " someProperty: \n" + " type: string\n" + " arrayOfOtherType: \n" + " type: array\n" + " items: \n" + " $ref: '#/definitions/StructureB'\n" + " StructureB: \n" + " type: object\n" + " properties: \n" + " someProperty: \n" + " type: string\n";
ParseOptions options = new ParseOptions();
options.setResolve(true);
options.setResolveFully(true);
OpenAPI openAPI = new OpenAPIV3Parser().readContents(yaml, auths, options).getOpenAPI();
ResolverFully resolverUtil = new ResolverFully();
resolverUtil.resolveFully(openAPI);
Parameter param = openAPI.getPaths().get("/test/method").getPost().getParameters().get(0);
Schema schema = param.getSchema();
assertNotNull(schema.getProperties().get("someProperty"));
ArraySchema am = (ArraySchema) schema.getProperties().get("arrayOfOtherType");
assertNotNull(am);
Schema prop = am.getItems();
assertTrue(prop instanceof Schema);
}
use of io.swagger.v3.parser.core.models.AuthorizationValue in project swagger-parser by swagger-api.
the class OpenAPIResolverTest method testIssue1161.
@Test
public void testIssue1161(@Injectable final List<AuthorizationValue> auths) {
String path = "/issue-1161/swagger.yaml";
ParseOptions options = new ParseOptions();
options.setResolve(true);
options.setResolveFully(true);
OpenAPI openAPI = new OpenAPIV3Parser().readLocation(path, auths, options).getOpenAPI();
Schema petsSchema = openAPI.getComponents().getSchemas().get("Pets");
Schema colouringsSchema = openAPI.getComponents().getSchemas().get("Colouring");
assertNotNull(petsSchema);
assertNotNull(colouringsSchema);
assertTrue(petsSchema instanceof ComposedSchema);
assertTrue(petsSchema.getProperties() != null);
assertTrue(((ComposedSchema) petsSchema).getOneOf() != null);
Schema petsColouringProperty = (Schema) petsSchema.getProperties().get("colouring");
assertTrue(petsColouringProperty.get$ref() == null);
assertTrue(petsColouringProperty == colouringsSchema);
}
use of io.swagger.v3.parser.core.models.AuthorizationValue in project swagger-parser by swagger-api.
the class OpenAPIV3ParserTest method test30NoOptions.
@Test
public void test30NoOptions(@Injectable final List<AuthorizationValue> auths) throws Exception {
String pathFile = FileUtils.readFileToString(new File("src/test/resources/oas3.yaml.template"));
pathFile = pathFile.replace("${dynamicPort}", String.valueOf(this.serverPort));
SwaggerParseResult result = new OpenAPIV3Parser().readContents(pathFile, auths, null);
Assert.assertNotNull(result);
Assert.assertNotNull(result.getOpenAPI());
assertEquals(result.getOpenAPI().getOpenapi(), "3.0.1");
assertEquals(result.getOpenAPI().getComponents().getSchemas().get("OrderRef").getType(), "object");
}
Aggregations