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


Java ExampleSpec类代码示例

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


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

示例1: toJsonValue

import org.raml.v2.api.model.v10.datamodel.ExampleSpec; //导入依赖的package包/类
/**
 * Converts an example of the given type to a JSON value.
 *
 * @param type
 *            RAML type declaration
 * @param example
 *            example instance
 * @return JSON value
 */
public JsonValue toJsonValue(TypeDeclaration type, ExampleSpec example) {
    TypeInstance instance = example.structuredValue();
    if (instance == null) {
        return JsonValue.NULL;
    }
    JsonObjectBuilder builder = createObject(instance);
    JsonObject jsonObject = builder.build();
    if (isArray(type)) {
        return jsonObject.entrySet().iterator().next().getValue();
    }
    if (!isObject(type) && jsonObject.containsKey("value")) {
        return jsonObject.get("value");
    }
    return jsonObject;
}
 
开发者ID:ops4j,项目名称:org.ops4j.ramler,代码行数:25,代码来源:ExampleSpecJsonRenderer.java

示例2: shouldParseObjectExample

import org.raml.v2.api.model.v10.datamodel.ExampleSpec; //导入依赖的package包/类
@Test
public void shouldParseObjectExample() {
    parse("simpleobject.raml");
    TypeDeclaration userGroup = apiModel.getDeclaredType("UserGroup");
    assertThat(userGroup).isNotNull();
    ExampleSpec exampleSpec = getExample(userGroup);
    TypeInstance instance = exampleSpec.structuredValue();
    assertThat(instance.isScalar()).isFalse();
    TypeInstanceProperty users = instance.properties().get(1);
    assertThat(users.isArray()).isTrue();
    TypeInstance user = users.values().get(0);
    assertThat(user.properties().get(0).name()).isEqualTo("firstname");
    assertThat(user.properties().get(0).value().value()).isEqualTo("Anna");

    ExampleSpecJsonRenderer renderer = new ExampleSpecJsonRenderer();
    JsonValue jsonValue = renderer.toJsonValue(userGroup, exampleSpec);

    assertThat(jsonValue.toString()).
        isEqualTo("{\"name\":\"Editors\",\"users\":["
            + "{\"firstname\":\"Anna\",\"lastname\":\"Walter\",\"age\":32,"
            + "\"address\":{\"city\":\"Hamburg\",\"street\":\"Colonnaden\"},"
            + "\"registered\":true,\"dateOfBirth\":\"1985-04-30\","
            + "\"registrationDate\":\"2016-02-28T16:41:41.090Z\"}]}");
}
 
开发者ID:ops4j,项目名称:org.ops4j.ramler,代码行数:25,代码来源:ExampleSpecTest.java

示例3: shouldParseNumberExample

import org.raml.v2.api.model.v10.datamodel.ExampleSpec; //导入依赖的package包/类
@Test
public void shouldParseNumberExample() {
    parse("simpleobject.raml");
    TypeDeclaration age = apiModel.getDeclaredType("Age");
    assertThat(age).isNotNull();
    ExampleSpec exampleSpec = getExample(age);
    List<TypeInstanceProperty> props = exampleSpec.structuredValue().properties();
    TypeInstanceProperty p0 = props.get(0);
    assertThat(p0.isArray()).isFalse();
    assertThat(p0.name()).isEqualTo("value");
    assertThat(p0.value().isScalar()).isTrue();
    Object scalar = p0.value().value();
    assertThat(scalar).isEqualTo(37L);

    ExampleSpecJsonRenderer renderer = new ExampleSpecJsonRenderer();
    JsonValue jsonValue = renderer.toJsonValue(age, exampleSpec);
    assertThat(jsonValue.toString()).isEqualTo("37");
}
 
开发者ID:ops4j,项目名称:org.ops4j.ramler,代码行数:19,代码来源:ExampleSpecTest.java

示例4: handle

import org.raml.v2.api.model.v10.datamodel.ExampleSpec; //导入依赖的package包/类
@Override
public void handle(final Context ctx) throws Exception {
    final Method method = ctx.get(Method.class);

    final List<TypeDeclaration> bodTypeDeclarations = method.responses().stream()
            .flatMap(r -> r.body().stream()).collect(Collectors.toList());

    final Map<String, ExampleSpec> contentTypeToExample = bodTypeDeclarations.stream()
            .collect(Collectors.toMap(TypeDeclaration::name, TypeDeclaration::example));

    ctx.byContent(byContentSpec ->
            contentTypeToExample.entrySet().stream()
                    .forEach(e -> byContentSpec.type(e.getKey(), () -> ctx.render(e.getValue().value()))));
}
 
开发者ID:vrapio,项目名称:vrap,代码行数:15,代码来源:RamlRouter.java

示例5: prettyPrint

import org.raml.v2.api.model.v10.datamodel.ExampleSpec; //导入依赖的package包/类
/**
 * Returns a pretty-printed JSON string for the given example instance of the given RAML type.
 *
 * @param type
 *            RAML type declaration
 * @param example
 *            example instance
 * @return pretty-printed JSON string
 */
public String prettyPrint(TypeDeclaration type, ExampleSpec example) {
    JsonValue json = toJsonValue(type, example);

    Map<String, Boolean> config = new HashMap<>();
    config.put(JsonGenerator.PRETTY_PRINTING, true);
    JsonWriterFactory jwf = Json.createWriterFactory(config);
    StringWriter sw = new StringWriter();
    JsonWriter writer = jwf.createWriter(sw);
    if (json instanceof JsonStructure) {
        writer.write((JsonStructure) json);
        return sw.toString();
    }
    else {
        return json.toString();
    }
}
 
开发者ID:ops4j,项目名称:org.ops4j.ramler,代码行数:26,代码来源:ExampleSpecJsonRenderer.java

示例6: validateRuntimeParameters

import org.raml.v2.api.model.v10.datamodel.ExampleSpec; //导入依赖的package包/类
private void validateRuntimeParameters(Options options) {
    if (!(options.getParameters().get(0) instanceof TypeDeclaration)) {
        throw HelperValidator.newValidationException("Parameter 0 must be a TypeDeclaration",
            ExampleHelper.class, options);
    }

    if (!(options.getParameters().get(1) instanceof ExampleSpec)) {
        throw HelperValidator.newValidationException("Parameter 1 must be an ExampleSpec",
            ExampleHelper.class, options);
    }
}
 
开发者ID:ops4j,项目名称:org.ops4j.ramler,代码行数:12,代码来源:ExampleHelper.java

示例7: execute

import org.raml.v2.api.model.v10.datamodel.ExampleSpec; //导入依赖的package包/类
@Override
public void execute(Options options) {
    validateRuntimeParameters(options);
    TypeDeclaration type = (TypeDeclaration) options.getParameters().get(0);
    ExampleSpec example = (ExampleSpec) options.getParameters().get(1);
    String json = renderer.prettyPrint(type, example);
    options.append(json);

}
 
开发者ID:ops4j,项目名称:org.ops4j.ramler,代码行数:10,代码来源:ExampleHelper.java

示例8: shouldParseListExample

import org.raml.v2.api.model.v10.datamodel.ExampleSpec; //导入依赖的package包/类
@Test
public void shouldParseListExample() {
    parse("simpleobject.raml");
    TypeDeclaration nameList = apiModel.getDeclaredType("NameList");
    assertThat(nameList).isNotNull();
    ExampleSpec exampleSpec = getExample(nameList);
    List<TypeInstanceProperty> props = exampleSpec.structuredValue().properties();
    TypeInstanceProperty p0 = props.get(0);
    assertThat(p0.isArray()).isTrue();

    ExampleSpecJsonRenderer renderer = new ExampleSpecJsonRenderer();
    JsonValue jsonValue = renderer.toJsonValue(nameList, exampleSpec);

    assertThat(jsonValue.toString()).isEqualTo("[\"foo\",\"bar\"]");
}
 
开发者ID:ops4j,项目名称:org.ops4j.ramler,代码行数:16,代码来源:ExampleSpecTest.java

示例9: example

import org.raml.v2.api.model.v10.datamodel.ExampleSpec; //导入依赖的package包/类
@Override
public ExampleSpec example() {
    return null;
}
 
开发者ID:vrapio,项目名称:vrap,代码行数:5,代码来源:RatpackPathMapperTest.java

示例10: examples

import org.raml.v2.api.model.v10.datamodel.ExampleSpec; //导入依赖的package包/类
@Override
public List<ExampleSpec> examples() {
    return null;
}
 
开发者ID:vrapio,项目名称:vrap,代码行数:5,代码来源:RatpackPathMapperTest.java

示例11: getExample

import org.raml.v2.api.model.v10.datamodel.ExampleSpec; //导入依赖的package包/类
private ExampleSpec getExample(TypeDeclaration type) {
    return type.examples().isEmpty() ? type.example() : type.examples().get(0);
}
 
开发者ID:ops4j,项目名称:org.ops4j.ramler,代码行数:4,代码来源:ExampleSpecTest.java


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