use of io.swagger.v3.oas.models.info.Info in project swagger-parser by swagger-api.
the class OpenAPIDeserializerTest method testIssue151.
@Test
public void testIssue151() throws Exception {
String yaml = "openapi: 3.0.0\n" + "servers: []\n" + "info:\n" + " version: 2.0.0\n" + " title: Test Issue 151\n" + " description: Tests that ComposedSchema vendor extensions are deserialized correctly.\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" + " Dog:\n" + " type: object\n" + " allOf:\n" + " - $ref: '#/components/schemas/Pet'\n" + " - required:\n" + " - name\n" + " properties:\n" + " name:\n" + " type: string\n" + " x-vendor-ext: some data";
OpenAPIV3Parser parser = new OpenAPIV3Parser();
SwaggerParseResult result = parser.readContents(yaml, null, null);
assertTrue(result.getMessages().isEmpty());
OpenAPI openAPI = result.getOpenAPI();
Map<String, Schema> definitions = openAPI.getComponents().getSchemas();
assertTrue(definitions.size() == 2);
Schema allOfModel = definitions.get("Dog");
assertTrue(allOfModel instanceof ComposedSchema);
assertFalse(allOfModel.getExtensions().isEmpty());
assertEquals("some data", allOfModel.getExtensions().get("x-vendor-ext"));
}
use of io.swagger.v3.oas.models.info.Info in project swagger-parser by swagger-api.
the class OpenAPIDeserializerTest method testSecurityDefinition.
@Test
public void testSecurityDefinition() {
String yaml = "openapi: 3.0.0\n" + "servers: []\n" + "paths:\n" + " /pet:\n" + " get:\n" + " security:\n" + " - basic_auth: []\n" + " api_key: []\n" + " responses:\n" + " default:\n" + " description: Default response\n" + "info:\n" + " version: ''\n" + " title: ''\n" + "components:\n" + " securitySchemes:\n" + " basic_auth:\n" + " type: http\n" + " x-foo: basicBar\n" + " scheme: basic\n" + " api_key:\n" + " type: apiKey\n" + " name: api_key\n" + " in: header\n" + " description: api key description\n" + " x-foo: apiKeyBar";
OpenAPIV3Parser parser = new OpenAPIV3Parser();
SwaggerParseResult result = parser.readContents(yaml, null, null);
OpenAPI openAPI = result.getOpenAPI();
assertNotNull(openAPI.getComponents().getSecuritySchemes());
assertTrue(openAPI.getComponents().getSecuritySchemes().keySet().size() == 2);
// Basic Authentication
SecurityScheme definitionBasic = openAPI.getComponents().getSecuritySchemes().get("basic_auth");
assertNotNull(definitionBasic);
assertEquals(definitionBasic.getType(), SecurityScheme.Type.HTTP);
assertEquals(definitionBasic.getExtensions().get("x-foo"), "basicBar");
// API Key Authentication
SecurityScheme definition = openAPI.getComponents().getSecuritySchemes().get("api_key");
assertNotNull(definition);
assertEquals(definition.getType(), SecurityScheme.Type.APIKEY);
SecurityScheme apiKey = definition;
assertEquals(apiKey.getName(), "api_key");
assertEquals(apiKey.getIn(), SecurityScheme.In.HEADER);
assertEquals(apiKey.getDescription(), "api key description");
assertEquals(apiKey.getExtensions().get("x-foo"), "apiKeyBar");
}
use of io.swagger.v3.oas.models.info.Info in project swagger-parser by swagger-api.
the class OpenAPIDeserializerTest method testAlmostEmpty.
@Test
public void testAlmostEmpty(@Injectable List<AuthorizationValue> auths) {
String yaml = "openapi: '3.0.1'\n" + "new: extra";
OpenAPIV3Parser parser = new OpenAPIV3Parser();
ParseOptions options = new ParseOptions();
options.setResolve(true);
SwaggerParseResult result = parser.readContents(yaml, auths, options);
List<String> messageList = result.getMessages();
Set<String> messages = new HashSet<>(messageList);
assertTrue(messages.contains("attribute info is missing"));
assertTrue(messages.contains("attribute paths is missing"));
assertTrue(messages.contains("attribute new is unexpected"));
}
use of io.swagger.v3.oas.models.info.Info in project swagger-parser by swagger-api.
the class OpenAPIDeserializerTest method testContact.
@Test
public void testContact() {
String yaml = "openapi: 3.0.0\n" + "servers: []\n" + "info:\n" + " title: title\n" + " bad: bad\n" + " x-foo: bar\n" + " description: description\n" + " termsOfService: tos\n" + " contact:\n" + " name: tony\n" + " url: url\n" + " email: email\n" + " invalid: invalid\n" + " x-fun: true\n" + " version: version\n" + "paths: {}";
OpenAPIV3Parser parser = new OpenAPIV3Parser();
SwaggerParseResult result = parser.readContents(yaml, null, null);
List<String> messageList = result.getMessages();
Set<String> messages = new HashSet<>(messageList);
assertEquals(result.getOpenAPI().getInfo().getTitle(), "title");
assertEquals(result.getOpenAPI().getInfo().getDescription(), "description");
assertEquals(result.getOpenAPI().getInfo().getTermsOfService(), "tos");
assertEquals(result.getOpenAPI().getInfo().getVersion(), "version");
Contact contact = result.getOpenAPI().getInfo().getContact();
assertEquals(contact.getName(), "tony");
assertEquals(contact.getUrl(), "url");
assertEquals(contact.getEmail(), "email");
assertTrue(messages.contains("attribute info.bad is unexpected"));
assertTrue(messages.contains("attribute info.contact.invalid is unexpected"));
assertEquals(result.getOpenAPI().getInfo().getExtensions().get("x-foo").toString(), "bar");
}
use of io.swagger.v3.oas.models.info.Info in project swagger-parser by swagger-api.
the class OpenAPIDeserializerTest method readInfoObject.
@Test(dataProvider = "data")
public void readInfoObject(JsonNode rootNode) throws Exception {
final OpenAPIDeserializer deserializer = new OpenAPIDeserializer();
final SwaggerParseResult result = deserializer.deserialize(rootNode);
Assert.assertNotNull(result);
final OpenAPI openAPI = result.getOpenAPI();
Assert.assertNotNull(openAPI);
Assert.assertEquals(openAPI.getOpenapi(), "3.0.1");
final Info info = openAPI.getInfo();
Assert.assertNotNull(info);
Assert.assertEquals(info.getTitle(), "Sample Pet Store App");
Assert.assertEquals(info.getDescription(), "This is a sample server Petstore");
Assert.assertEquals(info.getTermsOfService(), "http://swagger.io/terms/");
Assert.assertNotNull(info.getExtensions().get("x-info"));
Assert.assertEquals(info.getExtensions().get("x-info").toString(), "info extension");
final Contact contact = info.getContact();
Assert.assertNotNull(contact);
Assert.assertEquals(contact.getName(), "API Support");
Assert.assertEquals(contact.getUrl(), "http://www.example.com/support");
Assert.assertEquals(contact.getEmail(), "support@example.com");
Assert.assertNotNull(contact.getExtensions().get("x-contact"));
Assert.assertEquals(contact.getExtensions().get("x-contact").toString(), "contact extension");
final License license = info.getLicense();
Assert.assertNotNull(license);
Assert.assertEquals(license.getName(), "Apache 2.0");
Assert.assertEquals(license.getUrl(), "http://www.apache.org/licenses/LICENSE-2.0.html");
Assert.assertNotNull(license.getExtensions());
Assert.assertEquals(info.getVersion(), "1.0.1");
}
Aggregations