当前位置: 首页>>代码示例>>Java>>正文


Java Raml类代码示例

本文整理汇总了Java中org.raml.model.Raml的典型用法代码示例。如果您正苦于以下问题:Java Raml类的具体用法?Java Raml怎么用?Java Raml使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Raml类属于org.raml.model包,在下文中一共展示了Raml类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: obeyedBy

import org.raml.model.Raml; //导入依赖的package包/类
/**
 * Determine if the given `MockServer` location has obeyed the RAML API specifications.
 *
 * @param client           The `MockServer` client
 * @param responseObeyMode The level of obeying responses will adhere to.
 * @param alsoCheckMethods By default, only GET, POST, PUT and DELETE methods are checked.  Add HEAD, OPTIONS, etc. if needed here.
 * @return The result of the expectation validations.
 * @throws java.lang.IllegalStateException If the specification has not been initialized.
 * @see ResponseObeyMode
 */
public Result obeyedBy(MockServerClient client, ResponseObeyMode responseObeyMode, String... alsoCheckMethods) {
    Raml raml = this.raml.orElseThrow(() -> new IllegalStateException(String.format("[ %s ] specification has not been initialized", name)));
    Result result = new Result();
    List<String> methodsToCheck = newArrayList(DEFAULT_METHODS_TO_CHECK);
    methodsToCheck.addAll(newArrayList(alsoCheckMethods));

    Arrays.asList(client.retrieveExistingExpectations(null))
            .stream()
            .map(e -> {
                ApiSpecification specification = new ApiSpecification(raml);
                ApiExpectation expectation = new ApiExpectation(specification, e);
                if (!methodsToCheck.contains(expectation.getMethod()))
                    return Optional.<ExpectationError>empty();

                return new ExpectationValidator(expectation, getValidators(expectation, responseObeyMode)).validate();
            })
            .filter(Optional::isPresent)
            .map(Optional::get)
            .forEach(result::withErrors);

    return result;
}
 
开发者ID:ozwolf-software,项目名称:raml-mock-server,代码行数:33,代码来源:RamlSpecification.java

示例2: generate

import org.raml.model.Raml; //导入依赖的package包/类
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();
    });
}
 
开发者ID:qameta,项目名称:rarc,代码行数:23,代码来源:RestAssuredRamlCodegen.java

示例3: toString

import org.raml.model.Raml; //导入依赖的package包/类
@Override
public String toString(Object o, String formatString, Locale locale) {
    final Raml raml = (Raml) o;
    if (raml.getBaseUri() == null) {
        return "";
    }
    switch (formatString) {
        case "baseUri":
            if (raml.getProtocols() == null || raml.getProtocols().isEmpty()) {
                return raml.getBaseUri();
            }
            final int pos = raml.getBaseUri().indexOf("://");
            final String rest = pos < 0 ? raml.getBaseUri() : raml.getBaseUri().substring(pos + 3);
            if (raml.getProtocols().size() == 2) {
                return "http(s)://" + rest;
            }
            return raml.getProtocols().get(0).toString().toLowerCase() + "://" + rest;
        default:
            throw new IllegalArgumentException("unknown format '" + formatString + "'");
    }
}
 
开发者ID:nidi3,项目名称:raml-doc,代码行数:22,代码来源:RamlRenderer.java

示例4: StringRenderer

import org.raml.model.Raml; //导入依赖的package包/类
public StringRenderer(Raml raml, ResourceCache resourceCache) {
    this.raml = raml;
    this.resourceCache = resourceCache;
    final ScriptEngine engine = new ScriptEngineManager().getEngineByExtension("js");
    final Invocable invocable = (Invocable) engine;
    try {
        engine.eval("var window=this;");
        //beautify.js: changed default operators like 'bla || 0' into 'bla | 0' (jdk 6)
        engine.eval(new InputStreamReader(getClass().getResourceAsStream("/guru/nidi/raml/doc/static/beautify.js"), "utf-8"));
        engine.eval("jsBeautify=js_beautify;");
        jsBeautifyer = invocable.getInterface(JsBeautifyer.class);

        //marked.js: commented lines 723,727 because of unrecognized unicode chars (jdk 6)
        engine.eval("Inline=null;");
        engine.eval(new InputStreamReader(getClass().getResourceAsStream("/guru/nidi/raml/doc/marked.js"), "utf-8"));
        markdownProcessor = invocable.getInterface(MarkdownProcessor.class);
    } catch (ScriptException | UnsupportedEncodingException e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:nidi3,项目名称:raml-doc,代码行数:21,代码来源:StringRenderer.java

示例5: loadRamls

import org.raml.model.Raml; //导入依赖的package包/类
private LoadResults loadRamls() throws IOException {
    final LoadResults res = new LoadResults();
    for (String loc : ramlLocations) {
        try {
            final SavingLoaderInterceptor sli = new SavingLoaderInterceptor();
            final InterceptingLoader loader = new InterceptingLoader(new UriLoader(new FileLoader(new File("."))), sli);
            final Raml raml = new RamlLoad(loader).load(loc);
            new SchemaLoader(raml, loc, loader).loadSchemas();
            sli.raml = raml;
            res.ramls.add(raml);
            res.slis.add(sli);
        } catch (Exception e) {
            throw new IOException("Problem loading RAML from '" + loc + "'", e);
        }
    }
    return res;
}
 
开发者ID:nidi3,项目名称:raml-doc,代码行数:18,代码来源:GeneratorConfig.java

示例6: createApi

import org.raml.model.Raml; //导入依赖的package包/类
@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();
}
 
开发者ID:awslabs,项目名称:aws-apigateway-importer,代码行数:23,代码来源:ApiGatewaySdkRamlApiImporter.java

示例7: shouldFlattenResourceList

import org.raml.model.Raml; //导入依赖的package包/类
@Test
public void shouldFlattenResourceList() throws Exception {
    final Raml raml = new Raml();

    final Resource usersResource = new Resource();
    final Resource userResource = new Resource();
    final Resource userSettingsResource = new Resource();

    usersResource.getResources().put("/{userId}", userResource);
    userResource.getResources().put("/settings", userSettingsResource);

    raml.getResources().put("/users", usersResource);

    final List<Resource> flattenned = ResourceList.of(Lists.newArrayList(usersResource))
            .flatten()
            .collect(toList());

    assertThat(flattenned, containsInAnyOrder(usersResource, userResource, userSettingsResource));
}
 
开发者ID:hubrick,项目名称:raml-maven-plugin,代码行数:20,代码来源:ResourceListTest.java

示例8: getRaml

import org.raml.model.Raml; //导入依赖的package包/类
@Override
protected Raml getRaml() {
    try {
        File file = new File(filePath);
        if (!file.exists())
            throw new IllegalArgumentException(String.format("[ %s ] does not exist.", file.getPath()));

        if (file.exists() && !file.canRead())
            throw new IllegalStateException(String.format("[ %s ] cannot be read.", file.getPath()));

        if (file.exists() && !file.isFile())
            throw new IllegalArgumentException(String.format("[ %s ] is not a file.", file.getPath()));

        ResourceLoader loader = new FileResourceLoader(file.getParent());
        return new RamlDocumentBuilder(loader).build(new FileInputStream(file), file.getAbsolutePath());
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:ozwolf-software,项目名称:raml-mock-server,代码行数:20,代码来源:FilePathSpecification.java

示例9: createApi

import org.raml.model.Raml; //导入依赖的package包/类
@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()), raml.getResources(), false);
    } catch (Throwable t) {
        LOG.error("Error creating API, rolling back", t);
        rollback(api);
        throw t;
    }
    return api.getId();
}
 
开发者ID:Stockflare,项目名称:aws-api-gateway,代码行数:22,代码来源:ApiGatewaySdkRamlApiImporter.java

示例10: getProperty

import org.raml.model.Raml; //导入依赖的package包/类
@Override
public synchronized Object getProperty(Interpreter anInter, ST aSt,
		Object anObject, Object aProperty, String aName)
		throws STNoSuchPropertyException {
	Raml oRoot=(Raml)anObject;
	if(aName.equals("baseUri")) {
		return Resolver.resolve(oRoot.getBaseUri(), oRoot.getBaseUriParameters(), "[BaseUriParameter]");
	}
	if(aName.equals("cleanVersion")) {
		if(oRoot.getVersion()!=null) {
			return Utils.cleanString(oRoot.getVersion());
		} else {
			return null;
		}
	}
	return super.getProperty(anInter, aSt, anObject, aProperty, aName);
}
 
开发者ID:pagesjaunes,项目名称:raml-codegen,代码行数:18,代码来源:RamlAdaptator.java

示例11: run

import org.raml.model.Raml; //导入依赖的package包/类
public void run() {
	File[] ramlFiles = this.getRamlFiles();
	if (ramlFiles.length == 0) {
		throw new RuntimeException("There is no RAML file in " + this.configuration.getSourceDirectory().getPath());
	}
	
	Log logger = this.configuration.getLogger();
	for (File ramlFile : ramlFiles) {
		logger.info("------------------------------------------------------------------------");
		logger.info("Validating and Parsing RAML file " + ramlFile.getPath());
		
		ValidationHelper.validateRamlFile(ramlFile);
		Raml raml = RamlHelper.parseModel(ramlFile);
		currentRamlMap = RamlHelper.parseYaml(ramlFile);
		
		for (GeneratorType type : GeneratorType.values()) {
			logger.info("Generate code for " + type.name() + " layer.");
			this.buildCodeGenerator(type, raml).execute();
		}
	}
}
 
开发者ID:aureliano,项目名称:cgraml-maven-plugin,代码行数:22,代码来源:Generator.java

示例12: testParseModel

import org.raml.model.Raml; //导入依赖的package包/类
@Test
public void testParseModel() {
	Raml raml = RamlHelper.parseModel("src/test/resources/raml_definition.raml");
	
	assertEquals("World Music API", raml.getTitle());
	assertEquals("http://example.api.com/v1", raml.getBaseUri());
	assertEquals("v1", raml.getVersion());
	
	String[] expectedResources = new String[] { "/songs" };
	Object[] resources = raml.getResources().keySet().toArray();
	Arrays.sort(resources);
	
	for (short i = 0; i < expectedResources.length; i++) {
		assertEquals(expectedResources[i], resources[i]);
	}
}
 
开发者ID:aureliano,项目名称:cgraml-maven-plugin,代码行数:17,代码来源:RamlHelperTest.java

示例13: testResourceToService

import org.raml.model.Raml; //导入依赖的package包/类
@Test
public void testResourceToService() {
	Generator.currentRamlMap = RamlHelper.parseYaml("src/test/resources/raml.yaml");
	Raml raml = RamlHelper.parseModel("src/test/resources/raml.yaml");
	ServiceMeta service = RamlHelper.resourceToService(raml.getResource("/products"));
	
	assertNotNull(service);
	
	assertEquals("/products", service.getUri());
	assertEquals("Products", service.getType());
	assertEquals("Product", service.getGenericType());
	
	assertEquals(2, service.getActions().size());
	
	List<FieldMeta> params = service.getActions().get(0).getParameters();
	assertEquals(3, params.size());
	assertEquals("region", params.get(0).getName());
	assertEquals("java.lang.String", params.get(0).getType());
}
 
开发者ID:aureliano,项目名称:cgraml-maven-plugin,代码行数:20,代码来源:RamlHelperTest.java

示例14: controllerParsed

import org.raml.model.Raml; //导入依赖的package包/类
/**
 * Generate the raml file from a given controller source file.
 *
 * @param source The controller source file.
 * @param model  The controller model
 * @throws WatchingException If there is a problem while creating the raml file.
 */
@Override
public void controllerParsed(File source, ControllerModel<Raml> model) throws WatchingException {
    Raml raml = new Raml(); //Create a new raml file
    raml.setBaseUri(baseUri); //set the base uri
    raml.setVersion(project().getVersion());

    //Visit the controller model to populate the raml model
    model.accept(controllerVisitor, raml);

    getLog().info("Create raml file for controller " + raml.getTitle());

    try {
        //create the file
        File output = getRamlOutputFile(source);
        FileUtils.write(output, ramlEmitter.dump(raml));
        getLog().info("Created the RAML description for " + source.getName() + " => " + output.getAbsolutePath());
    } catch (IOException ie) {
        throw new WatchingException("Cannot create raml file", source, ie);
    } catch (IllegalArgumentException e) {
        throw new WatchingException("Cannot create Controller Element from", e);
    }
}
 
开发者ID:wisdom-framework,项目名称:wisdom,代码行数:30,代码来源:RamlCompilerMojo.java

示例15: javaFile

import org.raml.model.Raml; //导入依赖的package包/类
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();
    }
 
开发者ID:qameta,项目名称:rarc,代码行数:28,代码来源:RootApiClase.java


注:本文中的org.raml.model.Raml类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。