本文整理汇总了Java中org.raml.v2.api.RamlModelBuilder类的典型用法代码示例。如果您正苦于以下问题:Java RamlModelBuilder类的具体用法?Java RamlModelBuilder怎么用?Java RamlModelBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RamlModelBuilder类属于org.raml.v2.api包,在下文中一共展示了RamlModelBuilder类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: main
import org.raml.v2.api.RamlModelBuilder; //导入依赖的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: main
import org.raml.v2.api.RamlModelBuilder; //导入依赖的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
示例3: main
import org.raml.v2.api.RamlModelBuilder; //导入依赖的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
示例4: test1
import org.raml.v2.api.RamlModelBuilder; //导入依赖的package包/类
public void test1(){
ApiImpl model=new ApiImpl();
model.setTitle("Hello");
ActionImpl orCreateMethod = model.getOrCreateResource("persons").getOrCreateMethod("get");
orCreateMethod.addBody("application/json", BuiltIns.OBJECT);
AbstractType deriveObjectType = TypeOps.deriveObjectType("");
deriveObjectType.declareProperty("name", BuiltIns.STRING,false);
deriveObjectType.declareProperty("lastName", BuiltIns.STRING,false);
deriveObjectType.declareProperty("age", BuiltIns.INTEGER,false);
orCreateMethod.addResponse("200","application/json", deriveObjectType);
orCreateMethod.addQueryParameter(new NamedParamImpl("count",BuiltIns.STRING, true, true));
orCreateMethod.addQueryParameter(new NamedParamImpl("offset",BuiltIns.STRING, false, true));
String store = new RamlWriter().store(model);
RamlModelResult buildApi = new RamlModelBuilder().buildApi(store, "");
TestCase.assertTrue(!buildApi.hasErrors());
Api api=(Api) new TopLevelRamlModelBuilder().build(store, new CompositeResourceLoader(),"");
TestCase.assertTrue(api.resources().get(0).methods().get(0).queryParameters().get(0).isRequired());
TestCase.assertTrue(!api.resources().get(0).methods().get(0).queryParameters().get(1).isRequired());
}
开发者ID:OnPositive,项目名称:aml,代码行数:21,代码来源:WriterTest.java
示例5: test2
import org.raml.v2.api.RamlModelBuilder; //导入依赖的package包/类
public void test2(){
ApiImpl model=new ApiImpl();
model.setTitle("Hello");
ActionImpl orCreateMethod = model.getOrCreateResource("persons").getOrCreateMethod("get");
orCreateMethod.addBody("application/json", BuiltIns.OBJECT);
AbstractType deriveObjectType = TypeOps.deriveObjectType("Person");
deriveObjectType.declareProperty("name", BuiltIns.STRING,false);
deriveObjectType.declareProperty("lastName", BuiltIns.STRING,false);
deriveObjectType.declareProperty("age", BuiltIns.INTEGER,false);
orCreateMethod.addResponse("200","application/json", deriveObjectType);
model.addType(deriveObjectType);
orCreateMethod.addQueryParameter(new NamedParamImpl("count",BuiltIns.STRING, true, true));
orCreateMethod.addQueryParameter(new NamedParamImpl("offset",BuiltIns.STRING, false, true));
String store = new RamlWriter().store(model);
RamlModelResult buildApi = new RamlModelBuilder().buildApi(store, "");
TestCase.assertTrue(!buildApi.hasErrors());
Api api=(Api) new TopLevelRamlModelBuilder().build(store, new CompositeResourceLoader(),"");
TestCase.assertTrue(api.resources().get(0).methods().get(0).queryParameters().get(0).isRequired());
TestCase.assertTrue(!api.resources().get(0).methods().get(0).queryParameters().get(1).isRequired());
TestCase.assertTrue(api.resources().get(0).methods().get(0).responses().get(0).body().get(0).getTypeModel().name().equals("Person"));
}
开发者ID:OnPositive,项目名称:aml,代码行数:23,代码来源:WriterTest.java
示例6: test3
import org.raml.v2.api.RamlModelBuilder; //导入依赖的package包/类
public void test3(){
ApiImpl model=new ApiImpl();
model.setTitle("Hello");
ActionImpl orCreateMethod = model.getOrCreateResource("persons").getOrCreateMethod("get");
orCreateMethod.addBody("application/json", BuiltIns.OBJECT);
AbstractType deriveObjectType = TypeOps.deriveObjectType("Person");
deriveObjectType.declareProperty("name", BuiltIns.STRING,false);
deriveObjectType.declareProperty("lastName", BuiltIns.STRING,false);
deriveObjectType.declareProperty("age", BuiltIns.INTEGER,false);
orCreateMethod.addResponse("200","application/json", deriveObjectType);
model.addType(deriveObjectType);
orCreateMethod.addQueryParameter(new NamedParamImpl("count",BuiltIns.STRING, true, true));
orCreateMethod.addQueryParameter(new NamedParamImpl("offset",BuiltIns.STRING, false, true));
String store = new RamlWriter().store(model);
RamlModelResult buildApi = new RamlModelBuilder().buildApi(store, "");
TestCase.assertTrue(!buildApi.hasErrors());
Api api=(Api) new TopLevelRamlModelBuilder().build(store, new CompositeResourceLoader(),"");
TestCase.assertTrue(api.resources().get(0).methods().get(0).queryParameters().get(0).isRequired());
TestCase.assertTrue(!api.resources().get(0).methods().get(0).queryParameters().get(1).isRequired());
TestCase.assertTrue(api.resources().get(0).methods().get(0).responses().get(0).body().get(0).getTypeModel().name().equals("Person"));
}
开发者ID:OnPositive,项目名称:aml,代码行数:22,代码来源:WriterTest.java
示例7: test6
import org.raml.v2.api.RamlModelBuilder; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public void test6(){
ApiImpl model=new ApiImpl();
model.setTitle("hello");
SecuritySchemeImpl e = new SecuritySchemeImpl();
e.setName("o2");
e.settings().put("accessTokenUri","http");
e.settings().put("authorizationUri","http");
e.settings().put("authorizationGrants","password");
e.setType("OAuth 2.0");
e.settings().put("scopes", new String[]{"a","b"});
model.securityDefinitions().add(e);
String store = new RamlWriter().store(model);
RamlModelResult buildApi = new RamlModelBuilder().buildApi(store, "");
TestCase.assertTrue(!buildApi.hasErrors());
Api api=(Api) new TopLevelRamlModelBuilder().build(store, new CompositeResourceLoader(),"");
TestCase.assertTrue(Arrays.equals((Object[])((List<Object>) api.securityDefinitions().get(0).settings().get("scopes")).toArray(), new Object[]{"a","b"}));
}
开发者ID:OnPositive,项目名称:aml,代码行数:19,代码来源:WriterTest.java
示例8: test7
import org.raml.v2.api.RamlModelBuilder; //导入依赖的package包/类
public void test7(){
ApiImpl model=new ApiImpl();
ActionImpl orCreateMethod = model.getOrCreateResource("persons").getOrCreateMethod("get");
model.setTitle("hello");
SecuritySchemeImpl e = new SecuritySchemeImpl();
e.setName("oauth2");
e.settings().put("accessTokenUri","http");
e.settings().put("authorizationUri","http");
e.settings().put("authorizationGrants","password");
e.setType("OAuth 2.0");
e.settings().put("scopes", new String[]{"a","b"});
orCreateMethod.securedBy().add(new SecuredByConfigImpl("oauth2").with("scopes",new String[]{"c"}));
model.securityDefinitions().add(e);
String store = new RamlWriter().store(model);
RamlModelResult buildApi = new RamlModelBuilder().buildApi(store, "");
TestCase.assertTrue(!buildApi.hasErrors());
Api api=(Api) new TopLevelRamlModelBuilder().build(store, new CompositeResourceLoader(),"");
Object os=api.resources().get(0).methods().get(0).securedBy().get(0).settings().get("scopes");
TestCase.assertEquals(os.toString(), "[c]");
}
开发者ID:OnPositive,项目名称:aml,代码行数:21,代码来源:WriterTest.java
示例9: init
import org.raml.v2.api.RamlModelBuilder; //导入依赖的package包/类
private void init(String ramlLocation) {
try {
RamlModelResult ramlModelResult = new RamlModelBuilder().buildApi(ramlLocation);
Preconditions.checkArgument(!ramlModelResult.hasErrors(),
ramlModelResult.getValidationResults()
.stream()
.map(ValidationResult::getMessage)
.collect(Collectors.joining(", "))
);
Api api = ramlModelResult.getApiV08();
Preconditions.checkArgument(api != null, "API cannot be null. Check if there were errors or the RAML version is not 0.8");
logger.debug("RAML title: {}, version: {}", api.title(), api.version());
api.resources().forEach(this::addStubIfHaveExamples);
} catch(Exception ex) {
logger.error("Error {} while loading raml. Shutting down server. ", ex.getMessage());
this.shutdownServer();
throw new IllegalStateException(ex);
}
}
开发者ID:arielsegura,项目名称:raml-java-mock-server,代码行数:26,代码来源:RamlMockServer.java
示例10: createRamlModelFactoryFor
import org.raml.v2.api.RamlModelBuilder; //导入依赖的package包/类
/**
*
* Creates a Model factory for a specific raml document based on the documents version
* if the ramlVersion is specified, the model factory will only be created if the document is compatible with this specified version
*
* @param ramlURL The raml file for which to create a factory
* @param ramlVersion (nullable) The Version of raml for which to create a factory
* @return The Factory instance for this RAML document
*/
public static RamlModelFactory createRamlModelFactoryFor(String ramlURL, RamlVersion ramlVersion) {
RamlModelResult ramlModelResult = new RamlModelBuilder().buildApi(ramlURL);
if (ramlModelResult.hasErrors()) {
logger.error("Loaded RAML has validation errors: "+ StringUtils.collectionToCommaDelimitedString(ramlModelResult.getValidationResults()));
}
if (ramlModelResult.isVersion10()
&& (ramlVersion == null || RamlVersion.V10.equals(ramlVersion))) {
logger.info("RJP10V2RamlModelFactory Instantiated");
return new RJP10V2RamlModelFactory();
}
if ((!ramlModelResult.hasErrors() && RamlVersion.V08.equals(ramlVersion)) //To keep legacy support try load using the 08 if requested specifically
|| (ramlModelResult.isVersion08() && (ramlVersion == null || RamlVersion.V08.equals(ramlVersion)))) {
logger.info("RJP08V1RamlModelFactory Instantiated");
return new RJP08V1RamlModelFactory();
}
if (containsUnsupportedVersionError(ramlModelResult.getValidationResults()) || !isSupportedRamlVersionCombination(ramlVersion, ramlModelResult)) {
throw new UnsupportedRamlVersionError(RamlVersion.V08, RamlVersion.V10);
}
throw new InvalidRamlError(ramlURL, ramlModelResult.getValidationResults());
}
开发者ID:phoenixnap,项目名称:springmvc-raml-plugin,代码行数:32,代码来源:RamlModelFactoryOfFactories.java
示例11: buildRamlRoot
import org.raml.v2.api.RamlModelBuilder; //导入依赖的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
示例12: load
import org.raml.v2.api.RamlModelBuilder; //导入依赖的package包/类
public static Api load(InputStream is, String directory) {
RamlModelResult ramlModelResult =
new RamlModelBuilder().buildApi(
new InputStreamReader(is), directory);
if (ramlModelResult.hasErrors()) {
for (ValidationResult validationResult : ramlModelResult.getValidationResults()) {
System.out.println(validationResult.getMessage());
}
throw new AssertionError();
} else {
return ramlModelResult.getApiV10();
}
}
开发者ID:mulesoft-labs,项目名称:raml-java-tools,代码行数:15,代码来源:RamlLoader.java
示例13: execute
import org.raml.v2.api.RamlModelBuilder; //导入依赖的package包/类
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
getLog().error("GAAAAAA!");
if (skip) {
getLog().info("Skipping execution...");
return;
}
if (ramlFile == null) {
throw new MojoExecutionException("ramlFile is not defined");
}
try {
FileUtils.forceMkdir(outputDirectory);
} catch (final IOException ioe) {
throw new MojoExecutionException("Failed to create directory: " + outputDirectory, ioe);
}
try {
project.addCompileSourceRoot(outputDirectory.getPath());
RamlModelResult ramlModelResult =
new RamlModelBuilder().buildApi(
new FileReader(ramlFile),
".");
if (ramlModelResult.hasErrors()) {
for (ValidationResult validationResult : ramlModelResult.getValidationResults()) {
System.err.println(validationResult.getMessage());
}
throw new MojoExecutionException("invalid raml " + ramlFile);
}
final Api api = ramlModelResult.getApiV10();
RamlToPojo ramlToPojo = RamlToPojoBuilder.builder(api)
.inPackage(defaultPackage)
.fetchTypes(fromAnywhere())
.findTypes(everyWhere()).build();
ramlToPojo.buildPojos().createAllTypes(outputDirectory.getAbsolutePath());
} catch (IOException e) {
throw new MojoExecutionException("execution exception", e);
}
}
开发者ID:mulesoft-labs,项目名称:raml-java-tools,代码行数:47,代码来源:RamlToPojoMojo.java
示例14: RamlModelRepository
import org.raml.v2.api.RamlModelBuilder; //导入依赖的package包/类
RamlModelRepository(final Path filePath) {
this.filePath = filePath;
this.ramlModelResult = new RamlModelBuilder().buildApi(filePath.toFile());
if (ramlModelResult.hasErrors()) {
for (ValidationResult validationResult : ramlModelResult.getValidationResults()) {
LOG.error("{}", validationResult.toString());
}
System.exit(1);
}
}
开发者ID:vrapio,项目名称:vrap,代码行数:12,代码来源:RamlModelRepository.java
示例15: main
import org.raml.v2.api.RamlModelBuilder; //导入依赖的package包/类
public static void main(String[] args) {
RamlModelResult ramlModelResult = new RamlModelBuilder().buildApi(Paths.get("build", "ramldoc", "api.raml").toFile());
if (ramlModelResult.hasErrors()) {
for (ValidationResult validationResult : ramlModelResult.getValidationResults())
{
System.out.println(validationResult.getMessage());
}
} else {
System.out.println("validation successful");
Api api = ramlModelResult.getApiV10();
}
}
开发者ID:ePages-de,项目名称:restdocs-raml,代码行数:13,代码来源:RamlValidator.java
示例16: test
import org.raml.v2.api.RamlModelBuilder; //导入依赖的package包/类
public void test() {
AbstractType deriveObjectType = TypeOps.deriveObjectType("Person");
deriveObjectType.declareProperty("name", BuiltIns.STRING,false);
deriveObjectType.declareProperty("lastName", BuiltIns.STRING,false);
deriveObjectType.declareProperty("age", BuiltIns.INTEGER,false);
DumperOptions dumperOptions = new DumperOptions();
dumperOptions.setDefaultFlowStyle(FlowStyle.BLOCK);
RamlWriter w=new RamlWriter();
String result=w.store(deriveObjectType);
RamlModelResult buildApi = new RamlModelBuilder().buildApi(result, "");
TestCase.assertTrue(!buildApi.hasErrors());
}
开发者ID:OnPositive,项目名称:aml,代码行数:13,代码来源:WriterTest.java
示例17: test4
import org.raml.v2.api.RamlModelBuilder; //导入依赖的package包/类
public void test4(){
ApiImpl model=new ApiImpl();
model.setTitle("Hello");
model.addAnnotationType(TypeOps.derive("HelloAnnotation", BuiltIns.STRING));
model.annotations().add(new Annotation("HelloAnnotation", "Hello"));
String store = new RamlWriter().store(model);
RamlModelResult buildApi = new RamlModelBuilder().buildApi(store, "");
TestCase.assertTrue(!buildApi.hasErrors());
Api api=(Api) new TopLevelRamlModelBuilder().build(store, new CompositeResourceLoader(),"");
AbstractType tp=api.annotations().get(0).annotationType();
TestCase.assertTrue(tp.name().equals("HelloAnnotation"));
}
开发者ID:OnPositive,项目名称:aml,代码行数:13,代码来源:WriterTest.java
示例18: test5
import org.raml.v2.api.RamlModelBuilder; //导入依赖的package包/类
public void test5(){
ApiImpl model=new ApiImpl();
model.setTitle("Hello");
model.addAnnotationType(TypeOps.derive("HelloAnnotation", BuiltIns.STRING));
ActionImpl orCreateMethod = model.getOrCreateResource("persons").getOrCreateMethod("get");
orCreateMethod.annotations().add(new Annotation("HelloAnnotation", "Hello"));
String store = new RamlWriter().store(model);
RamlModelResult buildApi = new RamlModelBuilder().buildApi(store, "");
TestCase.assertTrue(!buildApi.hasErrors());
Api api=(Api) new TopLevelRamlModelBuilder().build(store, new CompositeResourceLoader(),"");
TestCase.assertTrue(api.resources().get(0).methods().get(0).annotations().get(0).value().equals("Hello"));
}
开发者ID:OnPositive,项目名称:aml,代码行数:13,代码来源:WriterTest.java
示例19: buildApiModel
import org.raml.v2.api.RamlModelBuilder; //导入依赖的package包/类
/**
* Builds an API model for the given RAML source file.
* @param sourceFileName source file name
* @return API model
* @throws ParserException on syntax errors
*/
public ApiModel buildApiModel(String sourceFileName) {
RamlModelResult ramlModelResult = new RamlModelBuilder().buildApi(sourceFileName);
if (ramlModelResult.hasErrors()) {
for (ValidationResult result : ramlModelResult.getValidationResults()) {
log.error("{}: {}", result.getPath(), result.getMessage());
}
throw new ParserException("RAML syntax errors, see previous messages");
}
Api api = ramlModelResult.getApiV10();
return new ApiModel(api);
}
开发者ID:ops4j,项目名称:org.ops4j.ramler,代码行数:19,代码来源:ApiModelBuilder.java
示例20: parse
import org.raml.v2.api.RamlModelBuilder; //导入依赖的package包/类
private void parse(String simpleName) {
RamlModelResult ramlModelResult = new RamlModelBuilder().buildApi("raml/" + simpleName);
if (ramlModelResult.hasErrors()) {
log.error("Parse errors: {}",ramlModelResult.getValidationResults());
}
assertThat(ramlModelResult.hasErrors()).isFalse();
Api api = ramlModelResult.getApiV10();
apiModel = new ApiModel(api);
}
开发者ID:ops4j,项目名称:org.ops4j.ramler,代码行数:10,代码来源:ParserTest.java
注:本文中的org.raml.v2.api.RamlModelBuilder类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论