use of io.gravitee.rest.api.service.swagger.OAIDescriptor in project gravitee-management-rest-api by gravitee-io.
the class SwaggerService_ParseTest method shouldReturnErrorMessageExceptionWhenParseSwaggerV2WithoutInfo_yaml.
@Test
public void shouldReturnErrorMessageExceptionWhenParseSwaggerV2WithoutInfo_yaml() throws IOException {
PageEntity pageEntity = getPage("io/gravitee/rest/api/management/service/swagger-v2-no-info.yaml", MediaType.TEXT_PLAIN);
OAIDescriptor descriptor = (OAIDescriptor) swaggerService.parse(pageEntity.getContent());
assertNotNull(descriptor.getMessages());
assertEquals("attribute info is missing", descriptor.getMessages().get(0));
}
use of io.gravitee.rest.api.service.swagger.OAIDescriptor in project gravitee-management-rest-api by gravitee-io.
the class SwaggerService_ParseTest method shouldThrowSwaggerDescriptorExceptionWhenParseSwaggerV3WithoutInfo_yaml.
@Test
public void shouldThrowSwaggerDescriptorExceptionWhenParseSwaggerV3WithoutInfo_yaml() throws IOException {
PageEntity pageEntity = getPage("io/gravitee/rest/api/management/service/openapi-no-info.yaml", MediaType.TEXT_PLAIN);
OAIDescriptor descriptor = (OAIDescriptor) swaggerService.parse(pageEntity.getContent());
assertNotNull(descriptor.getMessages());
assertEquals("attribute info is missing", descriptor.getMessages().get(0));
}
use of io.gravitee.rest.api.service.swagger.OAIDescriptor in project gravitee-management-rest-api by gravitee-io.
the class OAIParser method parse.
public OAIDescriptor parse(String content, ParseOptions options) {
OpenAPIParser parser = new OpenAPIParser();
SwaggerParseResult parseResult;
String path = content;
File temp = null;
if (!isLocationUrl(content)) {
// Swagger v1 supports only a URL to read swagger: create temporary file for Swagger parser
temp = createTempFile(content);
path = temp.getAbsolutePath();
}
parseResult = parser.readLocation(path, null, options);
if (temp != null) {
temp.delete();
}
/* Hack due to swagger v1 converting issue
* See https://github.com/swagger-api/swagger-parser/issues/1451
*/
if (parseResult.getMessages() != null) {
final List<String> filteredMessages = parseResult.getMessages().stream().filter(message -> message != null && !message.matches("^attribute info.contact.*")).collect(Collectors.toList());
parseResult.setMessages(filteredMessages);
}
if (parseResult.getOpenAPI() == null) {
throw new SwaggerDescriptorException("Malformed descriptor");
}
OAIDescriptor descriptor = new OAIDescriptor(parseResult.getOpenAPI());
descriptor.setMessages(parseResult.getMessages());
return descriptor;
}
use of io.gravitee.rest.api.service.swagger.OAIDescriptor in project gravitee-management-rest-api by gravitee-io.
the class SwaggerService_ParseTest method shouldNotParseSwaggerV1WithoutInfo_json.
@Test
public void shouldNotParseSwaggerV1WithoutInfo_json() throws IOException {
PageEntity pageEntity = getPage("io/gravitee/rest/api/management/service/swagger-v1-no-info.json", MediaType.APPLICATION_JSON);
OAIDescriptor descriptor = (OAIDescriptor) swaggerService.parse(pageEntity.getContent());
assertNotNull(descriptor.getMessages());
assertEquals("attribute info.title is missing", descriptor.getMessages().get(0));
}
use of io.gravitee.rest.api.service.swagger.OAIDescriptor in project gravitee-management-rest-api by gravitee-io.
the class SwaggerService_ParseTest method shouldThrowInfoNameMissingWhenFailIfErrorsTrue_yaml.
@Test
public void shouldThrowInfoNameMissingWhenFailIfErrorsTrue_yaml() throws IOException {
PageEntity pageEntity = getPage("io/gravitee/rest/api/management/service/swagger-v2-no-info-name.yaml", MediaType.APPLICATION_JSON);
OAIDescriptor descriptor = (OAIDescriptor) swaggerService.parse(pageEntity.getContent());
assertNotNull(descriptor.getMessages());
assertEquals("attribute info.title is missing", descriptor.getMessages().get(0));
}
Aggregations