@Override public Iterable<TypeDeclaration> findTypes(Api api) { return resourceTypes(api.resources()); } };
@Override public List<RamlResource> resources() { return Resource10.of(api.resources()); }
@Override public Map<String, RamlResource> getResources() { if (api != null) { return ramlModelFactory.transformToUnmodifiableMap(api.resources(), resources, ramlModelFactory::createRamlResource, r -> r.relativeUri().value()); } else { return Collections.emptyMap(); } }
@Override public Iterable<TypeDeclaration> findTypes(Api api) { return FluentIterable.from(api.types()) .append(resourceTypes(api.resources())) .append(Utils.goThroughLibraries(new ArrayList<TypeDeclaration>(), new HashSet<String>(), api.uses())); } };
@Override public GFinder findTypes(GFinderListener listener) { if (api.uses() != null) { goThroughLibraries(new HashSet<String>(), api.uses(), listener); } localTypes(api.types(), listener); resourceTypes(api.resources(), listener); return this; }
@Override public GFinder findTypes(GFinderListener listener) { if (api.uses() != null) { goThroughLibraries(new HashSet<String>(), api.uses(), listener); } localTypes(api.types(), listener); resourceTypes(api.resources(), listener); return this; }
@Override public void importApiDoc(final ApiImportDTO dto, final String token) throws MockImportException, ValidationException { logger.debug("importApiDoc (RAML) called"); validate(dto); File tempDir = null; try { tempDir = Files.createTempDirectory(Long.toString(System.nanoTime())).toFile(); final Api api = readContent(loadRamlFileFromUpload(dto.getFile(), tempDir)); final MockImportConfigDTO apiImportConfig = dto.getConfig(); final String conflictCtxPath = "raml_" + GeneralUtils.createFileNameUniqueTimeStamp(); debug("Keep existing mocks: " + apiImportConfig.isKeepExisting()); debug("Keep strategy: " + apiImportConfig.getKeepStrategy()); debug("Base"); debug("URI " + api.baseUri().value()); debug("version " + api.version().value()); final String defaultMimeType = api.mediaType().stream().findFirst().orElse(() -> "text/plain").value(); loadInResources(api.resources(), apiImportConfig, userTokenServiceUtils.loadCurrentUser(token), conflictCtxPath, defaultMimeType); } catch (RecordNotFoundException ex) { throw new MockImportException("Unauthorized user access"); } catch (MockImportException ex) { throw ex; } catch (Throwable ex) { logger.error("Unexpected error whilst importing RAML API", ex); throw new MockImportException("Unexpected error whilst importing RAML API"); } finally { if (!FileUtils.deleteQuietly(tempDir)) { logger.error("Error deleting temp dir"); } } }
public void handle(org.raml.v2.api.model.v10.api.Api api) throws IOException { CurrentBuild build = new CurrentBuild(api, ExtensionManager.createExtensionManager()); configuration.setupBuild(build); build.constructClasses(new V10Finder(build, api)); ResourceHandler resourceHandler = new ResourceHandler(build); // handle resources. for (Resource resource : api.resources()) { resourceHandler.handle(resource); } build.generate(configuration.getOutputDirectory()); }
/** * The convert method provides the functionality to convert the provided {@link File} into * a list of {@link RestApplication}. * @param ramlModelResult The RAML model result * @param generateResponse Will generate a default response if true. No response will be generated if false. * @return A list of {@link RestApplication} based on the provided file. * @throws IllegalStateException In case the {@link RamlModelResult} is not parsable. */ private List<RestApplication> convert(final RamlModelResult ramlModelResult, final boolean generateResponse){ if(!ramlModelResult.getValidationResults().isEmpty()){ throw new IllegalStateException("Unable to parse the RAML file"); } String title = null; List<RestResource> restResources = new ArrayList<>(); if(ramlModelResult.getApiV08() != null){ org.raml.v2.api.model.v08.api.Api api = ramlModelResult.getApiV08(); title = api.title(); new RAML08Parser().getResources(api.resources(), restResources, "", generateResponse); } else if(ramlModelResult.getApiV10() != null){ org.raml.v2.api.model.v10.api.Api api = ramlModelResult.getApiV10(); title = api.title().value(); new RAML10Parser().getResources(api.resources(), restResources, "", generateResponse); } RestApplication restApplication = new RestApplication(); restApplication.setName(title); restApplication.setResources(restResources); return Arrays.asList(restApplication); }
public void handle(org.raml.v2.api.model.v10.api.Api api) throws IOException { V10TypeRegistry registry = new V10TypeRegistry(); CurrentBuild build = new CurrentBuild(new V10Finder(api, registry), api); configuration.setupBuild(build); build.constructClasses(); ResourceHandler resourceHandler = new ResourceHandler(build); // handle resources. for (Resource resource : api.resources()) { resourceHandler.handle(registry, resource); } build.generate(configuration.getOutputDirectory()); }