本文整理汇总了Java中org.raml.v2.api.model.v10.api.Api类的典型用法代码示例。如果您正苦于以下问题:Java Api类的具体用法?Java Api怎么用?Java Api使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Api类属于org.raml.v2.api.model.v10.api包,在下文中一共展示了Api类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: main
import org.raml.v2.api.model.v10.api.Api; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
RamlModelResult ramlModelResult =
new RamlModelBuilder().buildApi(
new FileReader("/Users/jpbelang/IdeaProjects/raml-java-tools/raml-to-pojo/src/test/resources/org/raml/ramltopojo/union/union-primitive-type.raml"),
".");
if (ramlModelResult.hasErrors()) {
for (ValidationResult validationResult : ramlModelResult.getValidationResults()) {
System.err.println(validationResult.getMessage());
}
throw new Exception();
}
final Api api = ramlModelResult.getApiV10();
RamlToPojo ramlToPojo = RamlToPojoBuilder.builder(api)
.inPackage("my.packaging")
.fetchTypes(fromAnywhere())
.findTypes(everyWhere()).build();
ramlToPojo.buildPojos().createAllTypes("/Users/jpbelang/IdeaProjects/raml-java-tools/garbage/src/main/java");
}
开发者ID:mulesoft-labs,项目名称:raml-java-tools,代码行数:22,代码来源:Main.java
示例2: fromTypes
import org.raml.v2.api.model.v10.api.Api; //导入依赖的package包/类
public static TypeFetcher fromTypes() {
return new TypeFetcher() {
// this is technically invalid, as different apis might call. Won't happen, but could.
// make better
Iterable<TypeDeclaration> foundInApi;
@Override
public TypeDeclaration fetchType(Api api, final String name) throws GenerationException {
return FluentIterable.from(Optional.fromNullable(foundInApi).or(api.types()))
.firstMatch(namedPredicate(name)).or(fail(name));
}
};
}
开发者ID:mulesoft-labs,项目名称:raml-java-tools,代码行数:17,代码来源:TypeFetchers.java
示例3: inheritanceWithDiscriminatorAndValue
import org.raml.v2.api.model.v10.api.Api; //导入依赖的package包/类
@Test
public void inheritanceWithDiscriminatorAndValue() throws Exception {
Api api = RamlLoader.load(this.getClass().getResourceAsStream("inheritance-with-discriminatorvalue-type.raml"), ".");
ObjectTypeHandler handler = new ObjectTypeHandler(RamlLoader.findTypes("foo", api.types()));
CreationResult r = handler.create(createGenerationContext(api));
System.err.println(r.getInterface().toString());
System.err.println(r.getImplementation().toString());
assertThat(r.getImplementation().get(), is(allOf(
name(equalTo("FooImpl")),
fields(containsInAnyOrder(
allOf(fieldName(equalTo("kind")), fieldType(equalTo(ClassName.get(String.class))), initializer(equalTo("\"myOwnValue\""))),
allOf(fieldName(equalTo("right")), fieldType(equalTo(ClassName.get(String.class)))),
allOf(fieldName(equalTo("name")), fieldType(equalTo(ClassName.get(String.class))))
))
)));
}
开发者ID:mulesoft-labs,项目名称:raml-java-tools,代码行数:24,代码来源:ObjectTypeHandlerTest.java
示例4: main
import org.raml.v2.api.model.v10.api.Api; //导入依赖的package包/类
public static void main(String[] args) throws IOException {
// URL url = Main.class.getResource("api.raml");
URL url = Main.class.getResource("fun.raml");
Reader reader = new InputStreamReader(url.openStream());
RamlModelResult ramlModelResult = new RamlModelBuilder().buildApi(reader, url.getFile());
if (ramlModelResult.hasErrors()) {
for (ValidationResult validationResult : ramlModelResult.getValidationResults()) {
System.err.println(validationResult);
}
} else {
Api realApi = ramlModelResult.getApiV10();
System.err.println("grr " + realApi.annotationTypes().get(0).name());
}
}
开发者ID:mulesoft-labs,项目名称:raml-java-tools,代码行数:18,代码来源:OtherMain.java
示例5: main
import org.raml.v2.api.model.v10.api.Api; //导入依赖的package包/类
public static void main(String[] args) {
RamlModelResult ramlModelResult = new RamlModelBuilder().buildApi(new File(Query.class.getResource("/api.raml").getFile()));
if (ramlModelResult.hasErrors()) {
for (ValidationResult validationResult : ramlModelResult.getValidationResults()) {
System.out.println(validationResult.getMessage());
}
} else {
Api api = ramlModelResult.getApiV10();
List<Resource> tr = from(api).select(Selectors.allResources()).toList();
for (Resource resource : tr) {
System.err.println(resource.resourcePath());
}
}
}
开发者ID:mulesoft-labs,项目名称:raml-java-tools,代码行数:18,代码来源:Query.java
示例6: validateRequest
import org.raml.v2.api.model.v10.api.Api; //导入依赖的package包/类
/**
* Validates the body, headers, uri and query parameters of the request of the given context.
*
* @param context the context holding the requesz
* @param body the request body to validate
* @param method the method to validate the request aginst
* @return validation errors
*/
public Optional<ValidationErrors> validateRequest(final Context context, final TypedData body, final Method method) {
final List<ValidationError> errors = new ArrayList<>();
if (disableValidation(context.getRequest().getHeaders(), ValidationFlag.request)) {
return wrapAndLogErrors(errors);
}
final Api api = context.get(RamlModelRepository.class).getApi();
errors.addAll(validateQueryParameters(context.getRequest(), method));
errors.addAll(validateRequestHeaders(context.getRequest().getHeaders(), method));
final String contentType = Optional.ofNullable(body.getContentType().getType()).orElse(
!method.body().isEmpty() ? method.body().get(0).name() :
!api.mediaType().isEmpty() ? api.mediaType().get(0).value() : "application/json"
);
final Optional<TypeDeclaration> bodyTypeDeclaration = method.body().stream()
.filter(typeDeclaration -> contentType.equals(typeDeclaration.name())).findFirst();
errors.addAll(bodyTypeDeclaration
.map(bodyTypeDecl -> validate(body.getText(), bodyTypeDecl, ValidationKind.body, "request"))
.orElse(Collections.emptyList()));
return wrapAndLogErrors(errors);
}
开发者ID:vrapio,项目名称:vrap,代码行数:34,代码来源:Validator.java
示例7: preprocess
import org.raml.v2.api.model.v10.api.Api; //导入依赖的package包/类
public StringWriter preprocess(Context ctx, final Path filePath, final Api api) throws IOException {
final Integer port = ctx.getServerConfig().getPort();
final StringWriter stringWriter = new StringWriter();
final String baseUri = api.baseUri().value();
final List<SecurityScheme> oauthSchemes = api.securitySchemes().stream().filter(securityScheme -> securityScheme.type().equals("OAuth 2.0")).collect(Collectors.toList());
String content = new String(Files.readAllBytes(filePath), Charsets.UTF_8);
ObjectMapper mapper = new ObjectMapper(); // can reuse, share globally
final JsonNode file = mapper.readValue(filePath.toFile(), JsonNode.class);
if (file.has("baseUri")) {
content = content.replaceAll(baseUri, "http://localhost:" + port.toString() + "/api");
}
if (!oauthSchemes.isEmpty()) {
for (SecurityScheme scheme : oauthSchemes) {
content = content.replaceAll(scheme.settings().accessTokenUri().value(), "http://localhost:" + port.toString() + "/auth/" + scheme.name());
}
}
return stringWriter.append(content);
}
开发者ID:vrapio,项目名称:vrap,代码行数:22,代码来源:BaseUriReplacer.java
示例8: buildRamlRoot
import org.raml.v2.api.model.v10.api.Api; //导入依赖的package包/类
@Override
public RamlRoot buildRamlRoot(String ramlFileUrl) throws InvalidRamlResourceException {
RamlModelResult ramlModelResult = new RamlModelBuilder().buildApi(ramlFileUrl);
if (ramlModelResult.hasErrors()) {
List<String> errors = ramlModelResult.getValidationResults()
.stream()
.map(validationResult -> validationResult.getMessage())
.collect(Collectors.toList());
throw new InvalidRamlResourceException(ramlFileUrl, errors);
}
// The Api is created by RamlModelBuilder during runtime via a yagi ModelProxyBuilder.
// In org.raml.v2 there is no direct implementation for Api interface during compile time.
Api api = ramlModelResult.getApiV10();
return new RJP10V2RamlRoot(api);
}
开发者ID:phoenixnap,项目名称:springmvc-raml-plugin,代码行数:17,代码来源:RJP10V2RamlModelFactory.java
示例9: pojoToRamlTypeBuilder
import org.raml.v2.api.model.v10.api.Api; //导入依赖的package包/类
@Test
public void pojoToRamlTypeBuilder() throws Exception {
PojoToRamlImpl pojoToRaml = new PojoToRamlImpl(FieldClassParser.factory(), RamlAdjuster.NULL_ADJUSTER);
Result types = pojoToRaml.classToRaml(Fun.class);
RamlDocumentBuilder ramlDocumentBuilder = RamlDocumentBuilder
.document()
.baseUri("http://google.com")
.title("hello")
.version("1")
.withTypes(types.allTypes().toArray(new TypeDeclarationBuilder[0]));
Api api = ramlDocumentBuilder.buildModel();
final GrammarPhase grammarPhase = new GrammarPhase(RamlHeader.getFragmentRule(new RamlHeader(RAML_10, Default).getFragment()));
Node node = ((NodeModel) api).getNode();
Node checked = grammarPhase.apply(node);
List<ErrorNode> errors = checked.findDescendantsWith(ErrorNode.class);
for (ErrorNode error : errors) {
System.err.println("error: " + error.getErrorMessage());
}
List<TypeDeclaration> buildTypes = api.types();
assertEquals(2, buildTypes.size());
assertEquals("Fun", buildTypes.get(0).name());
assertEquals("SubFun", buildTypes.get(1).name());
}
开发者ID:mulesoft-labs,项目名称:raml-java-tools,代码行数:31,代码来源:PojoToRamlImplTest.java
示例10: buildModel
import org.raml.v2.api.model.v10.api.Api; //导入依赖的package包/类
public Api buildModel() {
NodeModelFactory fac = binding.bindingOf(Api.class);
Node node = buildNode();
NodeModel model = fac.create(node);
return ModelProxyBuilder.createModel(Api.class, model, binding);
}
开发者ID:mulesoft-labs,项目名称:raml-java-tools,代码行数:8,代码来源:RamlDocumentBuilder.java
示例11: inTypes
import org.raml.v2.api.model.v10.api.Api; //导入依赖的package包/类
public static TypeFinder inTypes() {
return new TypeFinder() {
@Override
public Iterable<TypeDeclaration> findTypes(Api api) {
return api.types();
}
};
}
开发者ID:mulesoft-labs,项目名称:raml-java-tools,代码行数:11,代码来源:TypeFinders.java
示例12: inLibraries
import org.raml.v2.api.model.v10.api.Api; //导入依赖的package包/类
public static TypeFinder inLibraries() {
return new TypeFinder() {
@Override
public Iterable<TypeDeclaration> findTypes(Api api) {
List<TypeDeclaration> foundTypes = new ArrayList<>();
Utils.goThroughLibraries(foundTypes, new HashSet<String>(), api.uses());
return foundTypes;
}
};
}
开发者ID:mulesoft-labs,项目名称:raml-java-tools,代码行数:13,代码来源:TypeFinders.java
示例13: everyWhere
import org.raml.v2.api.model.v10.api.Api; //导入依赖的package包/类
public static TypeFinder everyWhere() {
return new TypeFinder() {
@Override
public Iterable<TypeDeclaration> findTypes(Api api) {
return FluentIterable.from(api.types()).append(Utils.goThroughLibraries(new ArrayList<TypeDeclaration>(), new HashSet<String>(), api.uses()));
}
};
}
开发者ID:mulesoft-labs,项目名称:raml-java-tools,代码行数:11,代码来源:TypeFinders.java
示例14: fromLibraries
import org.raml.v2.api.model.v10.api.Api; //导入依赖的package包/类
public static TypeFetcher fromLibraries() {
return new TypeFetcher() {
Iterable<TypeDeclaration> foundInApi;
@Override
public TypeDeclaration fetchType(Api api, final String name) throws GenerationException {
return FluentIterable.from(Optional.fromNullable(foundInApi).or(Utils.goThroughLibraries(new ArrayList<TypeDeclaration>(), new HashSet<String>(), api.uses())))
.firstMatch(namedPredicate(name)).or(fail(name));
}
};
}
开发者ID:mulesoft-labs,项目名称:raml-java-tools,代码行数:14,代码来源:TypeFetchers.java
示例15: fromAnywhere
import org.raml.v2.api.model.v10.api.Api; //导入依赖的package包/类
public static TypeFetcher fromAnywhere() {
return new TypeFetcher() {
Iterable<TypeDeclaration> foundInApi;
@Override
public TypeDeclaration fetchType(Api api, final String name) throws GenerationException {
return FluentIterable.from(Optional.fromNullable(foundInApi).or(FluentIterable.from(api.types()).append(Utils.goThroughLibraries(new ArrayList<TypeDeclaration>(), new HashSet<String>(), api.uses()))))
.firstMatch(namedPredicate(name)).or(fail(name));
}
};
}
开发者ID:mulesoft-labs,项目名称:raml-java-tools,代码行数:14,代码来源:TypeFetchers.java
示例16: arrayUnion
import org.raml.v2.api.model.v10.api.Api; //导入依赖的package包/类
@Test(expected = GenerationException.class)
public void arrayUnion() throws Exception {
Api api = RamlLoader.load(this.getClass().getResourceAsStream("union-array-type.raml"), ".");
UnionTypeHandler handler = new UnionTypeHandler(findTypes("foo", api.types()));
handler.create(new GenerationContextImpl(PluginManager.NULL, api, TypeFetchers.fromTypes(), "bar.pack"));
}
开发者ID:mulesoft-labs,项目名称:raml-java-tools,代码行数:9,代码来源:UnionTypeHandlerTest.java
示例17: internalIntIsNotNewInlineType
import org.raml.v2.api.model.v10.api.Api; //导入依赖的package包/类
@Test
public void internalIntIsNotNewInlineType() {
Api api = RamlLoader.load(this.getClass().getResourceAsStream("inline-types.raml"), ".");
ObjectTypeDeclaration decl = RamlLoader.findTypes("foo", api.types());
TypeDeclaration property = findProperty(decl, "internalInt");
assertFalse(TypeDeclarationType.isNewInlineType(property));
}
开发者ID:mulesoft-labs,项目名称:raml-java-tools,代码行数:10,代码来源:TypeDeclarationTypeTest.java
示例18: simpleObjectIsNotNewInlineType
import org.raml.v2.api.model.v10.api.Api; //导入依赖的package包/类
@Test
public void simpleObjectIsNotNewInlineType() {
Api api = RamlLoader.load(this.getClass().getResourceAsStream("inline-types.raml"), ".");
ObjectTypeDeclaration decl = RamlLoader.findTypes("foo", api.types());
TypeDeclaration property = findProperty(decl, "unextended");
assertFalse(TypeDeclarationType.isNewInlineType(property));
}
开发者ID:mulesoft-labs,项目名称:raml-java-tools,代码行数:10,代码来源:TypeDeclarationTypeTest.java
示例19: extendedObjectIsNotNewInlineType
import org.raml.v2.api.model.v10.api.Api; //导入依赖的package包/类
@Test
public void extendedObjectIsNotNewInlineType() {
Api api = RamlLoader.load(this.getClass().getResourceAsStream("inline-types.raml"), ".");
ObjectTypeDeclaration decl = RamlLoader.findTypes("foo", api.types());
TypeDeclaration property = findProperty(decl, "extendedFromOne");
assertFalse(TypeDeclarationType.isNewInlineType(property));
}
开发者ID:mulesoft-labs,项目名称:raml-java-tools,代码行数:10,代码来源:TypeDeclarationTypeTest.java
示例20: extendedObjectWithExtraPropertiesIsNewInlineType
import org.raml.v2.api.model.v10.api.Api; //导入依赖的package包/类
@Test
public void extendedObjectWithExtraPropertiesIsNewInlineType() {
Api api = RamlLoader.load(this.getClass().getResourceAsStream("inline-types.raml"), ".");
ObjectTypeDeclaration decl = RamlLoader.findTypes("foo", api.types());
TypeDeclaration property = findProperty(decl, "extendedFromOneWithExtraProperty");
assertTrue(TypeDeclarationType.isNewInlineType(property));
}
开发者ID:mulesoft-labs,项目名称:raml-java-tools,代码行数:10,代码来源:TypeDeclarationTypeTest.java
注:本文中的org.raml.v2.api.model.v10.api.Api类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论