use of io.swagger.v3.jaxrs2.resources.model.Pet 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.jaxrs2.resources.model.Pet 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");
}
use of io.swagger.v3.jaxrs2.resources.model.Pet in project swagger-parser by swagger-api.
the class OpenAPIDeserializerTest method testIssue247.
@Test
public void testIssue247() {
String yaml = "openapi: 3.0.0\n" + "servers: []\n" + "info:\n" + " description: bleh\n" + " version: 2.0.0\n" + " title: Test\n" + "paths:\n" + " /:\n" + " get:\n" + " responses:\n" + " '200':\n" + " description: OK\n" + " parameters: []\n" + "components:\n" + " schemas:\n" + " Pet:\n" + " allOf:\n" + " - type: object\n" + " required:\n" + " - id\n" + " properties:\n" + " id:\n" + " type: integer\n" + " format: int64";
OpenAPIV3Parser parser = new OpenAPIV3Parser();
SwaggerParseResult result = parser.readContents(yaml, null, null);
OpenAPI openAPI = result.getOpenAPI();
assertNotNull(openAPI.getComponents().getSchemas().get("Pet"));
}
use of io.swagger.v3.jaxrs2.resources.model.Pet in project swagger-parser by swagger-api.
the class OpenAPIDeserializerTest method readSchemaArray.
@Test(dataProvider = "data")
public void readSchemaArray(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);
final Paths paths = openAPI.getPaths();
Assert.assertNotNull(paths);
Assert.assertEquals(paths.size(), 19);
// parameters operation get
PathItem petByStatusEndpoint = paths.get("/pet/findByTags");
Assert.assertNotNull(petByStatusEndpoint.getGet());
Assert.assertNotNull(petByStatusEndpoint.getGet().getParameters());
Assert.assertEquals(petByStatusEndpoint.getGet().getParameters().size(), 1);
Assert.assertNotNull(petByStatusEndpoint.getGet().getParameters().get(0).getSchema());
Assert.assertEquals(petByStatusEndpoint.getGet().getParameters().get(0).getSchema().getType(), "array");
Assert.assertEquals(((ArraySchema) (petByStatusEndpoint.getGet().getParameters().get(0).getSchema())).getItems().getType(), "string");
Assert.assertEquals(petByStatusEndpoint.getGet().getParameters().get(0).getName(), "tags");
Assert.assertEquals(petByStatusEndpoint.getGet().getParameters().get(0).getExplode(), Boolean.TRUE);
Assert.assertEquals(petByStatusEndpoint.getGet().getParameters().get(0).getStyle(), StyleEnum.FORM);
}
use of io.swagger.v3.jaxrs2.resources.model.Pet in project swagger-parser by swagger-api.
the class OpenAPIDeserializerTest method testDiscriminatorObject.
@Test
void testDiscriminatorObject(@Injectable List<AuthorizationValue> auths) {
String yaml = "openapi: '3.0.1'\n" + "components:\n" + " schemas:\n" + " Pet:\n" + " type: object\n" + " required:\n" + " - pet_type\n" + " properties:\n" + " pet_type:\n" + " type: string\n" + " discriminator:\n" + " propertyName: pet_type\n" + " mapping:\n" + " cachorro: Dog\n" + " Cat:\n" + " allOf:\n" + " - $ref: '#/components/schemas/Pet'\n" + " - type: object\n" + " # all other properties specific to a `Cat`\n" + " properties:\n" + " name:\n" + " type: string\n" + " Dog:\n" + " allOf:\n" + " - $ref: '#/components/schemas/Pet'\n" + " - type: object\n" + " # all other properties specific to a `Dog`\n" + " properties:\n" + " bark:\n" + " type: string\n" + " Lizard:\n" + " allOf:\n" + " - $ref: '#/components/schemas/Pet'\n" + " - type: object\n" + " # all other properties specific to a `Lizard`\n" + " properties:\n" + " lovesRocks:\n" + " type: boolean";
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);
assertEquals(result.getOpenAPI().getComponents().getSchemas().get("Pet").getDiscriminator().getPropertyName(), "pet_type");
assertEquals(result.getOpenAPI().getComponents().getSchemas().get("Pet").getDiscriminator().getMapping().get("cachorro"), "Dog");
assertTrue(messages.contains("attribute paths is missing"));
assertTrue(messages.contains("attribute info is missing"));
}
Aggregations