當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。