use of io.swagger.v3.oas.models.info.Info 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);
}
use of io.swagger.v3.oas.models.info.Info 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());
}
use of io.swagger.v3.oas.models.info.Info in project swagger-parser by swagger-api.
the class OpenAPIResolverTest method testSettingsAddParametersToEachOperationDisabled.
@Test
public void testSettingsAddParametersToEachOperationDisabled() {
String yaml = "openapi: 3.0.0\n" + "servers: []\n" + "info:\n" + " title: test spec\n" + " version: '1.0'\n" + "paths:\n" + " '/test/{id}':\n" + " parameters:\n" + " - name: id\n" + " in: path\n" + " required: true\n" + " schema:\n" + " type: string\n" + " get:\n" + " description: test get\n" + " parameters:\n" + " - name: page\n" + " in: query\n" + " schema:\n" + " type: string\n" + " responses:\n" + " default:\n" + " description: test response";
OpenAPIV3Parser parser = new OpenAPIV3Parser();
SwaggerParseResult result = parser.readContents(yaml, null, null);
OpenAPI swagger = result.getOpenAPI();
final OpenAPI resolved = new OpenAPIResolver(swagger, null, null, new OpenAPIResolver.Settings().addParametersToEachOperation(false)).resolve();
assertEquals(resolved.getPaths().get("/test/{id}").getParameters().size(), 1);
PathParameter pp = (PathParameter) resolved.getPaths().get("/test/{id}").getParameters().get(0);
assertEquals(pp.getName(), "id");
assertEquals(resolved.getPaths().get("/test/{id}").getGet().getParameters().size(), 1);
QueryParameter qp = (QueryParameter) resolved.getPaths().get("/test/{id}").getGet().getParameters().get(0);
assertEquals(qp.getName(), "page");
}
use of io.swagger.v3.oas.models.info.Info in project swagger-parser by swagger-api.
the class OpenAPIV3ParserTest method testIssue1644_NullValue.
@Test
public void testIssue1644_NullValue() throws Exception {
ParseOptions options = new ParseOptions();
String issue1644 = "openapi: 3.0.0\n" + "info:\n" + " title: Operations\n" + " version: 0.0.0\n" + "paths:\n" + " \"/operations\":\n" + " post:\n" + " parameters:\n" + " - name: param0\n" + " schema:\n" + " type: string\n" + " responses:\n" + " default:\n" + " description: None\n";
SwaggerParseResult result = new OpenAPIV3Parser().readContents(issue1644, null, options);
Assert.assertNotNull(result);
Assert.assertNotNull(result.getOpenAPI());
assertEquals(result.getMessages().size(), 1);
assertTrue(result.getMessages().contains("attribute paths.'/operations'(post).parameters.[param0].in is missing"));
assertFalse(result.getMessages().contains("attribute paths.'/operations'(post).parameters.[param0].in is not of type `string`"));
}
use of io.swagger.v3.oas.models.info.Info in project swagger-parser by swagger-api.
the class OpenAPIDeserializer method getInfo.
public Info getInfo(ObjectNode node, String location, ParseResult result) {
if (node == null)
return null;
Info info = new Info();
String value = getString("title", node, true, location, result);
if ((result.isAllowEmptyStrings() && value != null) || (!result.isAllowEmptyStrings() && !StringUtils.isBlank(value))) {
info.setTitle(value);
}
value = getString("description", node, false, location, result);
if ((result.isAllowEmptyStrings() && value != null) || (!result.isAllowEmptyStrings() && !StringUtils.isBlank(value))) {
info.setDescription(value);
}
value = getString("termsOfService", node, false, location, result);
if ((result.isAllowEmptyStrings() && value != null) || (!result.isAllowEmptyStrings() && !StringUtils.isBlank(value))) {
info.setTermsOfService(value);
}
ObjectNode obj = getObject("contact", node, false, "contact", result);
Contact contact = getContact(obj, String.format("%s.%s", location, "contact"), result);
if (obj != null) {
info.setContact(contact);
}
obj = getObject("license", node, false, location, result);
License license = getLicense(obj, String.format("%s.%s", location, "license"), result);
if (obj != null) {
info.setLicense(license);
}
value = getString("version", node, true, location, result);
if ((result.isAllowEmptyStrings() && value != null) || (!result.isAllowEmptyStrings() && !StringUtils.isBlank(value))) {
info.setVersion(value);
}
Map<String, Object> extensions = getExtensions(node);
if (extensions != null && extensions.size() > 0) {
info.setExtensions(extensions);
}
Set<String> keys = getKeys(node);
for (String key : keys) {
if (!INFO_KEYS.contains(key) && !key.startsWith("x-")) {
result.extra(location, key, node.get(key));
}
}
return info;
}
Aggregations