Skip to content
This repository has been archived by the owner on Feb 12, 2022. It is now read-only.

Adding JS and Java bindings. #66

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,6 @@ pom.xml.asc
package.json
.idea/
output/
bindings/js/**/*.js
bindings/js/**/*.js.map
bindings/js/node_modules
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,17 @@ $ lein jar
$ lein npm install # this is only required on the first run
$ lein node
```

The output NPM package will be generated at `output/node`.

### Java Bindings

The programming guide for the Java Bindings can be found [here](doc/java.md).
Javadoc for the bindings can be consulted [here](https://raml-org.github.io/api-modeling-framework/doc/java/apidocs/index.html).

### JS Bindings

The programming guide for the JS Bindings can be found [here](doc/js.md).
Documentation for the bindings can be consulted [here](https://raml-org.github.io/api-modeling-framework/doc/js/apidocs/index.html).

### API Modeling Framework Clojurescript/Web library

Expand Down
22 changes: 22 additions & 0 deletions bindings/java/amf-java.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_7" inherit-compiler-output="false">
<output url="file://$MODULE_DIR$/../target/classes" />
<output-test url="file://$MODULE_DIR$/../target/test-classes" />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module-library">
<library name="Maven: api-modeling-framework:api-modeling-framework:0.1.2-SNAPSHOT">
<CLASSES>
<root url="jar://$MODULE_DIR$/../target/api-modeling-framework-0.1.2-SNAPSHOT-standalone.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="library" name="api-modeling-framework-0.1.2-SNAPSHOT-standalone" level="project" />
</component>
</module>
57 changes: 57 additions & 0 deletions bindings/java/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?xml version="1.0" encoding="UTF-8"?><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.raml</groupId>
<artifactId>amf-java</artifactId>
<packaging>jar</packaging>
<version>0.1.2-SNAPSHOT</version>
<name>api-modeling-framework java bindings</name>
<description>API and domain modeling tools for RAML, OpenAPI (Swagger) and RDF</description>
<url>https://github.com/mulesoft-labs/api-modeling-framework</url>
<licenses>
<license>
<name>Apache-2.0</name>
<url>http://www.eclipse.org/legal/epl-v10.html</url>
</license>
</licenses>
<scm>
<connection>scm:git:git://github.com/raml-org/api-modelling-framework.git</connection>
<developerConnection>scm:git:ssh://git@github.com/raml-org/api-modelling-framework.git</developerConnection>
<tag>61a8011ec87cd6a09be6bcdaa7c37de34c5a538c
</tag>
<url>https://github.com/raml-org/api-modelling-framework</url>
</scm>
<properties>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
<build>
<sourceDirectory>src</sourceDirectory>
<directory>../../target</directory>
<outputDirectory>../../target/classes</outputDirectory>
<plugins/>
</build>
<dependencyManagement>
<dependencies/>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>api-modeling-framework</groupId>
<artifactId>api-modeling-framework</artifactId>
<version>0.1.2-SNAPSHOT</version>
<scope>system</scope>
<systemPath>${project.basedir}/../../target/api-modeling-framework-0.1.2-SNAPSHOT-standalone.jar</systemPath>
</dependency>
</dependencies>
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.10.4</version>
<configuration>
<additionalparam>-Xdoclint:none</additionalparam>
</configuration>
</plugin>
</plugins>
</reporting>
</project>
66 changes: 66 additions & 0 deletions bindings/java/src/org/raml/amf/AMF.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package org.raml.amf;

import org.raml.amf.generators.AMFJSONLDGenerator;
import org.raml.amf.generators.OpenAPIGenerator;
import org.raml.amf.generators.RAMLGenerator;
import org.raml.amf.parsers.AMFJSONLDParser;
import org.raml.amf.parsers.OpenAPIParser;
import org.raml.amf.parsers.RAMLParser;

/**
* Created by antoniogarrote on 04/05/2017.
*/

/**
* Facade class providing access to the main IO facilities in the library
*/
public class AMF {

/**
* Builds a RAML to AMF parser
* @return
*/
public static RAMLParser RAMLParser() {
return new RAMLParser();
}

/**
* Builds an OpenAPI to AMF parser
* @return
*/
public static OpenAPIParser OpenAPIParser() {
return new OpenAPIParser();
}

/**
* Builds a AMF encoded JSON-LD to AMF parser
* @return
*/
public static AMFJSONLDParser JSONLDParser() {
return new AMFJSONLDParser();
}

/**
* Builds a AMF to RAML generator
* @return
*/
public static RAMLGenerator RAMLGenerator() {
return new RAMLGenerator();
}

/**
* Builds a AMF to OpenAPI generator
* @return
*/
public static OpenAPIGenerator OpenAPIGenerator() {
return new OpenAPIGenerator();
}

/**
* Builds a AMF to JSON-LD generator
* @return
*/
public static AMFJSONLDGenerator JSONLDGenerator() {
return new AMFJSONLDGenerator();
}
}
37 changes: 37 additions & 0 deletions bindings/java/src/org/raml/amf/core/Model.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package org.raml.amf.core;

/**
* Created by antoniogarrote on 04/05/2017.
*/

import org.raml.amf.core.exceptions.InvalidModelException;
import org.raml.amf.utils.Clojure;

/**
* Base class for all AMF parsed models, provides methods to inspect and manipulate the model
*/
public abstract class Model {

static {
Clojure.require(Clojure.API_MODELING_FRAMEWORK_CORE);
}

protected Object rawModel;

/**
* Builds the model from the inner Clojure data structure generated by the AMF library
* @param rawModel
*/
protected Model(Object rawModel) {
if (rawModel instanceof Exception) {
throw new InvalidModelException((Exception) rawModel);
}
this.rawModel = rawModel;
}

/**
* Returns the raw Clojure data structure for this instance data
* @return
*/
public abstract Object clojureModel();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.raml.amf.core.document;

import org.raml.amf.core.domain.DomainModel;

import java.util.List;

/**
* Created by antoniogarrote on 04/05/2017.
*/

public interface DeclaresDomainModel {
/**
* Declared DomainElements that can be re-used from other documents.
* @return List of domain elements.
*/
public List<DomainModel> declares();
}
54 changes: 54 additions & 0 deletions bindings/java/src/org/raml/amf/core/document/Document.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package org.raml.amf.core.document;

import clojure.lang.IFn;
import org.raml.amf.core.domain.DomainModel;
import org.raml.amf.core.exceptions.InvalidModelException;
import org.raml.amf.utils.Clojure;

import java.util.ArrayList;
import java.util.List;

/**
* Created by antoniogarrote on 04/05/2017.
*/

/**
* AMF Documents encode the main element of a description in a particular Domain Model
* For example, in RAML/HTTP, the main domain element is an APIDescription.
*
* Since AMF Documents encode Domain elements they behave like Fragments
* AMF Documents can also contains declarations of domain elements to be used in the description of the domain.
* From this point of view Documents also behave like Modules.
*/
public class Document extends DocumentModel implements EncodesDomainModel, DeclaresDomainModel {
public Document(Object rawModel) {
super(rawModel);
}

/**
* Encoded domain element. It's considered to be the root element of a stand-alone description, not a domain element
* to be re-used and reference
* @return DomainElement encoded in the document.
* @throws InvalidModelException
*/
public DomainModel encodes() throws InvalidModelException {
IFn getFn = Clojure.var(Clojure.API_MODELING_FRAMEWORK_MODEL_DOCUMENT, "encodes");
return DomainModel.fromRawModel(getFn.invoke(this.clojureModel()));
}

/**
* List of domain elements declared in the document to be referenced in the encoded element.
* They are supposed to be private to the description and not meant to be re-used as in Modules.
* @return
*/
public List<DomainModel> declares() {
IFn getFn = Clojure.var(Clojure.API_MODELING_FRAMEWORK_MODEL_DOCUMENT, "declares");
List parsedElements = Clojure.toJavaList((List) getFn.invoke(this.clojureModel()));
ArrayList<DomainModel> declared = new ArrayList<>();
for(Object parsed : parsedElements) {
declared.add(DomainModel.fromRawModel(parsed));
}

return declared;
}
}
Loading