本文整理汇总了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;
}
示例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\"}]}");
}
示例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");
}
示例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()))));
}
示例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();
}
}
示例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);
}
}
示例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);
}
示例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\"]");
}
示例9: example
import org.raml.v2.api.model.v10.datamodel.ExampleSpec; //导入依赖的package包/类
@Override
public ExampleSpec example() {
return null;
}
示例10: examples
import org.raml.v2.api.model.v10.datamodel.ExampleSpec; //导入依赖的package包/类
@Override
public List<ExampleSpec> examples() {
return null;
}
示例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);
}