public List<Resource> getAllResources(Raml raml) { final List<Resource> res = new ArrayList<>(); for (Resource r : raml.getResources().values()) { res.add(r); addSubResources(r, res); } return res; }
public void loadSchemas() { for (final Resource resource : raml.getResources().values()) { loadSchemas(resource); } }
private Map<String, String> getAdjustedInlineSchemas() throws IOException { final ImmutableMap.Builder<String, String> inlinedSchemas = ImmutableMap.builder(); for (final Map.Entry<String, org.raml.model.Resource> singleResourceEntry : ramlFile.getResources().entrySet()) { final Resource singleResource = singleResourceEntry.getValue(); inlinedSchemas.putAll(adjustInlineSchema(singleResource)); for (final Resource subResource : singleResource.getResources().values()) { inlinedSchemas.putAll(adjustInlineSchema(subResource)); } } return inlinedSchemas.build(); }
/** * Returns a RAML Resource given its complete path. * * @param raml * The RAML in which the Resource is searched for. * @param path * The complete path of the resource. * @return The Resource. */ private static Resource getResourceByCompletePath(Raml raml, String path) { for (Entry<String, Resource> entry : raml.getResources().entrySet()) { if (path.equals(entry.getValue().getParentUri() + entry.getValue().getRelativeUri())) { return entry.getValue(); } } return null; }
/** * Returns a RAML Resource given its complete path. * * @param raml * The RAML in which the Resource is searched for. * @param path * The complete path of the resource. * @return The Resource. */ private static Resource getResourceByCompletePath(Raml raml, String path) { for (Entry<String, Resource> entry : raml.getResources().entrySet()) { if (path.equals(entry.getValue().getParentUri() + entry.getValue().getRelativeUri())) { return entry.getValue(); } } return null; }
/** * Returns a RAML Resource given its complete path. * * @param raml * The RAML in which the Resource is searched for. * @param path * The complete path of the resource. * @return The Resource. */ private static Resource getResourceByCompletePath(Raml raml, String path) { for (Entry<String, Resource> entry : raml.getResources().entrySet()) { if (path.equals(entry.getValue().getParentUri() + entry.getValue().getRelativeUri())) { return entry.getValue(); } } return null; }
/** * Returns a RAML Resource given its complete path. * * @param raml * The RAML in which the Resource is searched for. * @param path * The complete path of the resource. * @return The Resource. */ private static Resource getResourceByCompletePath(Raml raml, String path) { for (Entry<String, Resource> entry : raml.getResources().entrySet()) { if (path.equals(entry.getValue().getParentUri() + entry.getValue().getRelativeUri())) { return entry.getValue(); } } return null; }
/** * Returns a RAML Resource given its complete path. * * @param raml * The RAML in which the Resource is searched for. * @param path * The complete path of the resource. * @return The Resource. */ private static Resource getResourceByCompletePath(Raml raml, String path) { for (Entry<String, Resource> entry : raml.getResources().entrySet()) { if (path.equals(entry.getValue().getParentUri() + entry.getValue().getRelativeUri())) { return entry.getValue(); } } return null; }
@Override protected void postBuildProcess() { getMediaTypeResolver().setBodyDefaultMediaType(getDocumentObject().getResources()); }
private Set<String> run(final Raml raml, final Configuration configuration) throws Exception { validate(configuration); context = new Context(configuration, raml); types = new Types(context); for (final Resource resource : raml.getResources().values()) { createResourceInterface(resource); } return context.generate(); }
private Resource findResourceByPath(String resourcePath) { final Values values = new Values(); final List<ResourceMatch> matches = findResource(resourcePath, config.raml.getResources(), values); if (matches.isEmpty()) { requestViolations.add("resource.undefined", resourcePath); throw new RamlViolationException(); } if (matches.size() > 1 && matches.get(0).compareTo(matches.get(1)) == 0) { requestViolations.add("resource.ambiguous", resourcePath, matches.get(0).resource.getUri(), matches.get(1).resource.getUri()); throw new RamlViolationException(); } final Resource resource = matches.get(0).resource; locator.resource(resource); checkUriParams(values, resource); return resource; }
public JavaFile javaFile(Raml raml, String basePackage) { TypeSpec.Builder api = TypeSpec.classBuilder("Api" + capitalize(sanitize(raml.getTitle()))) .addJavadoc("$L api client\n", raml.getTitle()) .addJavadoc("Base URI pattern: $L\n", raml.getBaseUri()) .addField(configField.fieldSpec()) .addType(configClass.nestedConfSpec()) .addMethod(MethodSpec.constructorBuilder().addParameter(ClassName.bestGuess(NestedConfigClass.CONFIG_NESTED_STATIC_CLASS_NAME), configField.name()) .addStatement("this.$N = $N", configField.name(), configField.name()) .addModifiers(PRIVATE) .build()) .addModifiers(PUBLIC); api.addMethod(MethodSpec.methodBuilder(lowerCase(sanitize(raml.getTitle()))) .addParameter(ClassName.bestGuess(NestedConfigClass.CONFIG_NESTED_STATIC_CLASS_NAME), configField.name()) .returns(ClassName.bestGuess(api.build().name)) .addStatement("return new $N($N)", api.build().name, configField.name()) .addModifiers(PUBLIC, STATIC) .build()); raml.getResources().values().stream().forEach(resource -> api.addMethod( baseResource(resource, basePackage, configField.name(), configClass.getBaseSupplField().name()) )); return JavaFile.builder(basePackage, api.build()).build(); } }
public static Usage usage(Raml raml, List<RamlReport> reports) { final Usage usage = new Usage(); createTotalUsage(usage, raml.getResources()); for (final RamlReport report : reports) { usage.add(report.getUsage()); } return usage; }
@Override protected void postBuildProcess() { getMediaTypeResolver().setBodyDefaultMediaType(getDocumentObject().getResources()); compileGlobalSchemas(); }
@Override public void updateApi(String apiId, Raml raml, JSONObject config) { this.config = config; RestApi api = getApi(apiId); Optional<Resource> rootResource = getRootResource(api); createModels(api, raml.getSchemas(), true); createResources(api, createResourcePath(api, rootResource.get(), raml.getBasePath()), new HashMap<String, UriParameter>(), raml.getResources(), true); cleanupResources(api, this.paths); cleanupModels(api, this.models); }
public void generate() throws IOException { Path path = codegenConfig.getInputPath(); LOG.info("RAML: {}", path.toAbsolutePath()); if (path.endsWith(".raml")) { LOG.warn("Wrong path - should end with .raml"); return; } Raml raml = new RamlDocumentBuilder(new FileResourceLoader(path.getParent().toFile())) .build(path.getFileName().toString()); ReqSpecSupplField baseReqSpec = new ReqSpecSupplField(); ReqSpecField req = new ReqSpecField(); new RootApiClase(new NestedConfigClass(raml.getTitle(), baseReqSpec, req)) .javaFile(raml, codegenConfig.getBasePackage()) .writeTo(codegenConfig.getOutputPath()); raml.getResources().values().parallelStream().forEach(resource -> { new ResourceClassBuilder().withCodegenConfig(codegenConfig).withResource(resource).withReq(req).generate(); }); } }
@Override public String createApi(Raml raml, String name, JSONObject config) { this.config = config; // TODO: What to use as description? final RestApi api = createApi(getApiName(raml, name), null); LOG.info("Created API "+api.getId()); try { final Resource rootResource = getRootResource(api).get(); deleteDefaultModels(api); createModels(api, raml.getSchemas(), false); createResources(api, createResourcePath(api, rootResource, raml.getBasePath()), new HashMap<String, UriParameter>(), raml.getResources(), false); } catch (Throwable t) { LOG.error("Error creating API, rolling back", t); rollback(api); throw t; } return api.getId(); }
public RamlReport validate() { checker.parameters(raml.getBaseUriParameters(), BASE_URI); checker.description(raml.getDocumentation()); checker.description(raml.getBaseUriParameters(), BASE_URI); for (final Resource resource : raml.getResources().values()) { resource(resource); } return checker.getReport(); }
/** * {@inheritDoc} * <p> * This implementation creates accessor methods in the {@code builder}; one for each top-level resource that is * defined in the given {@code raml} API. It does so, by recursively invoking the appropriate * {@link ResourceBuilderProcreator}s and {@link ActionBuilderProcreator}s; so all necessary builder classes will be * procreated along the way. */ @Override protected void createMethods(final Raml raml, final JDefinedClass builder, final Context<Object, JDeclaration> context) { // create package for resource builders packageProcreator.procreate( Collections.singletonList(ResourceBuilderProcreator.BUILDER_SUB_PACKAGE_NAME), builder.owner().rootPackage(), context); builder.javadoc().append("\n<ul>"); // handle resources for (final Resource ramlResource : raml.getResources().values()) { resourceProcreator.procreate(ramlResource, builder, context); } builder.javadoc().append("\n</ul>"); }
/** * <p>run.</p> * * @param raml a {@link org.raml.model.Raml} object. * @param configuration a {@link org.raml.jaxrs.codegen.core.Configuration} object. * @return a {@link java.util.Set} object. * @throws java.lang.Exception if any. */ protected Set<String> run(final Raml raml, final Configuration configuration) throws Exception { validate(configuration); extensions = configuration.getExtensions(); context = new Context(configuration, raml); types = new Types(context); for (GeneratorExtension e : extensions) { e.setRaml(raml); e.setCodeModel(context.getCodeModel()); } Collection<Resource> resources = raml.getResources().values(); types.generateClassesFromXmlSchemas(resources); for (final Resource resource : resources) { createResourceInterface(resource, raml,configuration); } return context.generate(); }