main
Jörg Prante 1 year ago
parent fea602159f
commit 95c0501d5e

@ -0,0 +1,9 @@
dependencies {
implementation 'javax.json:javax.json-api:1.1.4'
implementation 'org.apache.ws.xmlschema:xmlschema-core:2.3.0'
implementation('com.github.fge:json-schema-validator:2.2.6') {
exclude group: 'com.google.guava'
}
implementation 'org.yaml:snakeyaml:2.0'
implementation 'com.fasterxml.jackson.core:jackson-databind:2.14.2'
}

@ -0,0 +1,256 @@
/*
* Copyright 2013 (c) MuleSoft, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*/
package org.xbib.raml.api;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
import java.net.URI;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import org.xbib.raml.api.loader.ResourceLoader;
import org.xbib.raml.api.loader.ResourceLoaderFactories;
import org.xbib.raml.api.loader.ResourceLoaderFactory;
import org.xbib.raml.api.model.PermissiveURI;
import org.xbib.raml.api.model.common.ValidationResult;
import org.xbib.raml.api.model.v10.RamlFragment;
import org.xbib.raml.api.model.v10.api.DocumentationItem;
import org.xbib.raml.api.model.v10.api.Library;
import org.xbib.raml.api.model.v10.datamodel.ExampleSpec;
import org.xbib.raml.api.model.v10.datamodel.TypeDeclaration;
import org.xbib.raml.api.model.v10.methods.Trait;
import org.xbib.raml.api.model.v10.resources.ResourceType;
import org.xbib.raml.api.model.v10.security.SecurityScheme;
import org.xbib.raml.internal.impl.RamlBuilder;
import org.xbib.raml.internal.impl.commons.RamlHeader;
import org.xbib.raml.internal.impl.commons.model.Api;
import org.xbib.raml.internal.impl.commons.model.DefaultModelElement;
import org.xbib.raml.internal.impl.commons.model.RamlValidationResult;
import org.xbib.raml.internal.impl.commons.model.StringType;
import org.xbib.raml.internal.impl.commons.model.factory.TypeDeclarationModelFactory;
import org.xbib.raml.internal.impl.commons.nodes.RamlDocumentNode;
import org.xbib.raml.internal.utils.IOUtils;
import org.xbib.raml.internal.utils.RamlNodeUtils;
import org.xbib.raml.internal.utils.StreamUtils;
import org.xbib.raml.yagi.framework.model.DefaultModelBindingConfiguration;
import org.xbib.raml.yagi.framework.model.ModelBindingConfiguration;
import org.xbib.raml.yagi.framework.model.ModelProxyBuilder;
import org.xbib.raml.yagi.framework.nodes.ErrorNode;
import org.xbib.raml.yagi.framework.nodes.KeyValueNode;
import org.xbib.raml.yagi.framework.nodes.KeyValueNodeImpl;
import org.xbib.raml.yagi.framework.nodes.Node;
import org.xbib.raml.yagi.framework.nodes.StringNodeImpl;
/**
* Entry point class to parse top level RAML descriptors.
*/
public class RamlModelBuilder {
public static final String MODEL_PACKAGE = "org.xbib.raml.internal.impl.commons.model";
private final ResourceLoaderFactory resourceLoaderFactory;
private final RamlBuilder builder = new RamlBuilder();
public RamlModelBuilder() {
resourceLoaderFactory = ResourceLoaderFactories.defaultResourceLoaderFactory();
// new DefaultResourceLoader(RootDirectoryFileAccessGuard.fromRootDir(Sets.newHashSet("file", "http", "https"),
// ".")));
}
public RamlModelBuilder(ResourceLoader resourceLoaderFactory) {
this.resourceLoaderFactory = ResourceLoaderFactories.identityFactory(resourceLoaderFactory);
}
public RamlModelResult buildApi(String ramlLocation) {
String content = getRamlContent(ramlLocation);
if (content == null) {
return generateRamlApiResult("Raml does not exist at: " + ramlLocation);
}
return buildApi(content, ramlLocation);
}
public RamlModelResult buildApi(File ramlFile) {
String content = getRamlContent(ramlFile);
if (content == null) {
return generateRamlApiResult("Files does not exist or is not a regular file: " + ramlFile.getPath());
}
return buildApi(content, ramlFile.getPath());
}
public RamlModelResult buildApi(Reader reader, String ramlLocation) {
String content = getRamlContent(reader);
if (content == null) {
return generateRamlApiResult("Invalid reader provided with location: " + ramlLocation);
}
return buildApi(content, ramlLocation);
}
public RamlModelResult buildApi(String content, String ramlLocation) {
if (content == null) {
return buildApi(ramlLocation);
}
if (ramlLocation.matches("^[a-z]+:.*")) {
String actualName = PermissiveURI.create(ramlLocation).toString();
if (ramlLocation.startsWith("file:")) {
actualName = new File(PermissiveURI.create(ramlLocation).getPath()).getParent();
}
Node ramlNode = builder.build(content, resourceLoaderFactory.createResourceLoader(actualName), ramlLocation);
return generateRamlApiResult(ramlNode, getFragment(content));
} else {
Node ramlNode = builder.build(content, resourceLoaderFactory.createResourceLoader(Paths.get(ramlLocation).toAbsolutePath().getParent().toString()), ramlLocation);
return generateRamlApiResult(ramlNode, getFragment(content));
}
}
private RamlFragment getFragment(String content) {
try {
RamlHeader ramlHeader = RamlHeader.parse(content);
return ramlHeader.getFragment();
} catch (RamlHeader.InvalidHeaderException e) {
// ignore, already handled by builder
}
return null;
}
private RamlModelResult generateRamlApiResult(Node ramlNode, RamlFragment fragment) {
List<ValidationResult> validationResults = new ArrayList<>();
List<ErrorNode> errors = RamlNodeUtils.getErrors(ramlNode);
for (ErrorNode errorNode : errors) {
validationResults.add(new RamlValidationResult(errorNode));
}
if (validationResults.isEmpty()) {
return wrapTree(ramlNode, fragment);
}
return new RamlModelResult(validationResults);
}
private RamlModelResult generateRamlApiResult(String errorMessage) {
List<ValidationResult> validationResults = new ArrayList<>();
validationResults.add(new RamlValidationResult(errorMessage));
return new RamlModelResult(validationResults);
}
private RamlModelResult wrapTree(Node ramlNode, RamlFragment fragment) {
if (ramlNode instanceof RamlDocumentNode) {
org.xbib.raml.api.model.v10.api.Api apiV10 = ModelProxyBuilder.createModel(org.xbib.raml.api.model.v10.api.Api.class, new Api((RamlDocumentNode) ramlNode), createV10Binding());
return new RamlModelResult(apiV10);
}
if (fragment == RamlFragment.Library) {
Library library = ModelProxyBuilder.createModel(Library.class, new DefaultModelElement(ramlNode), createV10Binding());
return new RamlModelResult(library);
}
if (fragment == RamlFragment.DataType || fragment == RamlFragment.AnnotationTypeDeclaration) {
final org.xbib.raml.internal.impl.commons.model.type.TypeDeclaration delegateNode = new TypeDeclarationModelFactory().create(ramlNode);
final ModelBindingConfiguration v10Binding = createV10Binding();
TypeDeclaration typeDeclaration = ModelProxyBuilder.createModel((Class<TypeDeclaration>) v10Binding.reverseBindingOf(delegateNode), delegateNode, v10Binding);
return new RamlModelResult(typeDeclaration);
}
if (fragment == RamlFragment.DocumentationItem) {
DocumentationItem documentationItem = ModelProxyBuilder.createModel(DocumentationItem.class, new DefaultModelElement(ramlNode), createV10Binding());
return new RamlModelResult(documentationItem);
}
if (fragment == RamlFragment.SecurityScheme) {
SecurityScheme securityScheme = ModelProxyBuilder.createModel(SecurityScheme.class, new DefaultModelElement(ramlNode), createV10Binding());
return new RamlModelResult(securityScheme);
}
if (fragment == RamlFragment.Trait) {
Trait trait = ModelProxyBuilder.createModel(Trait.class, new DefaultModelElement(ramlNode), createV10Binding());
return new RamlModelResult(trait);
}
if (fragment == RamlFragment.ResourceType) {
ResourceType resourceType = ModelProxyBuilder.createModel(ResourceType.class, new DefaultModelElement(ramlNode), createV10Binding());
return new RamlModelResult(resourceType);
}
if (fragment == RamlFragment.NamedExample) {
if (!(ramlNode instanceof KeyValueNode)) {
ramlNode = new KeyValueNodeImpl(new StringNodeImpl("__NamedExample_Fragment__"), ramlNode);
}
ExampleSpec exampleSpec = ModelProxyBuilder.createModel(ExampleSpec.class, new org.xbib.raml.internal.impl.commons.model.ExampleSpec((KeyValueNode) ramlNode), createV10Binding());
return new RamlModelResult(exampleSpec);
}
throw new IllegalStateException("Invalid ramlNode type (" + ramlNode.getClass().getSimpleName() + ") or fragment (" + fragment + ") combination");
}
private ModelBindingConfiguration createV10Binding() {
final DefaultModelBindingConfiguration bindingConfiguration = new DefaultModelBindingConfiguration();
bindingConfiguration.bindPackage(MODEL_PACKAGE);
// Bind all StringTypes to the StringType implementation they are only marker interfaces
bindingConfiguration.bind(org.xbib.raml.api.model.v10.system.types.StringType.class, StringType.class);
bindingConfiguration.bind(org.xbib.raml.api.model.v10.system.types.ValueType.class, StringType.class);
bindingConfiguration.defaultTo(DefaultModelElement.class);
bindingConfiguration.bind(TypeDeclaration.class, new TypeDeclarationModelFactory());
bindingConfiguration.reverseBindPackage("org.xbib.raml.api.model.v10.datamodel");
return bindingConfiguration;
}
private String getRamlContent(File ramlFile) {
if (ramlFile == null || !ramlFile.isFile()) {
return null;
}
ResourceLoader fileLoader = resourceLoaderFactory.createResourceLoader(ramlFile.getAbsoluteFile().getParent());
return getRamlContent(ramlFile.getName(), fileLoader);
}
private String getRamlContent(Reader ramlReader) {
if (ramlReader == null) {
return null;
}
try {
return IOUtils.toString(ramlReader);
} catch (IOException e) {
return null;
} finally {
IOUtils.closeQuietly(ramlReader);
}
}
private String getRamlContent(String ramlLocation) {
if (ramlLocation == null) {
return null;
}
if (ramlLocation.startsWith("file:")) {
Path p = Paths.get(URI.create(ramlLocation)).toAbsolutePath().getParent();
return getRamlContent(ramlLocation, resourceLoaderFactory.createResourceLoader(p.toString()));
} else {
Path p = Paths.get(ramlLocation).toAbsolutePath().getParent();
return getRamlContent(ramlLocation, resourceLoaderFactory.createResourceLoader(p.toString()));
}
}
private String getRamlContent(String ramlLocation, ResourceLoader loader) {
if (ramlLocation == null) {
return null;
}
InputStream ramlStream = loader.fetchResource(ramlLocation);
if (ramlStream != null) {
return StreamUtils.toString(ramlStream);
}
return null;
}
}

@ -0,0 +1,239 @@
/*
* Copyright 2013 (c) MuleSoft, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*/
package org.xbib.raml.api;
import java.util.ArrayList;
import java.util.List;
import org.xbib.raml.api.model.common.ValidationResult;
import org.xbib.raml.api.model.v10.RamlFragment;
import org.xbib.raml.api.model.v10.api.Api;
import org.xbib.raml.api.model.v10.api.DocumentationItem;
import org.xbib.raml.api.model.v10.api.Library;
import org.xbib.raml.api.model.v10.datamodel.ExampleSpec;
import org.xbib.raml.api.model.v10.datamodel.TypeDeclaration;
import org.xbib.raml.api.model.v10.methods.Trait;
import org.xbib.raml.api.model.v10.resources.ResourceType;
import org.xbib.raml.api.model.v10.security.SecurityScheme;
/**
* Represents the result of parsing a top level RAML descriptor or fragment.
* <p>
* If there are no parsing errors and the parsed RAML was a top level descriptor,
* the <code>Api</code> model matching the RAML version is available.
* If the parsed raml is 1.0 fragment and there are no errors, the corresponding
* fragment instance is available.
* <p>
* If there are parsing errors, the list of errors is available.
*/
public class RamlModelResult {
private List<ValidationResult> validationResults = new ArrayList<>();
private Api apiV10;
private Library library;
private TypeDeclaration typeDeclaration;
private SecurityScheme securityScheme;
private Trait trait;
private ResourceType resourceType;
private ExampleSpec exampleSpec;
private DocumentationItem documentationItem;
RamlModelResult(List<ValidationResult> validationResults) {
if (validationResults == null || validationResults.isEmpty()) {
throw new IllegalArgumentException("validationResults cannot be null or emtpy");
}
this.validationResults = validationResults;
}
RamlModelResult(Api apiV10) {
if (apiV10 == null) {
throw new IllegalArgumentException("apiV10 cannot be null");
}
this.apiV10 = apiV10;
}
RamlModelResult(Library library) {
if (library == null) {
throw new IllegalArgumentException("library cannot be null");
}
this.library = library;
}
public RamlModelResult(TypeDeclaration typeDeclaration) {
if (typeDeclaration == null) {
throw new IllegalStateException("typeDeclaration cannot be null");
}
this.typeDeclaration = typeDeclaration;
}
public RamlModelResult(SecurityScheme securityScheme) {
if (securityScheme == null) {
throw new IllegalStateException("securityScheme cannot be null");
}
this.securityScheme = securityScheme;
}
public RamlModelResult(DocumentationItem documentationItem) {
if (documentationItem == null) {
throw new IllegalStateException("documentationItem cannot be null");
}
this.documentationItem = documentationItem;
}
public RamlModelResult(Trait trait) {
if (trait == null) {
throw new IllegalStateException("trait cannot be null");
}
this.trait = trait;
}
public RamlModelResult(ResourceType resourceType) {
if (resourceType == null) {
throw new IllegalStateException("resourceType cannot be null");
}
this.resourceType = resourceType;
}
public RamlModelResult(ExampleSpec exampleSpec) {
if (exampleSpec == null) {
throw new IllegalStateException("exampleSpec cannot be null");
}
this.exampleSpec = exampleSpec;
}
/**
* @return true if any parsing error occurred
*/
public boolean hasErrors() {
return !validationResults.isEmpty();
}
/**
* @return the list of validation results if there were parsing errors
* or an empty list if there were no parsing errors
*/
public List<ValidationResult> getValidationResults() {
return validationResults;
}
/**
* @return the RAML Api v1.0 parsed without errors
* or null if there were errors or the RAML version is not 1.0 or is not a top level RAML
*/
public Api getApiV10() {
return apiV10;
}
/**
* @return the RAML Library v1.0 parsed without errors
* or null if there were errors or the RAML is not a Library fragment
*/
public Library getLibrary() {
return library;
}
/**
* @return the RAML Data Type v1.0 parsed without errors
* or null if there were errors or the RAML is not a Data Type fragment
*/
public TypeDeclaration getTypeDeclaration() {
return typeDeclaration;
}
/**
* @return the RAML Security Scheme v1.0 parsed without errors
* or null if there were errors or the RAML is not a Security Scheme fragment
*/
public SecurityScheme getSecurityScheme() {
return securityScheme;
}
/**
* @return the RAML Trait v1.0 parsed without errors
* or null if there were errors or the RAML is not a Trait fragment
*/
public Trait getTrait() {
return trait;
}
/**
* @return the RAML ResourceType v1.0 parsed without errors
* or null if there were errors or the RAML is not a ResourceType fragment
*/
public ResourceType getResourceType() {
return resourceType;
}
/**
* @return the RAML NamedExample v1.0 parsed without errors
* or null if there were errors or the RAML is not a NamedExample fragment
*/
public ExampleSpec getExampleSpec() {
return exampleSpec;
}
/**
* @return the RAML DocumentationItem v1.0 parsed without errors
* or null if there were errors or the RAML is not a DocumentationItem fragment
*/
public DocumentationItem getDocumentationItem() {
return documentationItem;
}
/**
* @return the RAML 1.0 fragment identifier or <code>null</code>
* if the RAML has errors or is version 0.8
*/
public RamlFragment getFragment() {
if (hasErrors()) {
return null;
}
if (getApiV10() != null) {
return RamlFragment.Default;
}
if (getLibrary() != null) {
return RamlFragment.Library;
}
if (getTypeDeclaration() != null) {
return RamlFragment.DataType;
}
if (getSecurityScheme() != null) {
return RamlFragment.SecurityScheme;
}
if (getTrait() != null) {
return RamlFragment.Trait;
}
if (getResourceType() != null) {
return RamlFragment.ResourceType;
}
if (getExampleSpec() != null) {
return RamlFragment.NamedExample;
}
if (getDocumentationItem() != null) {
return RamlFragment.DocumentationItem;
}
throw new IllegalStateException("Fragment not yet supported");
}
}

@ -0,0 +1,84 @@
/*
* Copyright 2013 (c) MuleSoft, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*/
package org.xbib.raml.api.loader;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.util.HashMap;
import java.util.Map;
import org.xbib.raml.internal.utils.IOUtils;
import org.xbib.raml.internal.utils.Pair;
public class CacheResourceLoader implements ResourceLoaderExtended {
private final Map<String, Pair<byte[], URI>> resources = new HashMap<>();
private final ResourceLoader resourceLoader;
public CacheResourceLoader(ResourceLoader resourceLoader) {
this.resourceLoader = resourceLoader;
}
@Override
public InputStream fetchResource(String resourceName) {
return fetchResource(resourceName, null);
}
@Override
public InputStream fetchResource(String resourceName, ResourceUriCallback callback) {
try {
if (resources.containsKey(resourceName)) {
final byte[] resourceByteArray = resources.get(resourceName).getLeft();
final URI uriCallback = resources.get(resourceName).getRight();
if (uriCallback != null && callback != null) {
callback.onResourceFound(uriCallback);
}
return toInputStreamOrNull(resourceByteArray);
}
InputStream resource;
URI uriCallback = null;
if (resourceLoader instanceof ResourceLoaderExtended) {
resource = ((ResourceLoaderExtended) resourceLoader).fetchResource(resourceName, callback);
uriCallback = ((ResourceLoaderExtended) resourceLoader).getUriCallBackParam();
} else {
resource = resourceLoader.fetchResource(resourceName);
}
// we want to cache results even if they are null
final byte[] resourceByteArray = resource == null ? null : IOUtils.toByteArray(resource);
resources.put(resourceName, Pair.of(resourceByteArray, uriCallback));
return toInputStreamOrNull(resourceByteArray);
} catch (final IOException e) {
return resourceLoader.fetchResource(resourceName);
}
}
private ByteArrayInputStream toInputStreamOrNull(final byte[] resourceByteArray) {
return resourceByteArray == null ? null : new ByteArrayInputStream(resourceByteArray);
}
@Override
public URI getUriCallBackParam() {
if (resourceLoader != null && resourceLoader instanceof ResourceLoaderExtended) {
return ((ResourceLoaderExtended) resourceLoader).getUriCallBackParam();
}
return null;
}
}

@ -0,0 +1,90 @@
/*
* Copyright 2013 (c) MuleSoft, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*/
package org.xbib.raml.api.loader;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
public class ClassPathResourceLoader implements ResourceLoaderExtended {
private final String rootRamlPackage;
private URI callbackParam;
public ClassPathResourceLoader() {
rootRamlPackage = "";
}
/**
* When the root raml is loaded through the classpath allows specifying
* the package where it is loaded from in order to correctly resolve
* absolute path includes and libraries
*
* @param rootRamlPackage in the classpath
*/
public ClassPathResourceLoader(String rootRamlPackage) {
if (rootRamlPackage.isBlank() || rootRamlPackage.equals("/")) {
this.rootRamlPackage = "";
} else {
this.rootRamlPackage = (rootRamlPackage.startsWith("/") ? rootRamlPackage.substring(1) : rootRamlPackage) + "/";
}
}
private URL getResource(String uselessRootPackage, String resourceName) {
String fixedResourceName = uselessRootPackage + (resourceName.startsWith("/") ? resourceName.substring(1) : resourceName);
URL url = getClass().getClassLoader().getResource(fixedResourceName);
if (url == null) {
return Thread.currentThread().getContextClassLoader().getResource(fixedResourceName);
}
return url;
}
@Override
public InputStream fetchResource(String resourceName, ResourceUriCallback callback) {
try {
final URL url = getResource(rootRamlPackage, resourceName);
if (url != null) {
this.callbackParam = url.toURI();
if (callback != null) {
callback.onResourceFound(callbackParam);
}
return url.openStream();
}
return null;
} catch (IOException | URISyntaxException e) {
return null;
}
}
@Override
public InputStream fetchResource(String resourceName) {
return fetchResource(resourceName, null);
}
@Override
public URI getUriCallBackParam() {
return callbackParam;
}
}

@ -0,0 +1,64 @@
/*
* Copyright 2013 (c) MuleSoft, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*/
package org.xbib.raml.api.loader;
import java.io.InputStream;
import java.net.URI;
public class CompositeResourceLoader implements ResourceLoaderExtended {
private final ResourceLoader[] resourceLoaders;
private ResourceLoader callBackLoader;
public CompositeResourceLoader(ResourceLoader... resourceLoaders) {
this.resourceLoaders = resourceLoaders;
}
public static CompositeResourceLoader compose(ResourceLoader... resourceLoaders) {
return new CompositeResourceLoader(resourceLoaders);
}
@Override
public InputStream fetchResource(String resourceName, ResourceUriCallback callback) {
InputStream inputStream = null;
for (ResourceLoader loader : resourceLoaders) {
if (loader instanceof ResourceLoaderExtended) {
inputStream = ((ResourceLoaderExtended) loader).fetchResource(resourceName, callback);
} else {
inputStream = loader.fetchResource(resourceName);
}
if (inputStream != null) {
callBackLoader = loader;
break;
}
}
return inputStream;
}
@Override
public InputStream fetchResource(String resourceName) {
return fetchResource(resourceName, null);
}
@Override
public URI getUriCallBackParam() {
if (callBackLoader != null && callBackLoader instanceof ResourceLoaderExtended) {
return ((ResourceLoaderExtended) callBackLoader).getUriCallBackParam();
}
return null;
}
}

@ -0,0 +1,54 @@
/*
* Copyright 2013 (c) MuleSoft, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*/
package org.xbib.raml.api.loader;
import java.io.InputStream;
import java.net.URI;
public class DefaultResourceLoader implements ResourceLoaderExtended {
private final ResourceLoader resourceLoader;
public DefaultResourceLoader() {
resourceLoader = CompositeResourceLoader.compose(
new UrlResourceLoader(),
new RamlUrlResourceLoader(),
new ClassPathResourceLoader(),
new FileResourceLoader("."));
}
@Override
public InputStream fetchResource(String resourceName, ResourceUriCallback callback) {
if (resourceLoader instanceof ResourceLoaderExtended) {
return ((ResourceLoaderExtended) resourceLoader).fetchResource(resourceName, callback);
} else {
return resourceLoader.fetchResource(resourceName);
}
}
@Override
public InputStream fetchResource(String resourceName) {
return fetchResource(resourceName, null);
}
@Override
public URI getUriCallBackParam() {
if (resourceLoader != null && resourceLoader instanceof ResourceLoaderExtended) {
return ((ResourceLoaderExtended) resourceLoader).getUriCallBackParam();
}
return null;
}
}

@ -0,0 +1,65 @@
/*
* Copyright 2013 (c) MuleSoft, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*/
package org.xbib.raml.api.loader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
public class FileResourceLoader implements ResourceLoaderExtended {
private final File parentPath;
private URI callbackParam;
public FileResourceLoader(String path) {
this(new File(path));
}
public FileResourceLoader(File path) {
this.parentPath = path;
}
@Override
public InputStream fetchResource(String resourceName, ResourceUriCallback callback) {
File includedFile = new File(resourceName);
if (!includedFile.isAbsolute()) {
includedFile = new File(parentPath, resourceName);
}
try {
if (callback != null) {
callbackParam = includedFile.toURI();
callback.onResourceFound(callbackParam);
}
return new FileInputStream(includedFile);
} catch (IOException e) {
return null;
}
}
@Override
public InputStream fetchResource(String resourceName) {
return fetchResource(resourceName, null);
}
@Override
public URI getUriCallBackParam() {
return callbackParam;
}
}

@ -0,0 +1,27 @@
/*
* Copyright 2013 (c) MuleSoft, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*/
package org.xbib.raml.api.loader;
import java.io.IOException;
import java.io.InputStream;
/**
* Created. There, you have it.
*/
public interface InputStreamProvider<T> {
InputStream apply(T object) throws IOException;
}

@ -0,0 +1,59 @@
/*
* Copyright 2013 (c) MuleSoft, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*/
package org.xbib.raml.api.loader;
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLConnection;
class RamlUrlResourceLoader implements ResourceLoaderExtended {
public static final String APPLICATION_RAML = "application/raml+yaml";
private URI callbackParam;
@Override
public InputStream fetchResource(String resourceName, ResourceUriCallback callback) {
try {
URL url = new URL(resourceName);
URLConnection connection = url.openConnection();
connection.setRequestProperty("Accept", APPLICATION_RAML + ", */*");
if (callback != null) {
callbackParam = url.toURI();
callback.onResourceFound(callbackParam);
}
return new BufferedInputStream(connection.getInputStream());
} catch (IOException e) {
// ignore on resource not found
} catch (URISyntaxException e) {
// Ignore
}
return null;
}
@Override
public InputStream fetchResource(String resourceName) {
return fetchResource(resourceName, null);
}
@Override
public URI getUriCallBackParam() {
return callbackParam;
}
}

@ -0,0 +1,31 @@
/*
* Copyright 2013 (c) MuleSoft, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*/
package org.xbib.raml.api.loader;
import java.io.InputStream;
public interface ResourceLoader {
/**
* Returns an input stream for reading the specified resource.
*
* @param resourceName the resource to try to fetch
* @return An input stream for reading the resource, or <tt>null</tt>
* if the resource could not be found
*/
InputStream fetchResource(String resourceName);
}

@ -0,0 +1,22 @@
/*
* Copyright 2013 (c) MuleSoft, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*/
package org.xbib.raml.api.loader;
public interface ResourceLoaderAware {
void setResourceLoader(ResourceLoader resourceLoader);
}

@ -0,0 +1,37 @@
/*
* Copyright 2013 (c) MuleSoft, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*/
package org.xbib.raml.api.loader;
import java.io.InputStream;
import java.net.URI;
public interface ResourceLoaderExtended extends ResourceLoader {
/**
* Returns an input stream for reading the specified resource.
*
* @param resourceName the resource to try to fetch
* @return An input stream for reading the resource, or <tt>null</tt>
* if the resource could not be found
*/
InputStream fetchResource(String resourceName, ResourceUriCallback callback);
/**
* Returns the URI used by ResourceUriCallback if exists
*
* @return An URI if callback is called in fetchResource method, or <tt>null</tt>
*/
URI getUriCallBackParam();
}

@ -0,0 +1,65 @@
/*
* Copyright 2013 (c) MuleSoft, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*/
package org.xbib.raml.api.loader;
import java.io.File;
import java.io.InputStream;
/**
* Created. There, you have it.
*/
public class ResourceLoaderFactories {
// this continously returns the same resource loader.
public static ResourceLoaderFactory identityFactory(final ResourceLoader loader) {
return new ResourceLoaderFactory() {
@Override
public ResourceLoader createResourceLoader(String parent) {
return loader;
}
};
}
// this is used nowhere but in the empty positions. these loaders shouldn't open files.
public static ResourceLoaderFactory nullFactory() {
return new ResourceLoaderFactory() {
@Override
public ResourceLoader createResourceLoader(String parent) {
return new ResourceLoader() {
@Override
public InputStream fetchResource(String resourceName) {
return null;
}
};
}
};
}
public static ResourceLoaderFactory defaultResourceLoaderFactory() {
return new ResourceLoaderFactory() {
@Override
public ResourceLoader createResourceLoader(String parent) {
return CompositeResourceLoader.compose(
new DefaultResourceLoader(),
new RootRamlFileResourceLoader(new File(parent)),
new RootRamlUrlResourceLoader(parent)
);
}
};
}
}

@ -0,0 +1,23 @@
/*
* Copyright 2013 (c) MuleSoft, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*/
package org.xbib.raml.api.loader;
/**
* Created. There, you have it.
*/
public interface ResourceLoaderFactory {
ResourceLoader createResourceLoader(String parent);
}

@ -0,0 +1,22 @@
/*
* Copyright 2013 (c) MuleSoft, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*/
package org.xbib.raml.api.loader;
import java.net.URI;
public interface ResourceUriCallback {
void onResourceFound(URI resourceURI);
}

@ -0,0 +1,62 @@
/*
* Copyright 2013 (c) MuleSoft, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*/
package org.xbib.raml.api.loader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.util.logging.Level;
import java.util.logging.Logger;
public class RootRamlFileResourceLoader implements ResourceLoaderExtended {
private final Logger logger = Logger.getLogger(RootRamlFileResourceLoader.class.getName());
private final File parentPath;
private URI callbackParam;
public RootRamlFileResourceLoader(File path) {
this.parentPath = path;
}
@Override
public InputStream fetchResource(String resourceName, ResourceUriCallback callback) {
final File includedFile = new File(parentPath, resourceName.startsWith("/") ? resourceName.substring(1) : resourceName);
logger.log(Level.FINE, "Looking for resource " + resourceName + " on directory " + parentPath);
try {
if (callback != null) {
callbackParam = includedFile.toURI();
callback.onResourceFound(callbackParam);
}
return new FileInputStream(includedFile);
} catch (IOException e) {
return null;
}
}
@Override
public InputStream fetchResource(String resourceName) {
return fetchResource(resourceName, null);
}
@Override
public URI getUriCallBackParam() {
return callbackParam;
}
}

@ -0,0 +1,64 @@
/*
* Copyright 2013 (c) MuleSoft, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*/
package org.xbib.raml.api.loader;
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLConnection;
public class RootRamlUrlResourceLoader implements ResourceLoaderExtended {
public static final String APPLICATION_RAML = "application/raml+yaml";
private final String rootRamlUrl;
private URI callbackParam;
public RootRamlUrlResourceLoader(String rootRamlUrl) {
this.rootRamlUrl = rootRamlUrl.endsWith("/") ? rootRamlUrl : rootRamlUrl + "/";
}
@Override
public InputStream fetchResource(String resourceName, ResourceUriCallback callback) {
try {
URL url = new URL(resourceName.startsWith(rootRamlUrl) ? resourceName : rootRamlUrl + resourceName);
final URLConnection connection = url.openConnection();
connection.setRequestProperty("Accept", APPLICATION_RAML + ", */*");
if (callback != null) {
callbackParam = url.toURI();
callback.onResourceFound(callbackParam);
}
return new BufferedInputStream(connection.getInputStream());
} catch (IOException | URISyntaxException e) {
return null;
}
}
@Override
public InputStream fetchResource(String resourceName) {
return fetchResource(resourceName, null);
}
@Override
public URI getUriCallBackParam() {
return callbackParam;
}
}

@ -0,0 +1,52 @@
/*
* Copyright 2013 (c) MuleSoft, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*/
package org.xbib.raml.api.loader;
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
class UrlResourceLoader implements ResourceLoaderExtended {
private URI callbackParam;
@Override
public InputStream fetchResource(String resourceName, ResourceUriCallback callback) {
try {
URL url = new URL(resourceName);
if (callback != null) {
callbackParam = url.toURI();
callback.onResourceFound(url.toURI());
}
return new BufferedInputStream(url.openStream());
} catch (URISyntaxException | IOException e) {
return null;
}
}
@Override
public InputStream fetchResource(String resourceName) {
return fetchResource(resourceName, null);
}
@Override
public URI getUriCallBackParam() {
return callbackParam;
}
}

@ -0,0 +1,29 @@
/*
* Copyright 2013 (c) MuleSoft, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*/
package org.xbib.raml.api.model;
import java.net.URI;
/**
* Created. There, you have it.
*/
public class PermissiveURI {
public static URI create(String s) {
return URI.create(s.replace(" ", "%20"));
}
}

@ -0,0 +1,23 @@
/*
* Copyright 2013 (c) MuleSoft, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*/
package org.xbib.raml.api.model.common;
public interface ValidationResult {
String getMessage();
String getPath();
}

@ -0,0 +1,44 @@
/*
* Copyright 2013 (c) MuleSoft, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*/
package org.xbib.raml.api.model.v10;
public enum RamlFragment {
DocumentationItem,
DataType,
NamedExample,
ResourceType,
Trait,
AnnotationTypeDeclaration,
Library,
Overlay,
Extension,
SecurityScheme,
Default;
public static RamlFragment byName(String name) {
if (name.isBlank()) {
return RamlFragment.Default;
} else {
try {
return RamlFragment.valueOf(name);
} catch (IllegalArgumentException iae) {
return null;
}
}
}
}

@ -0,0 +1,96 @@
/*
* Copyright 2013 (c) MuleSoft, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*/
package org.xbib.raml.api.model.v10.api;
import java.util.List;
import org.xbib.raml.api.model.v10.bodies.MimeType;
import org.xbib.raml.api.model.v10.datamodel.TypeDeclaration;
import org.xbib.raml.api.model.v10.resources.Resource;
import org.xbib.raml.api.model.v10.security.SecuritySchemeRef;
import org.xbib.raml.api.model.v10.system.types.AnnotableStringType;
import org.xbib.raml.api.model.v10.system.types.FullUriTemplateString;
import org.xbib.raml.api.model.v10.system.types.MarkdownString;
public interface Api extends LibraryBase {
/**
* Short plain-text label for the API
**/
AnnotableStringType title();
/**
* Longer description for the API. May be formatted using markdown.
**/
MarkdownString description();
/**
* The version of the API, e.g. 'v1'
**/
AnnotableStringType version();
/**
* A URI that's to be used as the base of all the resources' URIs. Often used as the base of the URL of each resource, containing the location of the API. Can be a template URI.
**/
FullUriTemplateString baseUri();
/**
* Named parameters used in the baseUri (template)
**/
List<TypeDeclaration> baseUriParameters();
/**
* The protocols supported by the API
**/
List<String> protocols();
/**
* The default media type to use for request and response bodies (payloads), e.g. "application&#47;json"
**/
List<MimeType> mediaType();
/**
* The security schemes that apply to every resource and method in the API
**/
List<SecuritySchemeRef> securedBy();
/**
* The resources of the API, identified as relative URIs that begin with a slash (&#47;). Every property whose key begins with a slash (&#47;), and is either at the root of the API definition or is the child property of a resource property, is a resource property, e.g.: &#47;users, &#47;{groupId}, etc
**/
List<Resource> resources();
/**
* Additional overall documentation for the API
**/
List<DocumentationItem> documentation();
/**
* Returns RAML version. "RAML10" string is returned for RAML 1.0. "RAML08" string is returned for RAML 0.8.
**/
// --def-system-mod--
String ramlVersion();
}

@ -0,0 +1,35 @@
/*
* Copyright 2013 (c) MuleSoft, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*/
package org.xbib.raml.api.model.v10.api;
import org.xbib.raml.api.model.v10.common.Annotable;
import org.xbib.raml.api.model.v10.system.types.AnnotableStringType;
import org.xbib.raml.api.model.v10.system.types.MarkdownString;
public interface DocumentationItem extends Annotable {
/**
* Title of documentation section
**/
AnnotableStringType title();
/**
* Content of documentation section
**/
MarkdownString content();
}

@ -0,0 +1,34 @@
/*
* Copyright 2013 (c) MuleSoft, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*/
package org.xbib.raml.api.model.v10.api;
import org.xbib.raml.api.model.v10.system.types.AnnotableStringType;
public interface Library extends LibraryBase {
/**
* contains description of why library exist
**/
AnnotableStringType usage();
/**
* Namespace which the library is imported under
**/
String name();
}

@ -0,0 +1,69 @@
/*
* Copyright 2013 (c) MuleSoft, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*/
package org.xbib.raml.api.model.v10.api;
import java.util.List;
import org.xbib.raml.api.model.v10.common.Annotable;
import org.xbib.raml.api.model.v10.datamodel.TypeDeclaration;
import org.xbib.raml.api.model.v10.methods.Trait;
import org.xbib.raml.api.model.v10.resources.ResourceType;
import org.xbib.raml.api.model.v10.security.SecurityScheme;
public interface LibraryBase extends Annotable {
/**
* Alias for the equivalent "types" property, for compatibility with RAML 0.8. Deprecated - API definitions should use the "types" property, as the "schemas" alias for that property name may be removed in a future RAML version. The "types" property allows for XML and JSON schemas.
**/
List<TypeDeclaration> schemas();
/**
* Declarations of (data) types for use within this API
**/
List<TypeDeclaration> types();
/**
* Declarations of traits for use within this API
**/
List<Trait> traits();
/**
* Declarations of resource types for use within this API
**/
List<ResourceType> resourceTypes();
/**
* Declarations of annotation types for use by annotations
**/
List<TypeDeclaration> annotationTypes();
/**
* Declarations of security schemes for use within this API.
**/
List<SecurityScheme> securitySchemes();
/***
* Importing external libraries that can be used within the API.
**/
List<Library> uses();
}

@ -0,0 +1,34 @@
/*
* Copyright 2013 (c) MuleSoft, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*/
package org.xbib.raml.api.model.v10.api;
import org.xbib.raml.api.model.v10.common.Annotable;
public interface UsesDeclaration extends Annotable {
/**
* Name prefix (without dot) used to refer imported declarations
**/
String key();
/**
* Content of the schema
**/
String value();
}

@ -0,0 +1,24 @@
/*
* Copyright 2013 (c) MuleSoft, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*/
package org.xbib.raml.api.model.v10.bodies;
import org.xbib.raml.api.model.v10.system.types.StringType;
public interface MimeType extends StringType {
}

@ -0,0 +1,51 @@
/*
* Copyright 2013 (c) MuleSoft, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*/
package org.xbib.raml.api.model.v10.bodies;
import java.util.List;
import org.xbib.raml.api.model.v10.common.Annotable;
import org.xbib.raml.api.model.v10.datamodel.TypeDeclaration;
import org.xbib.raml.api.model.v10.system.types.MarkdownString;
import org.xbib.raml.api.model.v10.system.types.StatusCodeString;
public interface Response extends Annotable {
/**
* Responses MUST be a map of one or more HTTP status codes, where each status code itself is a map that describes that status code.
**/
StatusCodeString code();
/**
* Detailed information about any response headers returned by this method
**/
List<TypeDeclaration> headers();
/**
* The body of the response: a body declaration
**/
List<TypeDeclaration> body();
/**
* A longer, human-friendly description of the response
**/
// --def-system-mod--
MarkdownString description();
}

@ -0,0 +1,29 @@
/*
* Copyright 2013 (c) MuleSoft, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*/
package org.xbib.raml.api.model.v10.common;
import java.util.List;
import org.xbib.raml.api.model.v10.declarations.AnnotationRef;
public interface Annotable {
/**
* Most of RAML model elements may have attached annotations describing additional meta data about this element
**/
List<AnnotationRef> annotations();
}

@ -0,0 +1,22 @@
/*
* Copyright 2013 (c) MuleSoft, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*/
package org.xbib.raml.api.model.v10.datamodel;
public interface AnyTypeDeclaration extends TypeDeclaration {
}

@ -0,0 +1,44 @@
/*
* Copyright 2013 (c) MuleSoft, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*/
package org.xbib.raml.api.model.v10.datamodel;
public interface ArrayTypeDeclaration extends TypeDeclaration {
/**
* Should items in array be unique
**/
Boolean uniqueItems();
/**
* Array component type.
**/
TypeDeclaration items();
/**
* Minimum amount of items in array
**/
Integer minItems();
/**
* Maximum amount of items in array
**/
Integer maxItems();
}

@ -0,0 +1,24 @@
/*
* Copyright 2013 (c) MuleSoft, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*/
package org.xbib.raml.api.model.v10.datamodel;
import java.util.List;
public interface BooleanTypeDeclaration extends TypeDeclaration {
List<Boolean> enumValues();
}

@ -0,0 +1,22 @@
/*
* Copyright 2013 (c) MuleSoft, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*/
package org.xbib.raml.api.model.v10.datamodel;
public interface DateTimeOnlyTypeDeclaration extends TypeDeclaration {
}

@ -0,0 +1,26 @@
/*
* Copyright 2013 (c) MuleSoft, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*/
package org.xbib.raml.api.model.v10.datamodel;
public interface DateTimeTypeDeclaration extends TypeDeclaration {
/**
* Format used for this date time rfc3339 or rfc2616
**/
String format();
}

@ -0,0 +1,22 @@
/*
* Copyright 2013 (c) MuleSoft, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*/
package org.xbib.raml.api.model.v10.datamodel;
public interface DateTypeDeclaration extends TypeDeclaration {
}

@ -0,0 +1,41 @@
/*
* Copyright 2013 (c) MuleSoft, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*/
package org.xbib.raml.api.model.v10.datamodel;
import org.xbib.raml.api.model.v10.common.Annotable;
public interface ExampleSpec extends Annotable {
/**
* String representation of example
**/
// --def-system-mod--
String value();
/**
* Example identifier, if specified
**/
String name();
/**
* Returns object representation of example, if possible
**/
TypeInstance structuredValue();
}

@ -0,0 +1,36 @@
/*
* Copyright 2013 (c) MuleSoft, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*/
package org.xbib.raml.api.model.v10.datamodel;
public interface ExternalTypeDeclaration extends TypeDeclaration {
/**
* Returns schema/type content for the cases when schema is inlined
**/
String schemaContent();
/**
* Returns internal fragment name when it is used
**/
String internalFragment();
/**
* Returns the schema path
**/
String schemaPath();
}

@ -0,0 +1,29 @@
/*
* Copyright 2013 (c) MuleSoft, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*/
package org.xbib.raml.api.model.v10.datamodel;
import java.util.List;
public interface FileTypeDeclaration extends TypeDeclaration {
Number minLength();
Number maxLength();
List<String> fileTypes();
}

@ -0,0 +1,22 @@
/*
* Copyright 2013 (c) MuleSoft, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*/
package org.xbib.raml.api.model.v10.datamodel;
public interface IntegerTypeDeclaration extends NumberTypeDeclaration {
}

@ -0,0 +1,20 @@
/*
* Copyright 2013 (c) MuleSoft, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*/
package org.xbib.raml.api.model.v10.datamodel;
public interface JSONTypeDeclaration extends ExternalTypeDeclaration {
}

@ -0,0 +1,22 @@
/*
* Copyright 2013 (c) MuleSoft, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*/
package org.xbib.raml.api.model.v10.datamodel;
public interface NullTypeDeclaration extends TypeDeclaration {
}

@ -0,0 +1,52 @@
/*
* Copyright 2013 (c) MuleSoft, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*/
package org.xbib.raml.api.model.v10.datamodel;
import java.util.List;
public interface NumberTypeDeclaration extends TypeDeclaration {
/**
* (Optional, applicable only for parameters of type number or integer) The minimum attribute specifies the parameter's minimum value.
**/
Double minimum();
/**
* (Optional, applicable only for parameters of type number or integer) The maximum attribute specifies the parameter's maximum value.
**/
Double maximum();
/**
* (Optional, applicable only for parameters of type string) The enum attribute provides an enumeration of the parameter's valid values. This MUST be an array. If the enum attribute is defined, API clients and servers MUST verify that a parameter's value matches a value in the enum array. If there is no matching value, the clients and servers MUST treat this as an error.
**/
List<Number> enumValues();
/**
* Value format
**/
String format();
/**
* A numeric instance is valid against "multipleOf" if the result of the division of the instance by this keyword's value is an integer.
**/
Double multipleOf();
}

@ -0,0 +1,53 @@
/*
* Copyright 2013 (c) MuleSoft, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*/
package org.xbib.raml.api.model.v10.datamodel;
import java.util.List;
public interface ObjectTypeDeclaration extends TypeDeclaration {
/**
* The properties that instances of this type may or must have.
**/
List<TypeDeclaration> properties();
/**
* The minimum number of properties allowed for instances of this type.
**/
Integer minProperties();
/**
* The maximum number of properties allowed for instances of this type.
**/
Integer maxProperties();
Boolean additionalProperties();
/**
* Type property name to be used as discriminator, or boolean
**/
String discriminator();
/**
* The value of discriminator for the type.
**/
String discriminatorValue();
}

@ -0,0 +1,46 @@
/*
* Copyright 2013 (c) MuleSoft, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*/
package org.xbib.raml.api.model.v10.datamodel;
import java.util.List;
public interface StringTypeDeclaration extends TypeDeclaration {
/**
* Regular expression that this string should path
**/
String pattern();
/**
* Minimum length of the string
**/
Integer minLength();
/**
* Maximum length of the string
**/
Integer maxLength();
/**
* (Optional, applicable only for parameters of type string) The enum attribute provides an enumeration of the parameter's valid values. This MUST be an array. If the enum attribute is defined, API clients and servers MUST verify that a parameter's value matches a value in the enum array. If there is no matching value, the clients and servers MUST treat this as an error.
**/
List<String> enumValues();
}

@ -0,0 +1,22 @@
/*
* Copyright 2013 (c) MuleSoft, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*/
package org.xbib.raml.api.model.v10.datamodel;
public interface TimeOnlyTypeDeclaration extends TypeDeclaration {
}

@ -0,0 +1,115 @@
/*
* Copyright 2013 (c) MuleSoft, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*/
package org.xbib.raml.api.model.v10.datamodel;
import java.util.List;
import org.xbib.raml.api.model.common.ValidationResult;
import org.xbib.raml.api.model.v10.common.Annotable;
import org.xbib.raml.api.model.v10.declarations.AnnotationTarget;
import org.xbib.raml.api.model.v10.system.types.AnnotableStringType;
import org.xbib.raml.api.model.v10.system.types.MarkdownString;
public interface TypeDeclaration extends Annotable {
/**
* Name of the parameter
**/
String name();
/**
* The displayName attribute specifies the type display name. It is a friendly name used only for display or documentation purposes. If displayName is not specified, it defaults to the element's key (the name of the property itself).
**/
AnnotableStringType displayName();
/**
* A base type which the current type extends, or more generally a type expression.
**/
String type();
/**
* The list of inherited types
*/
List<TypeDeclaration> parentTypes();
/**
* Provides default value for a property
**/
String defaultValue();
/**
* An example of this type instance represented as string or yaml map&#47;sequence. This can be used, e.g., by documentation generators to generate sample values for an object of this type. Cannot be present if the examples property is present.
**/
ExampleSpec example();
/**
* An example of this type instance represented as string. This can be used, e.g., by documentation generators to generate sample values for an object of this type. Cannot be present if the example property is present.
**/
List<ExampleSpec> examples();
/**
* Sets if property is optional or not
**/
Boolean required();
/**
* A longer, human-friendly description of the type
**/
MarkdownString description();
/**
* Restrictions on where annotations of this type can be applied. If this property is specified, annotations of this type may only be applied on a property corresponding to one of the target names specified as the value of this property.
**/
List<AnnotationTarget> allowedTargets();
/**
* Validates <tt>payload</tt> against the type/schema defined
*
* @param payload the payload to be validated
* @return the list of errors if any or an empty list if validation succeeded
*/
List<ValidationResult> validate(String payload);
/**
* Gets the list of user-defined facets
*/
List<TypeDeclaration> facets();
XMLFacetInfo xml();
/**
* Returns a XML Schema representation of the type.
*/
String toXmlSchema();
/**
* Returns a JSON Schema representation of the type.
*/
String toJsonSchema();
}

@ -0,0 +1,40 @@
/*
* Copyright 2013 (c) MuleSoft, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*/
package org.xbib.raml.api.model.v10.datamodel;
import java.util.List;
public interface TypeInstance {
/**
* Array of instance properties
**/
List<TypeInstanceProperty> properties();
/**
* Whether the type is scalar
**/
Boolean isScalar();
/**
* For instances of scalar types returns scalar value
**/
Object value();
}

@ -0,0 +1,46 @@
/*
* Copyright 2013 (c) MuleSoft, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*/
package org.xbib.raml.api.model.v10.datamodel;
import java.util.List;
public interface TypeInstanceProperty {
/**
* Property name
**/
String name();
/**
* Property value
**/
TypeInstance value();
/**
* Array of values if property value is array
**/
List<TypeInstance> values();
/**
* Whether property has array as value
**/
Boolean isArray();
}

@ -0,0 +1,22 @@
/*
* Copyright 2013 (c) MuleSoft, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*/
package org.xbib.raml.api.model.v10.datamodel;
import java.util.List;
public interface UnionTypeDeclaration extends TypeDeclaration {
List<TypeDeclaration> of();
}

@ -0,0 +1,52 @@
/*
* Copyright 2013 (c) MuleSoft, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*/
package org.xbib.raml.api.model.v10.datamodel;
import org.xbib.raml.api.model.v10.common.Annotable;
public interface XMLFacetInfo extends Annotable {
/**
* If attribute is set to true, a type instance should be serialized as an XML attribute. It can only be true for scalar types.
**/
Boolean attribute();
/**
* If wrapped is set to true, a type instance should be wrapped in its own XML element. It can not be true for scalar types and it can not be true at the same moment when attribute is true.
**/
Boolean wrapped();
/**
* Allows to override the name of the XML element or XML attribute in it's XML representation.
**/
String name();
/**
* Allows to configure the name of the XML namespace.
**/
String namespace();
/**
* Allows to configure the prefix which will be used during serialization to XML.
**/
String prefix();
}

@ -0,0 +1,20 @@
/*
* Copyright 2013 (c) MuleSoft, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*/
package org.xbib.raml.api.model.v10.datamodel;
public interface XMLTypeDeclaration extends ExternalTypeDeclaration {
}

@ -0,0 +1,29 @@
/*
* Copyright 2013 (c) MuleSoft, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*/
package org.xbib.raml.api.model.v10.declarations;
import org.xbib.raml.api.model.v10.datamodel.TypeDeclaration;
import org.xbib.raml.api.model.v10.system.types.Reference;
public interface AnnotationRef extends Reference {
/**
* Returns referenced annotation
**/
TypeDeclaration annotation();
}

@ -0,0 +1,36 @@
/*
* Copyright 2013 (c) MuleSoft, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*/
package org.xbib.raml.api.model.v10.declarations;
public enum AnnotationTarget {
API,
DocumentationItem,
Resource,
Method,
Response,
RequestBody,
ResponseBody,
TypeDeclaration,
Example,
ResourceType,
Trait,
SecurityScheme,
SecuritySchemeSettings,
AnnotationType,
Library,
Overlay,
Extension
}

@ -0,0 +1,34 @@
/*
* Copyright 2013 (c) MuleSoft, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*/
package org.xbib.raml.api.model.v10.methods;
import org.xbib.raml.api.model.v10.resources.Resource;
public interface Method extends MethodBase {
/**
* Method that can be called
**/
String method();
/**
* Parent resource of the Method
*
* @return the parent resource or null if there is none
*/
Resource resource();
}

@ -0,0 +1,56 @@
/*
* Copyright 2013 (c) MuleSoft, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*/
package org.xbib.raml.api.model.v10.methods;
import java.util.List;
import org.xbib.raml.api.model.v10.datamodel.TypeDeclaration;
import org.xbib.raml.api.model.v10.security.SecuritySchemeRef;
import org.xbib.raml.api.model.v10.system.types.AnnotableStringType;
import org.xbib.raml.api.model.v10.system.types.MarkdownString;
public interface MethodBase extends Operation {
/**
* Some method verbs expect the resource to be sent as a request body. For example, to create a resource, the request must include the details of the resource to create. Resources CAN have alternate representations. For example, an API might support both JSON and XML representations. A method's body is defined in the body property as a hashmap, in which the key MUST be a valid media type.
**/
List<TypeDeclaration> body();
/**
* A method can override the protocols specified in the resource or at the API root, by employing this property.
**/
List<String> protocols();
/**
* Instantiation of applyed traits
**/
List<TraitRef> is();
/**
* securityScheme may also be applied to a resource by using the securedBy key, which is equivalent to applying the securityScheme to all methods that may be declared, explicitly or implicitly, by defining the resourceTypes or traits property for that resource. To indicate that the method may be called without applying any securityScheme, the method may be annotated with the null securityScheme.
**/
List<SecuritySchemeRef> securedBy();
MarkdownString description();
AnnotableStringType displayName();
}

@ -0,0 +1,49 @@
/*
* Copyright 2013 (c) MuleSoft, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*/
package org.xbib.raml.api.model.v10.methods;
import java.util.List;
import org.xbib.raml.api.model.v10.bodies.Response;
import org.xbib.raml.api.model.v10.common.Annotable;
import org.xbib.raml.api.model.v10.datamodel.TypeDeclaration;
public interface Operation extends Annotable {
/**
* An APIs resources MAY be filtered (to return a subset of results) or altered (such as transforming a response body from JSON to XML format) by the use of query strings. If the resource or its method supports a query string, the query string MUST be defined by the queryParameters property
**/
List<TypeDeclaration> queryParameters();
/**
* Headers that allowed at this position
**/
List<TypeDeclaration> headers();
/**
* Specifies the query string needed by this method. Mutually exclusive with queryParameters.
**/
TypeDeclaration queryString();
/**
* Information about the expected responses to a request
**/
List<Response> responses();
}

@ -0,0 +1,37 @@
/*
* Copyright 2013 (c) MuleSoft, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*/
package org.xbib.raml.api.model.v10.methods;
import org.xbib.raml.api.model.v10.system.types.AnnotableStringType;
public interface Trait {
// MarkdownString description();
//
// AnnotableSimpleType<String> displayName();
/**
* Name of the trait
**/
String name();
/**
* Instructions on how and when the trait should be used.
**/
AnnotableStringType usage();
}

@ -0,0 +1,28 @@
/*
* Copyright 2013 (c) MuleSoft, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*/
package org.xbib.raml.api.model.v10.methods;
import org.xbib.raml.api.model.v10.system.types.Reference;
public interface TraitRef extends Reference {
/**
* Returns referenced trait
**/
Trait trait();
}

@ -0,0 +1,42 @@
/*
* Copyright 2013 (c) MuleSoft, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*/
package org.xbib.raml.api.model.v10.parameters;
import java.util.List;
import org.xbib.raml.api.model.v10.datamodel.TypeDeclaration;
import org.xbib.raml.api.model.v10.system.types.ContentType;
public interface FileTypeDeclaration extends TypeDeclaration {
/**
* It should also include a new property: fileTypes, which should be a list of valid content-type strings for the file. The file type *&#47;* should be a valid value.
**/
List<ContentType> fileTypes();
/**
* The minLength attribute specifies the parameter value's minimum number of bytes.
**/
Long minLength();
/**
* The maxLength attribute specifies the parameter value's maximum number of bytes.
**/
Long maxLength();
}

@ -0,0 +1,50 @@
/*
* Copyright 2013 (c) MuleSoft, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*/
package org.xbib.raml.api.model.v10.resources;
import java.util.List;
import org.xbib.raml.api.model.v10.system.types.AnnotableStringType;
import org.xbib.raml.api.model.v10.system.types.RelativeUriString;
public interface Resource extends ResourceBase {
/**
* Relative URL of this resource from the parent resource
**/
RelativeUriString relativeUri();
/**
* The displayName attribute specifies the resource display name. It is a friendly name used only for display or documentation purposes. If displayName is not specified, it defaults to the element's key (the name of the property itself).
**/
AnnotableStringType displayName();
/**
* A nested resource is identified as any property whose name begins with a slash ("&#47;") and is therefore treated as a relative URI.
**/
List<Resource> resources();
/*
* helper methods (non-autogenerated)
*/
String resourcePath();
Resource parentResource();
}

@ -0,0 +1,62 @@
/*
* Copyright 2013 (c) MuleSoft, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*/
package org.xbib.raml.api.model.v10.resources;
import java.util.List;
import org.xbib.raml.api.model.v10.common.Annotable;
import org.xbib.raml.api.model.v10.datamodel.TypeDeclaration;
import org.xbib.raml.api.model.v10.methods.Method;
import org.xbib.raml.api.model.v10.methods.TraitRef;
import org.xbib.raml.api.model.v10.security.SecuritySchemeRef;
import org.xbib.raml.api.model.v10.system.types.MarkdownString;
public interface ResourceBase extends Annotable {
/**
* Methods that are part of this resource type definition
**/
List<Method> methods();
/**
* A list of the traits to apply to all methods declared (implicitly or explicitly) for this resource. Individual methods may override this declaration
**/
List<TraitRef> is();
/**
* The resource type which this resource inherits.
**/
ResourceTypeRef type();
// --def-system-mod--
MarkdownString description();
/**
* The security schemes that apply to all methods declared (implicitly or explicitly) for this resource.
**/
List<SecuritySchemeRef> securedBy();
/**
* Detailed information about any URI parameters of this resource
**/
List<TypeDeclaration> uriParameters();
}

@ -0,0 +1,42 @@
/*
* Copyright 2013 (c) MuleSoft, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*/
package org.xbib.raml.api.model.v10.resources;
import org.xbib.raml.api.model.v10.system.types.AnnotableStringType;
public interface ResourceType {
/**
* The displayName attribute specifies the resource type display name. It is a friendly name used only for display or documentation purposes. If displayName is not specified, it defaults to the element's key (the name of the property itself).
**/
// AnnotableSimpleType<String> displayName();
/**
* Name of the resource type
**/
String name();
/**
* Instructions on how and when the resource type should be used.
**/
AnnotableStringType usage();
// MarkdownString description();
}

@ -0,0 +1,28 @@
/*
* Copyright 2013 (c) MuleSoft, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*/
package org.xbib.raml.api.model.v10.resources;
import org.xbib.raml.api.model.v10.system.types.Reference;
public interface ResourceTypeRef extends Reference {
/**
* Returns referenced resource type
**/
ResourceType resourceType();
}

@ -0,0 +1,60 @@
/*
* Copyright 2013 (c) MuleSoft, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*/
package org.xbib.raml.api.model.v10.security;
import org.xbib.raml.api.model.v10.common.Annotable;
import org.xbib.raml.api.model.v10.system.types.AnnotableStringType;
import org.xbib.raml.api.model.v10.system.types.MarkdownString;
public interface SecurityScheme extends Annotable {
/**
* Name of the security scheme
**/
String name();
/**
* The securitySchemes property MUST be used to specify an API's security mechanisms, including the required settings and the authentication methods that the API supports. one authentication method is allowed if the API supports them.
**/
String type();
/**
* The description MAY be used to describe a securityScheme.
**/
MarkdownString description();
/**
* A description of the request components related to Security that are determined by the scheme: the headers, query parameters or responses. As a best practice, even for standard security schemes, API designers SHOULD describe these properties of security schemes. Including the security scheme description completes an API documentation.
**/
SecuritySchemePart describedBy();
/**
* The displayName attribute specifies the security scheme display name. It is a friendly name used only for display or documentation purposes. If displayName is not specified, it defaults to the element's key (the name of the property itself).
**/
AnnotableStringType displayName();
/**
* The settings attribute MAY be used to provide security scheme-specific information. The required attributes vary depending on the type of security scheme is being declared. It describes the minimum set of properties which any processing application MUST provide and validate if it chooses to implement the security scheme. Processing applications MAY choose to recognize other properties for things such as token lifetime, preferred cryptographic algorithms, and more.
**/
SecuritySchemeSettings settings();
}

@ -0,0 +1,24 @@
/*
* Copyright 2013 (c) MuleSoft, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*/
package org.xbib.raml.api.model.v10.security;
import org.xbib.raml.api.model.v10.methods.Operation;
public interface SecuritySchemePart extends Operation {
}

@ -0,0 +1,28 @@
/*
* Copyright 2013 (c) MuleSoft, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*/
package org.xbib.raml.api.model.v10.security;
import org.xbib.raml.api.model.v10.system.types.Reference;
public interface SecuritySchemeRef extends Reference {
/**
* Returns AST node of security scheme, this reference refers to, or null.
**/
SecurityScheme securityScheme();
}

@ -0,0 +1,76 @@
/*
* Copyright 2013 (c) MuleSoft, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*/
package org.xbib.raml.api.model.v10.security;
import java.util.List;
import org.xbib.raml.api.model.v10.common.Annotable;
import org.xbib.raml.api.model.v10.system.types.FixedUriString;
public interface SecuritySchemeSettings extends Annotable {
/**
* The URI of the Temporary Credential Request endpoint as defined in RFC5849 Section 2.1
* (OAuth 1)
**/
FixedUriString requestTokenUri();
/**
* The URI of the Resource Owner Authorization endpoint as defined in RFC5849 Section 2.2
* (OAuth 1)
* <p>
* The URI of the Authorization Endpoint as defined in RFC6749 Section 3.1. Required forby authorization_code and implicit grant types.
* (OAuth 2)
**/
FixedUriString authorizationUri();
/**
* The URI of the Token Request endpoint as defined in RFC5849 Section 2.3
* (OAuth 1)
**/
FixedUriString tokenCredentialsUri();
/**
* List of the signature methods used by the server. Available methods: HMAC-SHA1, RSA-SHA1, PLAINTEXT
* (OAuth 1)
**/
List<String> signatures();
/**
* The URI of the Token Endpoint as defined in RFC6749 Section 3.2. Not required forby implicit grant type.
* (OAuth 2)
**/
FixedUriString accessTokenUri();
/**
* A list of the Authorization grants supported by the API as defined in RFC6749 Sections 4.1, 4.2, 4.3 and 4.4, can be any of: authorization_code, password, client_credentials, implicit, or refresh_token.
* (OAuth 2)
**/
List<String> authorizationGrants();
/**
* A list of scopes supported by the security scheme as defined in RFC6749 Section 3.3
* (OAuth 2)
**/
List<String> scopes();
}

@ -0,0 +1,28 @@
/*
* Copyright 2013 (c) MuleSoft, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*/
package org.xbib.raml.api.model.v10.system.types;
import org.xbib.raml.api.model.v10.common.Annotable;
public interface AnnotableSimpleType<T> extends Annotable {
/**
* @return String representation of the node value
**/
T value();
}

@ -0,0 +1,22 @@
/*
* Copyright 2013 (c) MuleSoft, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*/
package org.xbib.raml.api.model.v10.system.types;
public interface AnnotableStringType extends AnnotableSimpleType<String> {
@Override
String value();
}

@ -0,0 +1,22 @@
/*
* Copyright 2013 (c) MuleSoft, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*/
package org.xbib.raml.api.model.v10.system.types;
public interface AnyType extends ValueType {
}

@ -0,0 +1,26 @@
/*
* Copyright 2013 (c) MuleSoft, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*/
package org.xbib.raml.api.model.v10.system.types;
public interface BooleanType {
/**
* @return Boolean representation of the node value
**/
Boolean value();
}

@ -0,0 +1,22 @@
/*
* Copyright 2013 (c) MuleSoft, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*/
package org.xbib.raml.api.model.v10.system.types;
public interface ContentType extends StringType {
}

@ -0,0 +1,22 @@
/*
* Copyright 2013 (c) MuleSoft, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*/
package org.xbib.raml.api.model.v10.system.types;
public interface FixedUriString extends AnnotableStringType {
}

@ -0,0 +1,22 @@
/*
* Copyright 2013 (c) MuleSoft, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*/
package org.xbib.raml.api.model.v10.system.types;
public interface FullUriTemplateString extends UriTemplate, AnnotableStringType {
}

@ -0,0 +1,22 @@
/*
* Copyright 2013 (c) MuleSoft, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*/
package org.xbib.raml.api.model.v10.system.types;
public interface MarkdownString extends AnnotableStringType {
}

@ -0,0 +1,26 @@
/*
* Copyright 2013 (c) MuleSoft, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*/
package org.xbib.raml.api.model.v10.system.types;
public interface NumberType {
/**
* @return Number representation of the node value
**/
Double value();
}

@ -0,0 +1,34 @@
/*
* Copyright 2013 (c) MuleSoft, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*/
package org.xbib.raml.api.model.v10.system.types;
import org.xbib.raml.api.model.v10.datamodel.TypeInstance;
public interface Reference {
/**
* Returns a structured object if the reference point to one.
**/
TypeInstance structuredValue();
/**
* Returns name of referenced object
**/
String name();
}

@ -0,0 +1,22 @@
/*
* Copyright 2013 (c) MuleSoft, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*/
package org.xbib.raml.api.model.v10.system.types;
public interface RelativeUriString extends UriTemplate, StringType {
}

@ -0,0 +1,22 @@
/*
* Copyright 2013 (c) MuleSoft, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*/
package org.xbib.raml.api.model.v10.system.types;
public interface SchemaString extends StringType {
}

@ -0,0 +1,22 @@
/*
* Copyright 2013 (c) MuleSoft, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*/
package org.xbib.raml.api.model.v10.system.types;
public interface StatusCodeString extends StringType {
}

@ -0,0 +1,26 @@
/*
* Copyright 2013 (c) MuleSoft, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*/
package org.xbib.raml.api.model.v10.system.types;
public interface StringType {
/**
* @return String representation of the node value
**/
String value();
}

@ -0,0 +1,22 @@
/*
* Copyright 2013 (c) MuleSoft, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*/
package org.xbib.raml.api.model.v10.system.types;
public interface UriTemplate {
}

@ -0,0 +1,26 @@
/*
* Copyright 2013 (c) MuleSoft, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*/
package org.xbib.raml.api.model.v10.system.types;
public interface ValueType {
/**
* @return Java representation of the node value
**/
Object value();
}

@ -0,0 +1,125 @@
/*
* Copyright 2013 (c) MuleSoft, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*/
package org.xbib.raml.internal.impl;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
import java.io.StringReader;
import org.xbib.raml.api.loader.DefaultResourceLoader;
import org.xbib.raml.api.loader.ResourceLoader;
import org.xbib.raml.api.loader.ResourceLoaderFactories;
import org.xbib.raml.internal.impl.commons.RamlHeader;
import org.xbib.raml.internal.impl.v10.Raml10Builder;
import org.xbib.raml.internal.utils.IOUtils;
import org.xbib.raml.internal.utils.StreamUtils;
import org.xbib.raml.yagi.framework.grammar.rule.ErrorNodeFactory;
import org.xbib.raml.yagi.framework.nodes.Node;
/**
* RamlBuilder create a Node representation of your raml.
*
* @see Node
*/
public class RamlBuilder {
public static int FIRST_PHASE = 1;
public static int GRAMMAR_PHASE = 4;
public static int LIBRARY_LINK_PHASE = 5;
public static int ALL_PHASES = Integer.MAX_VALUE;
private final int maxPhaseNumber;
private String actualPath = null;
public RamlBuilder() {
maxPhaseNumber = ALL_PHASES;
}
public RamlBuilder(int maxPhaseNumber) {
this.maxPhaseNumber = maxPhaseNumber;
}
public Node build(File ramlFile) {
return build(ramlFile, ResourceLoaderFactories.defaultResourceLoaderFactory().createResourceLoader(ramlFile.getAbsoluteFile().getParent()));
}
public Node build(File ramlFile, ResourceLoader resourceLoader) {
this.actualPath = ramlFile.getPath();
try (InputStream inputStream = new FileInputStream(ramlFile)) {
return build(StreamUtils.reader(inputStream), resourceLoader, ramlFile.getName());
} catch (IOException ioe) {
return ErrorNodeFactory.createInvalidInput(ioe);
}
}
public Node build(String content) {
return build(content, "");
}
public Node build(String content, String resourceLocation) {
return build(content, new DefaultResourceLoader(), resourceLocation);
}
public Node build(String content, ResourceLoader resourceLoader, String resourceLocation) {
return build(new StringReader(content), resourceLoader, resourceLocation);
}
public Node build(Reader content, ResourceLoader resourceLoader, String resourceLocation) {
try {
resourceLoader = addRootRamlResourceLoaders(resourceLoader, resourceLocation);
final String stringContent = IOUtils.toString(content);
// In order to be consistent between different OS, we normalize the resource location
resourceLocation = normalizeResourceLocation(resourceLocation);
RamlHeader ramlHeader = RamlHeader.parse(stringContent);
Node result = new Raml10Builder().build(stringContent, ramlHeader.getFragment(), resourceLoader, resourceLocation, maxPhaseNumber);
return result;
} catch (IOException ioe) {
return ErrorNodeFactory.createInvalidInput(ioe);
} catch (RamlHeader.InvalidHeaderVersionException e) {
return ErrorNodeFactory.createUnsupportedVersion(e.getMessage());
} catch (RamlHeader.InvalidHeaderFragmentException e) {
return ErrorNodeFactory.createInvalidFragmentName(e.getMessage());
} catch (RamlHeader.MissingHeaderException e) {
return ErrorNodeFactory.createEmptyDocument();
} catch (RamlHeader.InvalidHeaderException e) {
return ErrorNodeFactory.createInvalidHeader(e.getMessage());
} finally {
IOUtils.closeQuietly(content);
}
}
private ResourceLoader addRootRamlResourceLoaders(ResourceLoader resourceLoader, String resourceLocation) {
return resourceLoader;
}
private String normalizeResourceLocation(String resourceLocation) {
return resourceLocation.replace("\\", "/");
}
public String getActualPath() {
return actualPath;
}
}

@ -0,0 +1,425 @@
/*
* Copyright 2013 (c) MuleSoft, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*/
package org.xbib.raml.internal.impl;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import org.xbib.raml.api.loader.DefaultResourceLoader;
import org.xbib.raml.api.loader.ResourceLoader;
import org.xbib.raml.internal.impl.commons.RamlHeader;
import org.xbib.raml.yagi.framework.grammar.rule.Rule;
import org.xbib.raml.yagi.framework.nodes.EmptyErrorNode;
import org.xbib.raml.yagi.framework.nodes.ErrorNode;
import org.xbib.raml.yagi.framework.nodes.KeyValueNode;
import org.xbib.raml.yagi.framework.nodes.Node;
import org.xbib.raml.yagi.framework.nodes.ObjectNode;
import org.xbib.raml.yagi.framework.nodes.StringNode;
import org.xbib.raml.yagi.framework.suggester.DefaultSuggestion;
import org.xbib.raml.yagi.framework.suggester.ParsingContext;
import org.xbib.raml.yagi.framework.suggester.ParsingContextType;
import org.xbib.raml.yagi.framework.suggester.Suggestion;
import org.xbib.raml.yagi.framework.suggester.Suggestions;
public class RamlSuggester {
private final ResourceLoader resourceLoader;
public RamlSuggester(ResourceLoader resourceLoader) {
this.resourceLoader = resourceLoader;
}
public RamlSuggester() {
this(new DefaultResourceLoader());
}
/**
* Returns the suggestions for the specified document at the given position.
* In most common cases the offset will be the cursor position.
*
* @param document The raml document
* @param offset The offset from the begging of the document
* @return The suggestions
*/
public Suggestions suggestions(String document, int offset) {
final List<Suggestion> result = new ArrayList<>();
final ParsingContext parsingContext = getContext(document, offset);
final int location = parsingContext.getLocation();
final String content = parsingContext.getContent();
final List<Suggestion> suggestions = getSuggestions(parsingContext, document, offset, location);
if (content.isEmpty()) {
result.addAll(suggestions);
} else {
for (Suggestion suggestion : suggestions) {
if (suggestion.getValue().startsWith(content)) {
result.add(suggestion);
}
}
}
Collections.sort(result);
return new Suggestions(result, content, location);
}
private List<Suggestion> getSuggestions(ParsingContext context, String document, int offset, int location) {
switch (context.getContextType()) {
case HEADER:
return getHeaderSuggestions();
case FUNCTION_CALL:
return getFunctionCallSuggestions();
case STRING_TEMPLATE:
return getTemplateParameterSuggestions(document, offset, location);
case LIBRARY_CALL:
case ITEM:
case VALUE:
return getSuggestionsAt(context, document, offset, location);
default:
return getSuggestionByColumn(context, document, offset, location);
}
}
private List<Suggestion> getTemplateParameterSuggestions(String document, int offset, int location) {
final Node rootNode = getRootNode(document, offset, location);
Node node = org.xbib.raml.yagi.framework.util.NodeUtils.searchNodeAt(rootNode, location);
boolean inTrait = false;
while (node != null) {
if (node instanceof KeyValueNode) {
if (((KeyValueNode) node).getKey() instanceof StringNode) {
final String value = ((StringNode) ((KeyValueNode) node).getKey()).getValue();
if (value.equals("traits") || value.equals("resourceTypes")) {
inTrait = value.equals("traits");
break;
}
}
}
node = node.getParent();
}
return inTrait ? defaultTraitParameters() : defaultResourceTypeParameters();
}
private List<Suggestion> defaultTraitParameters() {
final List<Suggestion> suggestions = defaultResourceTypeParameters();
suggestions.add(new DefaultSuggestion("methodName", "The name of the method", ""));
return suggestions;
}
private List<Suggestion> defaultResourceTypeParameters() {
final List<Suggestion> suggestions = new ArrayList<>();
suggestions.add(new DefaultSuggestion("resourcePath", "The resource's full URI relative to the baseUri (if any)", ""));
suggestions.add(new DefaultSuggestion("resourcePathName", "The rightmost path fragment of the resource's relative URI, " +
"omitting any parametrize brackets (\"{\" and \"}\")", ""));
return suggestions;
}
private List<Suggestion> getFunctionCallSuggestions() {
List<Suggestion> suggestions = new ArrayList<>();
/*final Method[] declaredMethods = Inflector.class.getDeclaredMethods();
for (Method declaredMethod : declaredMethods)
{
if (Modifier.isStatic(declaredMethod.getModifiers()) && Modifier.isPublic(declaredMethod.getModifiers()))
{
suggestions.add(new DefaultSuggestion("!" + declaredMethod.getName(), "", declaredMethod.getName()));
}
}*/
return suggestions;
}
private List<Suggestion> getSuggestionsAt(ParsingContext context, String document, int offset, int location) {
final Node root = getRootNode(document, offset, location);
Node node = org.xbib.raml.yagi.framework.util.NodeUtils.searchNodeAt(root, location);
if (node != null) {
// If it is the key of a key value pair
if (node.getParent() instanceof KeyValueNode && node.getParent().getChildren().indexOf(node) == 0) {
node = node.getParent().getParent();
}
// Recreate path with the node at the correct indentation
final List<Node> pathToRoot = createPathToRoot(node);
// Follow the path from the root to the node and apply the rules for auto-completion.
final Rule rootRule = getRuleFor(document);
return rootRule != null ? rootRule.getSuggestions(pathToRoot, context) : Collections.emptyList();
} else {
return Collections.emptyList();
}
}
private Node getRootNode(String document, int offset, int location) {
// We only run the first phase
final RamlBuilder ramlBuilder = new RamlBuilder(RamlBuilder.FIRST_PHASE);
try {
// We try the with the original document
final Node rootNode = ramlBuilder.build(document, resourceLoader, "");
if (rootNode instanceof StringNode) {
// File still doesn't have any mapping and will not generate any suggestions so we'll force the parsing to make it a mapping
final Node rootNode2 = ramlBuilder.build(stripLastChanges(document, offset, location) + "\n\nstub: stub", resourceLoader, ""); // we add an invalid key so as to enforce the creation of
// the root node
if (rootNode2 instanceof ErrorNode) {
// Otherwise let's just try to remove the whole line starting from where we are located
return ramlBuilder.build(removeChangedLine(document, offset, location) + "\n\nstub: stub", resourceLoader, "");
} else {
return rootNode2;
}
} else if (!(rootNode instanceof ErrorNode)) {
return rootNode;
} else if (rootNode instanceof EmptyErrorNode) {
// File is not corrupted but just empty, we should suggest initial keys for the current file
return ramlBuilder.build(document + "\n\nstub: stub", resourceLoader, ""); // we add an invalid key so as to force the creation of the root node
} else { // let's just try to remove the whole line starting from where we are located
return ramlBuilder.build(removeChangedLine(document, offset, location) + "\n\nstub: stub", resourceLoader, "");
}
} catch (final Exception e) {
// We remove some current keywords to see if it parses
return ramlBuilder.build(stripLastChanges(document, offset, location), resourceLoader, "");
}
}
private String removeChangedLine(String document, int offset, int location) {
final String header = document.substring(0, location + 1);
final String footer = getFooter1(document, offset);
return header + footer;
}
private String stripLastChanges(String document, int offset, int location) {
final String header = document.substring(0, location + 1);
final String footer = getFooter(document, offset);
return header + footer;
}
private List<Suggestion> getSuggestionByColumn(ParsingContext context, String document, int offset, int location) {
// // I don't care column number unless is an empty new line
int columnNumber = getColumnNumber(document, offset);
final Node root = getRootNode(document, offset, location);
Node node = org.xbib.raml.yagi.framework.util.NodeUtils.searchNodeAt(root, location);
if (node != null) {
node = getValueNodeAtColumn(columnNumber, node);
// Recreate path with the node at the correct indentation
final List<Node> pathToRoot = createPathToRoot(node);
// Follow the path from the root to the node and apply the rules for auto-completion.
final Rule rootRule = getRuleFor(document);
return rootRule != null ? rootRule.getSuggestions(pathToRoot, context) : Collections.emptyList();
} else {
return Collections.emptyList();
}
}
private int getLineNumber(final String document, final int offset) {
int lineNumber = 0;
for (int currentIndex = 0; currentIndex <= offset; ++currentIndex) {
if (currentIndex - 1 == offset || //
currentIndex >= document.length()) // should never be possible if offset is legal
{
return lineNumber;
}
if (document.charAt(currentIndex) == '\n') {
++lineNumber;
}
}
// should never reach this
return lineNumber;
}
private List<Suggestion> getHeaderSuggestions() {
return Arrays.asList(
new DefaultSuggestion("#%RAML 1.0", "RAML 1.0 root file header", DefaultSuggestion.RAML_1_0_HEADER),
new DefaultSuggestion("#%RAML 1.0 DocumentationItem", "An item in the collection of items that is the value of the root-level documentation property",
"RAML 1.0 Documentation Item fragment"),
new DefaultSuggestion("#%RAML 1.0 DataType", "A data type declaration where the type property may be used", "RAML 1.0 Data Type fragment"),
new DefaultSuggestion("#%RAML 1.0 NamedExample", "A property of the examples property, whose key is a name of an example and whose value describes the example",
"RAML 1.0 Named Example fragment"),
new DefaultSuggestion("#%RAML 1.0 ResourceType", "A single resource type declaration", "RAML 1.0 Resource Type fragment"),
new DefaultSuggestion("#%RAML 1.0 Trait", "A single trait declaration", "RAML 1.0 Trait fragment"),
new DefaultSuggestion("#%RAML 1.0 AnnotationTypeDeclaration", "A single annotation type declaration", "RAML 1.0 Annotation Type Declaration fragment"),
new DefaultSuggestion("#%RAML 1.0 Library", "A RAML library", "RAML 1.0 Library fragment"),
new DefaultSuggestion("#%RAML 1.0 Overlay", "An overlay file", "RAML 1.0 Overlay fragment"),
new DefaultSuggestion("#%RAML 1.0 Extension", "An extension file", "RAML 1.0 Extension fragment"),
new DefaultSuggestion("#%RAML 1.0 SecurityScheme", "A definition of a security scheme", "RAML 1.0 Security Scheme fragment"));
}
private ParsingContext getContext(String document, int offset) {
if (offset == -1 || getLineNumber(document, offset) == 0) {
final String content = offset < 0 || document.isEmpty() ? "" : document.substring(0, offset + 1);
return new ParsingContext(ParsingContextType.HEADER, content, offset);
}
ParsingContext context = null;
int location = offset;
final StringBuilder content = new StringBuilder();
while (location >= 0 && context == null) {
char character = document.charAt(location);
switch (character) {
case ':':
context = new ParsingContext(ParsingContextType.VALUE, revertAndTrim(content), location + 1);
break;
case ',':
case '[':
case '{':
case '-':
context = new ParsingContext(ParsingContextType.ITEM, revertAndTrim(content), location);
break;
case '<':
if (location > 0) {
if (document.charAt(location - 1) == '<') {
location--;
final String contextContent = revertAndTrim(content);
final String[] split = contextContent.split("\\|");
if (split.length > 1) {
context = new ParsingContext(ParsingContextType.FUNCTION_CALL, split[split.length - 1].trim(), location);
} else if (contextContent.endsWith("|")) {
context = new ParsingContext(ParsingContextType.FUNCTION_CALL, "", location);
} else {
context = new ParsingContext(ParsingContextType.STRING_TEMPLATE, contextContent, location);
}
break;
}
}
content.append(character);
break;
case '.':
context = new ParsingContext(ParsingContextType.LIBRARY_CALL, revertAndTrim(content), location);
break;
case '\n':
context = new ParsingContext(ParsingContextType.ANY, revertAndTrim(content), location);
break;
default:
content.append(character);
}
location--;
}
if (context == null) {
context = new ParsingContext(ParsingContextType.ANY, revertAndTrim(content), location);
}
return context;
}
private String revertAndTrim(StringBuilder content) {
return content.reverse().toString().trim();
}
private Node getValueNodeAtColumn(int columnNumber, Node node) {
if (columnNumber == 0) {
return node.getRootNode();
} else {
// Create the path from the selected node to the root.
final List<Node> path = createPathToRoot(node);
// Find the node with the indentation in the path
for (Node element : path) {
if (element instanceof KeyValueNode) {
if (element.getStartPosition().getColumn() < columnNumber) {
// In an object we need that it should be minor for arrays
node = ((KeyValueNode) element).getValue();
}
} else if (element instanceof ObjectNode) {
// In an object we need that it should be equals or minor
if (element.getStartPosition().getColumn() <= columnNumber) {
node = element;
}
}
}
return node;
}
}
private List<Node> createPathToRoot(Node node) {
final List<Node> path = new ArrayList<>();
Node parent = node;
while (parent != null) {
path.add(0, parent);
parent = parent.getParent();
}
return path;
}
private String getFooter(String document, int offset) {
int loc = offset;
char current = document.charAt(loc);
while (loc < document.length() && current != '\n' && current != '}' && current != ']' && current != ',') {
loc++;
if (loc == document.length()) {
break;
}
current = document.charAt(loc);
}
return loc < document.length() ? document.substring(loc) : "";
}
private String getFooter1(String document, int offset) {
return getFooter(document, offset + 1);
}
private int getColumnNumber(String document, int offset) {
final StringBuilder contextLine = getContextLine(document, offset);
int columnNumber = 0;
for (int i = 0; i < contextLine.length(); i++) {
if (Character.isWhitespace(contextLine.charAt(i))) {
columnNumber++;
} else {
break;
}
}
return columnNumber;
}
private StringBuilder getContextLine(String document, int offset) {
final StringBuilder contextLine = new StringBuilder();
if (offset < 0) // start of file detected!
{
return contextLine;
}
int location = offset;
char character = document.charAt(location);
while (location > 0 && character != '\n') {
location--;
contextLine.append(character);
character = document.charAt(location);
}
return contextLine.reverse();
}
public Rule getRuleFor(String stringContent) {
try {
RamlHeader ramlHeader = RamlHeader.parse(stringContent);
return ramlHeader.getRule();
} catch (RamlHeader.InvalidHeaderException e) {
// ignore, just return null
}
return null;
}
}

@ -0,0 +1,107 @@
/*
* Copyright 2013 (c) MuleSoft, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*/
package org.xbib.raml.internal.impl;
import java.io.File;
import java.io.FileFilter;
import java.util.List;
import org.xbib.raml.internal.utils.RamlNodeUtils;
import org.xbib.raml.yagi.framework.nodes.ErrorNode;
import org.xbib.raml.yagi.framework.nodes.Node;
import org.xbib.raml.yagi.framework.nodes.Position;
public class RamlValidator {
private static final String USAGE = "Arguments: [-dump] file|url|dir";
private boolean dump;
private String ramlLocation;
private RamlValidator(String[] args) {
parseArguments(args);
}
private void validate() {
validate(new File(ramlLocation));
}
private void validate(File location) {
if (isRamlFile(location)) {
validateRaml(location);
}
File[] files = new File[]{};
if (location.isDirectory()) {
files = location.listFiles(new FileFilter() {
@Override
public boolean accept(File pathname) {
return pathname.isDirectory() || isRamlFile(pathname);
}
});
}
for (File file : files) {
validate(file);
}
}
private void validateRaml(File ramlFile) {
final Node raml = new RamlBuilder().build(ramlFile);
List<ErrorNode> errors = RamlNodeUtils.getErrors(raml);
if (!errors.isEmpty()) {
logErrors(errors);
}
}
private boolean isRamlFile(File pathname) {
return pathname.isFile() && pathname.getName().endsWith(".raml");
}
public static void main(String[] args) {
new RamlValidator(args).validate();
}
private void logErrors(List<ErrorNode> errors) {
String label = errors.size() > 1 ? "errors" : "error";
System.out.format("%d %s found:\n\n", errors.size(), label);
for (ErrorNode error : errors) {
String message = error.getErrorMessage();
int idx = message.indexOf(". Options are");
if (idx != -1) {
message = message.substring(0, idx);
}
Position position = error.getSource() != null ? error.getSource().getStartPosition() : error.getStartPosition();
System.out.format("\t- %s %s\n\n", message, position);
}
}
private void parseArguments(String[] args) {
if (args.length < 1 || args.length > 2) {
throw new IllegalArgumentException(USAGE);
}
if (args.length == 2) {
if (!"-dump".equals(args[0])) {
throw new IllegalArgumentException(USAGE);
}
this.dump = true;
this.ramlLocation = args[1];
} else {
this.ramlLocation = args[0];
}
}
}

@ -0,0 +1,163 @@
/*
* Copyright 2013 (c) MuleSoft, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*/
package org.xbib.raml.internal.impl.commons;
import java.util.StringTokenizer;
import org.xbib.raml.api.model.v10.RamlFragment;
import org.xbib.raml.internal.impl.commons.nodes.TypeDeclarationNodeFragment;
import org.xbib.raml.internal.impl.v10.grammar.Raml10Grammar;
import org.xbib.raml.internal.impl.v10.grammar.Raml10GrammarUsesAllowed;
import org.xbib.raml.internal.utils.StreamUtils;
import org.xbib.raml.yagi.framework.grammar.rule.Rule;
import static org.xbib.raml.internal.impl.commons.RamlVersion.RAML_10;
public class RamlHeader {
public static final String RAML_HEADER_PREFIX = "#%RAML";
private final RamlVersion version;
private final RamlFragment fragment;
public RamlHeader(RamlVersion version, RamlFragment fragment) {
this.version = version;
this.fragment = fragment;
}
public RamlHeader(RamlVersion version) {
this(version, null);
}
public static RamlHeader parse(String stringContent) throws InvalidHeaderException {
final StringTokenizer lines = new StringTokenizer(StreamUtils.trimBom(stringContent), "\n");
if (lines.hasMoreElements()) {
final String header = lines.nextToken().trim();
final StringTokenizer headerParts = new StringTokenizer(header);
if (headerParts.hasMoreTokens()) {
final String raml = headerParts.nextToken();
if (RAML_HEADER_PREFIX.equals(raml)) {
if (headerParts.hasMoreTokens()) {
String stringVersion = headerParts.nextToken();
RamlVersion version;
try {
version = RamlVersion.parse(stringVersion);
} catch (IllegalArgumentException e) {
throw new InvalidHeaderVersionException(stringVersion);
}
if (version == RAML_10) {
final String fragmentText = headerParts.hasMoreTokens() ? headerParts.nextToken() : "";
RamlFragment fragment = RamlFragment.byName(fragmentText);
if (fragment == null) {
throw new InvalidHeaderFragmentException(fragmentText);
}
return new RamlHeader(RAML_10, fragment);
}
throw new IllegalStateException("unsupported RAML version");
}
}
}
throw new InvalidHeaderException(header);
} else {
throw new MissingHeaderException();
}
}
public RamlVersion getVersion() {
return version;
}
public RamlFragment getFragment() {
return fragment;
}
public Rule getRule() {
return getFragmentRule(fragment);
}
public static Rule getFragmentRule(RamlFragment fragment) {
Raml10Grammar grammar = new Raml10Grammar();
return getRule(fragment, grammar);
}
public static Rule getFragmentUsesAllowedRule(RamlFragment fragment) {
Raml10Grammar grammar = new Raml10GrammarUsesAllowed();
return getRule(fragment, grammar);
}
private static Rule getRule(RamlFragment fragment, Raml10Grammar grammar) {
switch (fragment) {
case DocumentationItem:
return grammar.documentation()
.with(0, grammar.usesField());
case DataType:
return grammar.explicitType().with(0, grammar.usesField()).then(TypeDeclarationNodeFragment.class);
case NamedExample:
return grammar.exampleFragment();
case ResourceType:
return grammar.resourceType().with(0, grammar.usesField());
case Trait:
return grammar.trait().with(0, grammar.usesField());
case AnnotationTypeDeclaration:
return grammar.annotationTypeDeclaration().with(0, grammar.usesField());
case Library:
return grammar.libraryValue();
case Overlay:
case Extension:
return grammar.extension();
case SecurityScheme:
return grammar.securityScheme().with(0, grammar.usesField());
case Default:
return grammar.raml();
default:
return null;
}
}
@Override
public String toString() {
return RAML_HEADER_PREFIX + " " + version.value() + (fragment != null ? (" " + fragment) : "");
}
public static class InvalidHeaderException extends Exception {
public InvalidHeaderException() {
}
public InvalidHeaderException(String message) {
super(message);
}
}
public static class InvalidHeaderFragmentException extends InvalidHeaderException {
public InvalidHeaderFragmentException(String fragmentText) {
super(fragmentText);
}
}
public static class InvalidHeaderVersionException extends InvalidHeaderException {
public InvalidHeaderVersionException(String version) {
super(version);
}
}
public static class MissingHeaderException extends InvalidHeaderException {
}
}

@ -0,0 +1,39 @@
/*
* Copyright 2013 (c) MuleSoft, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*/
package org.xbib.raml.internal.impl.commons;
public enum RamlVersion {
RAML_10("1.0");
public final String number;
public static RamlVersion parse(String version) {
for (RamlVersion item : values()) {
if (item.number.equals(version)) {
return item;
}
}
throw new IllegalArgumentException("Invalid version " + version);
}
RamlVersion(String number) {
this.number = number;
}
public String value() {
return number;
}
}

@ -0,0 +1,652 @@
/*
* Copyright 2013 (c) MuleSoft, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*/
package org.xbib.raml.internal.impl.commons.grammar;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.Callable;
import java.util.function.Function;
import org.xbib.raml.internal.impl.commons.nodes.BodyNode;
import org.xbib.raml.internal.impl.commons.nodes.MethodNode;
import org.xbib.raml.internal.impl.commons.nodes.ParametrizedResourceTypeRefNode;
import org.xbib.raml.internal.impl.commons.nodes.ParametrizedSecuritySchemeRefNode;
import org.xbib.raml.internal.impl.commons.nodes.ParametrizedTraitRefNode;
import org.xbib.raml.internal.impl.commons.nodes.RamlDocumentNode;
import org.xbib.raml.internal.impl.commons.nodes.ResourceNode;
import org.xbib.raml.internal.impl.commons.nodes.ResourceTypeNode;
import org.xbib.raml.internal.impl.commons.nodes.ResourceTypeRefNode;
import org.xbib.raml.internal.impl.commons.nodes.SecuritySchemeNode;
import org.xbib.raml.internal.impl.commons.nodes.SecuritySchemeRefNode;
import org.xbib.raml.internal.impl.commons.nodes.TraitNode;
import org.xbib.raml.internal.impl.commons.nodes.TraitRefNode;
import org.xbib.raml.internal.impl.commons.rule.NodeReferenceFactory;
import org.xbib.raml.internal.impl.commons.rule.NodeReferenceRule;
import org.xbib.raml.internal.impl.commons.rule.ParametrizedNodeReferenceRule;
import org.xbib.raml.internal.impl.v10.nodes.factory.EmptyObjectNodeFactory;
import org.xbib.raml.internal.impl.v10.nodes.factory.OverlayableSimpleTypeFactory;
import org.xbib.raml.internal.impl.v10.nodes.factory.TypeExpressionReferenceFactory;
import org.xbib.raml.yagi.framework.grammar.BaseGrammar;
import org.xbib.raml.yagi.framework.grammar.ExclusiveSiblingRule;
import org.xbib.raml.yagi.framework.grammar.RuleFactory;
import org.xbib.raml.yagi.framework.grammar.RuleTraverser;
import org.xbib.raml.yagi.framework.grammar.rule.AnyOfRule;
import org.xbib.raml.yagi.framework.grammar.rule.ArrayRule;
import org.xbib.raml.yagi.framework.grammar.rule.ArrayWrapperFactory;
import org.xbib.raml.yagi.framework.grammar.rule.KeyValueRule;
import org.xbib.raml.yagi.framework.grammar.rule.NodeFactory;
import org.xbib.raml.yagi.framework.grammar.rule.ObjectRule;
import org.xbib.raml.yagi.framework.grammar.rule.RegexValueRule;
import org.xbib.raml.yagi.framework.grammar.rule.Rule;
import org.xbib.raml.yagi.framework.grammar.rule.StringValueRule;
import org.xbib.raml.yagi.framework.nodes.Node;
import static org.xbib.raml.internal.impl.commons.phase.StringTemplateExpressionTransformer.TEMPLATE_PATTERN;
public abstract class BaseRamlGrammar extends BaseGrammar {
public static final String USES_KEY_NAME = "uses";
public static final String RESOURCE_TYPES_KEY_NAME = "resourceTypes";
public static final String TRAITS_KEY_NAME = "traits";
public static final String TYPES_KEY_NAME = "types";
public static final String SCHEMAS_KEY_NAME = "schemas";
public static final String QUERY_PARAMETERS_KEY_NAME = "queryParameters";
public static final String QUERY_STRING_KEY_NAME = "queryString";
public static final String SECURITY_SCHEMES_KEY_NAME = "securitySchemes";
public static final String MIME_TYPE_REGEX =
"([\\w\\d\\.\\-\\_\\+]+|\\*)\\/([\\w\\d\\.\\-\\_\\+]+|\\*);?([\\w\\d\\.\\-\\_\\+]+=[\\w\\d\\.\\-\\_\\+]+)?(\\s+[\\w\\d\\.\\-\\_\\+]+=[\\w\\d\\.\\-\\_\\+]+)*";
public static final String OAUTH_1_0 = "OAuth 1.0";
public static final String OAUTH_2_0 = "OAuth 2.0";
public ObjectRule raml() {
return untitledRaml().with(titleField().description("Short plain-text label for the API."));
}
protected NodeReferenceRule nodeRef(String referenceKey) {
return new NodeReferenceRule(referenceKey);
}
public ObjectRule untitledRaml() {
return objectType()
.with(descriptionField())
.with(schemasField())
.with(traitsField())
.with(resourceTypesField())
.with(securitySchemesField())
.with(versionField())
.with(baseUriField())
.with(baseUriParametersField())
.with(protocolsField())
.with(mediaTypeField())
.with(securedByField().description("The security schemes that apply to every resource and method in the API."))
.with(resourceField())
.with(fieldWithRequiredValue(documentationKey(), documentations()))
.then(RamlDocumentNode.class);
}
protected KeyValueRule baseUriParametersField() {
return field(baseUriParametersKey(), parameters());
}
protected KeyValueRule baseUriField() {
return field(baseUriKey(), new UriTemplateValidationRule(ramlScalarValue()));
}
protected KeyValueRule docTitleField() {
return requiredField(titleKey(), allOf(minLength(1), ramlScalarValue()));
}
protected KeyValueRule titleField() {
return requiredField(titleKey(), titleValue());
}
protected Rule titleValue() {
return allOf(ramlScalarValue(), minLength(1));
}
protected KeyValueRule resourceField() {
return new KeyValueRule(resourceKey(), anyOf(resourceValue(), nullValue().then(new EmptyObjectNodeFactory()))).then(ResourceNode.class);
}
protected KeyValueRule versionField() {
return field(versionKey(), ramlScalarValue());
}
protected Rule ramlScalarValue() {
return scalarType();
}
protected KeyValueRule mediaTypeField() {
return field(mediaTypeKey(), mimeTypeRegex());
}
public ObjectRule resourceType() {
final ObjectRule resourceType = inNewContext(new Callable<ObjectRule>() {
@Override
public ObjectRule call() {
return new RuleTraverser().traverse(baseResourceValue().with(field(anyResourceTypeMethod(), methodValue())), ruleParameterModifier());
}
});
return resourceType
.with(0, usageField()); // match anything but nested resources
}
/**
* Returns a function that modifies a rule to support parameter
*
* @return The function that injects the parameters
*/
private Function<Rule, Boolean> ruleParameterModifier() {
return new Function<Rule, Boolean>() {
@Override
public Boolean apply(Rule input) {
// We should change that any object now should have a parametrized key value pair
// This mean that any key can be parametrized and we don't know anything about the value
// And any value can be parametrized of any known key
if (input instanceof ObjectRule) {
((ObjectRule) input).with(0, fieldParametrizedKey());
} else if (input instanceof KeyValueRule keyValueRule) {
keyValueRule.setValueRule(anyOf(parametrizedValueRule(), keyValueRule.getValueRule()));
keyValueRule.cleanDefaultValue();
} else if (input instanceof ArrayRule arrayRule) {
arrayRule.of(anyOf(parametrizedValueRule(), arrayRule.of()));
}
// We keep reference factories so that we can validate reference consistency
// and we keep overlay factories so traits/rt can be overlaid
if (!isReferenceFactory(input) && !isOverlayFactory(input) && input.getFactory() != null) {
input.cleanFactory();
}
return true;
}
};
}
private boolean isOverlayFactory(Rule input) {
return input.getFactory() instanceof OverlayableSimpleTypeFactory;
}
private boolean isReferenceFactory(Rule input) {
return input.getFactory() instanceof NodeReferenceFactory || input.getFactory() instanceof TypeExpressionReferenceFactory;
}
public ObjectRule resourceTypeParamsResolved() {
return baseResourceValue()
.with(usageField())
.with(field(anyResourceTypeMethod(), methodValue())
.then(MethodNode.class));
}
public ObjectRule traitParamsResolved() {
return objectType()
.with(descriptionField())
.with(field(displayNameKey(), ramlScalarValue()))
.with(queryParametersField())
.with(headersField())
.with(responsesField())
.with(bodyField())
.with(protocolsField().description("A method can override the protocols specified in the resource or at the API root, by employing this property."))
.with(isField().description("A list of the traits to apply to this method."))
.with(securedByField().description("The security schemes that apply to this method."))
.with(usageField());
}
// Documentation
protected Rule documentations() {
return array(documentation());
}
public ObjectRule documentation() {
return objectType()
.with(docTitleField().description("Title of documentation section."))
.with(contentField().description("Content of documentation section."));
}
protected KeyValueRule contentField() {
return requiredField(string("content"), ramlScalarValue());
}
// Security scheme
protected Rule securitySchemes() {
return objectType()
.with(
field(scalarType(), securityScheme())
.then(SecuritySchemeNode.class)
);
}
public ObjectRule securityScheme() {
return objectType()
.with(descriptionField())
.with(requiredField(
securitySchemeTypeKey(),
anyOf(
string(OAUTH_1_0).description("The API's authentication uses OAuth 1.0 as described in RFC5849 [RFC5849]"),
string(OAUTH_2_0).description("The API's authentication uses OAuth 2.0 as described in RFC6749 [RFC6749]"),
string("Basic Authentication").description(
"The API's authentication uses Basic Authentication as described in RFC2617 [RFC2617]"),
string("Digest Authentication").description(
"The API's authentication uses Digest Authentication as described in RFC2617 [RFC2617]"),
string("Pass Through").description("Headers or Query Parameters are passed through to the API based on a defined object."),
regex("x-.+").description("The API's authentication uses an authentication method not listed above.")
)))
.with(displayNameField())
.with(field(string("describedBy"), securitySchemePart()))
.with(when("type", is(anyOf(string(OAUTH_1_0), string(OAUTH_2_0))).add(requiredField(string("settings"), securitySchemeSettings()))));
}
protected ObjectRule securitySchemePart() {
return objectType()
.with(displayNameField())
.with(descriptionField())
.with(field(headersKey(), parameters()))
.with(queryParametersField())
.with(responsesField());
}
protected ObjectRule securitySchemeSettings() {
return objectType()
.with(field(string("requestTokenUri"), ramlScalarValue()))
.with(field(string("tokenCredentialsUri"), ramlScalarValue()))
.with(field(string("accessTokenUri"), ramlScalarValue()))
.with(field(string("authorizationGrants"), anyOf(authorizationGrantsValue(), array(authorizationGrantsValue()))))
.with(field(string("scopes"), anyOf(scalarType(), array(scalarType()))));
}
protected Rule authorizationGrantsValue() {
return scalarType();
}
// Traits
protected Rule traitsValue() {
return objectType()
.with(
field(scalarType(), trait()).then(TraitNode.class)
);
}
public ObjectRule trait() {
final ObjectRule trait = inNewContext(new Callable<ObjectRule>() {
@Override
public ObjectRule call() {
return new RuleTraverser().traverse(methodValue(), ruleParameterModifier());
}
});
return trait
.with(0, usageField());
}
private RegexValueRule parametrizedValueRule() {
return regex(TEMPLATE_PATTERN).fullMatch(false);
}
private KeyValueRule fieldParametrizedKey() {
return field(parametrizedValueRule(), any());
}
// Resource Types
protected Rule resourceTypes() {
return objectType().with(field(scalarType(), resourceType()).then(ResourceTypeNode.class));
}
// Resources
protected ObjectRule resourceValue() {
return named("resourceValue", new RuleFactory<ObjectRule>() {
@Override
public ObjectRule create() {
return baseResourceValue()
.with(methodField())
.with(resourceField());
}
});
}
protected KeyValueRule methodField() {
return new KeyValueRule(anyMethod(), anyOf(methodValue(), nullValue().then(new EmptyObjectNodeFactory()))).then(MethodNode.class);
}
protected ObjectRule baseResourceValue() {
return objectType()
.with(displayNameField())
.with(descriptionField())
.with(isField().description("A list of the traits to apply to all methods declared (implicitly or explicitly) for this resource. "))
.with(resourceTypeReferenceField())
.with(securedByField().description("The security schemes that apply to all methods declared (implicitly or explicitly) for this resource."))
.with(field(uriParametersKey(), parameters()));
}
// Method
protected ObjectRule methodValue() {
return objectType()
.with(descriptionField())
.with(displayNameField())
.with(queryParametersField())
.with(headersField())
.with(responsesField())
.with(bodyField())
.with(protocolsField().description("A method can override the protocols specified in the resource or at the API root, by employing this property."))
.with(isField().description("A list of the traits to apply to this method."))
.with(securedByField().description("The security schemes that apply to this method."));
}
protected KeyValueRule queryParametersField() {
return field(queryParametersKey(), parameters());
}
protected KeyValueRule responsesField() {
return field(responseKey(), responses());
}
protected StringValueRule responseKey() {
return string("responses")
.description("Information about the expected responses to a request");
}
protected StringValueRule queryStringKey() {
return string(QUERY_STRING_KEY_NAME)
.description("Specifies the query string needed by this method." +
" Mutually exclusive with queryParameters.");
}
protected StringValueRule queryParametersKey() {
return string(QUERY_PARAMETERS_KEY_NAME)
.description("Detailed information about any query parameters needed by this method. " +
"Mutually exclusive with queryString.");
}
protected Rule responses() {
return objectType().with(responseField());
}
protected KeyValueRule responseField() {
return field(responseCodes(), response());
}
protected ObjectRule response() {
return objectType()
.with(displayNameField())
.with(descriptionField())
.with(headersField())
.with(bodyField());
}
protected Rule body() {
return objectType().with(mimeTypeField());
}
public KeyValueRule mimeTypeField() {
return field(mimeTypeRegex(), mimeType());
}
public RegexValueRule mimeTypeRegex() {
return regex(MIME_TYPE_REGEX)
.suggest("application/json")
.suggest("application/xml");
}
protected abstract Rule mimeType();
protected Rule parameters() {
return objectType().with(field(scalarType(), parameter()));
}
/**
* Describes the rule for a parameter.
*/
protected abstract Rule parameter();
protected ExclusiveSiblingRule exclusiveWith(String key, String... notAllowedSiblings) {
Set<String> set = new HashSet<>(Arrays.asList(notAllowedSiblings));
return new ExclusiveSiblingRule(key, set);
}
protected KeyValueRule securitySchemesField() {
return field(securitySchemesKey(), securitySchemesValue());
}
protected abstract Rule securitySchemesValue();
protected StringValueRule securitySchemesKey() {
return string(SECURITY_SCHEMES_KEY_NAME).description("Declarations of security schemes for use within this API.");
}
protected KeyValueRule schemasField() {
return field(schemasKey(), schemasValue());
}
protected abstract Rule schemasValue();
protected StringValueRule schemasKey() {
return string("schemas")
.description(schemasDescription());
}
protected abstract String schemasDescription();
protected KeyValueRule resourceTypesField() {
return field(resourceTypesKey(), resourceTypesValue());
}
protected Rule resourceTypesValue() {
return anyOf(array(resourceTypes()), resourceTypes()).then(new ArrayWrapperFactory());
}
protected StringValueRule resourceTypesKey() {
return string(RESOURCE_TYPES_KEY_NAME).description("Declarations of resource types for use within this API.");
}
protected KeyValueRule traitsField() {
return field(traitsKey(), traitsValue());
}
protected StringValueRule traitsKey() {
return string(TRAITS_KEY_NAME).description("Declarations of traits for use within this API.");
}
protected KeyValueRule protocolsField() {
return field(protocolsKey(), protocols());
}
protected StringValueRule protocolsKey() {
return string("protocols").description("The protocols supported by the API.");
}
protected KeyValueRule bodyField() {
return field(bodyKey(),
firstOf(
whenChildIs(mimeTypeField(), body()),
whenPresent("/mediaType", mimeType())))
.then(BodyNode.class);
}
protected StringValueRule bodyKey() {
return string("body")
.description("Some methods admit request bodies, which are described by this property.");
}
protected KeyValueRule headersField() {
return field(headersKey(), parameters());
}
protected StringValueRule headersKey() {
return string("headers")
.description("Detailed information about any request headers needed by this method.");
}
protected KeyValueRule descriptionField() {
return field(descriptionKey(), descriptionValue());
}
protected Rule descriptionValue() {
return ramlScalarValue();
}
protected KeyValueRule displayNameField() {
return field(displayNameKey(), ramlScalarValue()).defaultValue(parentKey());
}
protected KeyValueRule securedByField() {
Rule securitySchemeRef = anyOf(nullValue(), anyTypeReference(SECURITY_SCHEMES_KEY_NAME, SecuritySchemeRefNode.class, ParametrizedSecuritySchemeRefNode.class));
return field(securedByKey(), anyOf(securitySchemeRef, array(securitySchemeRef)).then(new ArrayWrapperFactory()));
}
protected KeyValueRule usageField() {
return field(string("usage"), ramlScalarValue());
}
protected KeyValueRule isField() {
Rule traitRef = anyTypeReference(TRAITS_KEY_NAME, TraitRefNode.class, ParametrizedTraitRefNode.class);
return field(isKey(), anyOf(traitRef, array(traitRef)).then(new ArrayWrapperFactory()));
}
protected KeyValueRule resourceTypeReferenceField() {
return field(resourceTypeRefKey(), anyTypeReference(RESOURCE_TYPES_KEY_NAME, ResourceTypeRefNode.class, ParametrizedResourceTypeRefNode.class));
}
protected Rule anyTypeReference(String referenceKey, Class<? extends Node> simpleClass, Class<? extends Node> parametrisedClass) {
final KeyValueRule paramsRule = field(scalarType(), any());
final KeyValueRule typeWithParams = field(scalarType(), objectType().with(paramsRule));
final NodeFactory factory = new NodeReferenceFactory(simpleClass);
final NodeFactory parametrisedFactory = new NodeReferenceFactory(parametrisedClass);
return anyOf(nodeRef(referenceKey).then(factory), new ParametrizedNodeReferenceRule(referenceKey).with(typeWithParams).then(parametrisedFactory));
}
protected StringValueRule titleKey() {
return string("title");
}
// Repeated keys
protected Rule resourceKey() {
RegexValueRule rule = regex("/.*")
.label("/Resource")
.suggest("/<cursor>")
.description("The resources of the API, identified as relative URIs that begin with a slash (/). " +
"Every property whose key begins with a slash (/), and is either at the root of the API definition " +
"or is the child property of a resource property, is a resource property, e.g.: /users, /{groupId}, etc");
return new UriTemplateValidationRule(rule);
}
protected StringValueRule usesKey() {
return string(USES_KEY_NAME).description("Importing libraries.");
}
protected StringValueRule uriParametersKey() {
return string("uriParameters").description("Detailed information about any URI parameters of this resource");
}
protected StringValueRule securedByKey() {
return string("securedBy");
}
protected StringValueRule typeKey() {
return string("type")
.description("The resource type which this resource inherits.");
}
protected StringValueRule securitySchemeTypeKey() {
return string("type")
.description("Specify the security mechanism.");
}
protected StringValueRule resourceTypeRefKey() {
return string("type")
.description("The resource type which this resource inherits.");
}
protected StringValueRule isKey() {
return string("is");
}
protected StringValueRule displayNameKey() {
return string("displayName")
.description("An alternate, human-friendly name for the method (in the resource's context).");
}
protected StringValueRule descriptionKey() {
return string("description").description("A longer, human-friendly description of the API");
}
protected StringValueRule documentationKey() {
return string("documentation")
.description("Additional overall documentation for the API.");
}
protected StringValueRule mediaTypeKey() {
return string("mediaType")
.description("The default media type to use for request and response bodies (payloads), e.g. \"application/json\".");
}
protected StringValueRule baseUriParametersKey() {
return string("baseUriParameters").description("Named parameters used in the baseUri (template).");
}
protected StringValueRule baseUriKey() {
return string("baseUri").description("A URI that's to be used as the base of all the resources' URIs." +
" Often used as the base of the URL of each resource, containing the location of the API. " +
"Can be a template URI.");
}
protected StringValueRule versionKey() {
return string("version").description("The version of the API, e.g. \"v1\".");
}
// Enum of values
protected AnyOfRule anyMethod() {
return anyOf(
string("get"),
string("patch"),
string("put"),
string("post"),
string("delete"),
string("options"),
string("head"));
}
protected AnyOfRule anyOptionalMethod() {
return anyOf(string("get?"), string("patch?"), string("put?"), string("post?"), string("delete?"), string("options?"), string("head?"));
}
protected AnyOfRule anyResourceTypeMethod() {
return anyOf(anyMethod(), anyOptionalMethod());
}
protected Rule protocols() {
AnyOfRule protocols = anyOf(string("HTTP").caseSensitive(false), string("HTTPS").caseSensitive(false));
return anyOf(protocols, array(protocols)).then(new ArrayWrapperFactory());
}
protected Rule responseCodes() {
return allOf(range(100, 599));
}
}

@ -0,0 +1,63 @@
/*
* Copyright 2013 (c) MuleSoft, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*/
package org.xbib.raml.internal.impl.commons.grammar;
import java.util.List;
import org.xbib.raml.internal.impl.commons.rule.RamlErrorNodeFactory;
import org.xbib.raml.internal.utils.UriTemplateValidation;
import org.xbib.raml.yagi.framework.grammar.rule.Rule;
import org.xbib.raml.yagi.framework.nodes.Node;
import org.xbib.raml.yagi.framework.nodes.snakeyaml.SYStringNode;
import org.xbib.raml.yagi.framework.suggester.ParsingContext;
import org.xbib.raml.yagi.framework.suggester.Suggestion;
public class UriTemplateValidationRule extends Rule {
private final Rule rule;
public UriTemplateValidationRule(Rule rule) {
super();
this.rule = rule;
}
@Override
public boolean matches(Node node) {
return rule.matches(node);
}
@Override
public Node apply(Node node) {
Node apply = rule.apply(node);
if (node instanceof SYStringNode) {
if (!UriTemplateValidation.isBalanced(((SYStringNode) node).getValue())) {
apply = RamlErrorNodeFactory.createInvalidUriTemplate();
}
}
return apply;
}
@Override
public String getDescription() {
return rule.getDescription();
}
@Override
public List<Suggestion> getSuggestions(Node node, ParsingContext context) {
return rule.getSuggestions(node, context);
}
}

@ -0,0 +1,38 @@
/*
* Copyright 2013 (c) MuleSoft, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*/
package org.xbib.raml.internal.impl.commons.model;
import java.util.ArrayList;
import java.util.List;
import org.xbib.raml.internal.impl.commons.nodes.AnnotationNode;
import org.xbib.raml.yagi.framework.model.AbstractNodeModel;
import org.xbib.raml.yagi.framework.nodes.Node;
public abstract class Annotable<T extends Node> extends AbstractNodeModel<T> {
public Annotable(T node) {
super(node);
}
public List<AnnotationRef> annotations() {
List<AnnotationRef> result = new ArrayList<>();
for (Node child : getNode().getChildren()) {
if (child instanceof AnnotationNode) {
result.add(new AnnotationRef((AnnotationNode) child));
}
}
return result;
}
}

@ -0,0 +1,45 @@
/*
* Copyright 2013 (c) MuleSoft, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*/
package org.xbib.raml.internal.impl.commons.model;
import org.xbib.raml.internal.impl.commons.model.factory.TypeDeclarationModelFactory;
import org.xbib.raml.internal.impl.commons.model.type.TypeDeclaration;
import org.xbib.raml.internal.impl.commons.nodes.AnnotationNode;
import org.xbib.raml.yagi.framework.model.AbstractNodeModel;
import org.xbib.raml.yagi.framework.nodes.Node;
public class AnnotationRef extends AbstractNodeModel<AnnotationNode> {
public AnnotationRef(AnnotationNode node) {
super(node);
}
public TypeDeclaration annotation() {
return new TypeDeclarationModelFactory().create(node.getAnnotationTypeNode());
}
public String name() {
return node.getKey().getValue();
}
public TypeInstance structuredValue() {
return new TypeInstance(node.getValue());
}
@Override
public Node getNode() {
return node;
}
}

@ -0,0 +1,50 @@
/*
* Copyright 2013 (c) MuleSoft, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*/
package org.xbib.raml.internal.impl.commons.model;
import java.util.ArrayList;
import java.util.List;
import org.xbib.raml.internal.impl.commons.nodes.RamlDocumentNode;
import org.xbib.raml.internal.impl.commons.nodes.ResourceNode;
import org.xbib.raml.yagi.framework.nodes.Node;
import static org.xbib.raml.internal.utils.RamlNodeUtils.getVersion;
public class Api extends Annotable<RamlDocumentNode> {
public Api(RamlDocumentNode delegateNode) {
super(delegateNode);
}
@Override
public Node getNode() {
return node;
}
public List<Resource> resources() {
ArrayList<Resource> resultList = new ArrayList<>();
for (Node item : node.getChildren()) {
if (item instanceof ResourceNode) {
resultList.add(new Resource((ResourceNode) item));
}
}
return resultList;
}
public String ramlVersion() {
return getVersion(node).value();
}
}

@ -0,0 +1,55 @@
/*
* Copyright 2013 (c) MuleSoft, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*/
package org.xbib.raml.internal.impl.commons.model;
import org.xbib.raml.yagi.framework.model.AbstractNodeModel;
import org.xbib.raml.yagi.framework.nodes.KeyValueNode;
import org.xbib.raml.yagi.framework.nodes.Node;
import org.xbib.raml.yagi.framework.nodes.StringNode;
import org.xbib.raml.yagi.framework.util.NodeSelector;
public class BodyLike extends AbstractNodeModel<KeyValueNode> {
public BodyLike(KeyValueNode node) {
super(node);
}
@Override
public Node getNode() {
return node.getValue();
}
public String name() {
return ((StringNode) node.getKey()).getValue();
}
public String schemaContent() {
String schema = NodeSelector.selectStringValue("schema", getNode());
// For an inline schema
if (schema == null || schema.startsWith("{") || schema.startsWith("<")) {
return schema;
}
// For an schema reference,
Node rootRamlSchema = NodeSelector.selectFrom("/schemas/" + schema, getNode());
if (rootRamlSchema instanceof StringNode) {
return ((StringNode) rootRamlSchema).getValue();
}
return null;
}
}

@ -0,0 +1,29 @@
/*
* Copyright 2013 (c) MuleSoft, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*/
package org.xbib.raml.internal.impl.commons.model;
import org.xbib.raml.yagi.framework.nodes.Node;
public class DefaultModelElement extends Annotable<Node> {
public DefaultModelElement(Node node) {
super(node);
}
@Override
public Node getNode() {
return node;
}
}

@ -0,0 +1,85 @@
/*
* Copyright 2013 (c) MuleSoft, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*/
package org.xbib.raml.internal.impl.commons.model;
import org.xbib.raml.internal.utils.JSonDumper;
import org.xbib.raml.yagi.framework.nodes.KeyValueNode;
import org.xbib.raml.yagi.framework.nodes.Node;
import org.xbib.raml.yagi.framework.nodes.ObjectNode;
import org.xbib.raml.yagi.framework.util.NodeSelector;
public class ExampleSpec extends Annotable<KeyValueNode> {
public ExampleSpec(KeyValueNode node) {
super(node);
}
public String value() {
final Node exampleValue = getExampleValue();
if (structuredValue().isScalar()) {
return exampleValue.toString();
} else {
return JSonDumper.dump(exampleValue);
}
}
public String name() {
return getName();
}
public TypeInstance structuredValue() {
final Node value = getExampleValue();
// FIXME ExampleTypeNode may wrap a SimpleTypeNode
// if ((value instanceof ExampleTypeNode) && value.getSource() != null)
// {
// value = value.getSource();
// }
return new TypeInstance(value);
}
@Override
public Node getNode() {
return node.getValue();
}
private Node getExampleValue() {
if (isExplicitExample()) {
return NodeSelector.selectFrom("value", node.getValue());
} else {
return node.getValue();
}
}
private String getName() {
final Node ancestor = org.xbib.raml.yagi.framework.util.NodeUtils.getAncestor(node, 2);
if (ancestor instanceof KeyValueNode && ((KeyValueNode) ancestor).getKey().toString().equals("examples")) {
return node.getKey().toString();
} else {
return null;
}
}
private boolean isExplicitExample() {
if (node.getValue() instanceof ObjectNode) {
final Node value = NodeSelector.selectFrom("value", node.getValue());
return value != null;
}
return false;
}
}

@ -0,0 +1,40 @@
/*
* Copyright 2013 (c) MuleSoft, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*/
package org.xbib.raml.internal.impl.commons.model;
import org.xbib.raml.yagi.framework.model.AbstractNodeModel;
import org.xbib.raml.yagi.framework.nodes.KeyValueNode;
import org.xbib.raml.yagi.framework.nodes.Node;
import org.xbib.raml.yagi.framework.nodes.SimpleTypeNode;
public class GlobalSchema extends AbstractNodeModel<KeyValueNode> {
public GlobalSchema(KeyValueNode node) {
super(node);
}
@Override
public Node getNode() {
return node.getValue();
}
public String key() {
return ((SimpleTypeNode) node.getKey()).getLiteralValue();
}
public StringType value() {
return new StringType((SimpleTypeNode) node.getValue());
}
}

@ -0,0 +1,36 @@
/*
* Copyright 2013 (c) MuleSoft, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*/
package org.xbib.raml.internal.impl.commons.model;
import org.xbib.raml.internal.impl.v10.nodes.LibraryLinkNode;
import org.xbib.raml.internal.impl.v10.nodes.LibraryNode;
import org.xbib.raml.yagi.framework.nodes.Node;
public class Library extends Annotable<LibraryNode> {
public Library(LibraryNode node) {
super(node);
}
@Override
public Node getNode() {
final Node value = node.getValue();
return ((LibraryLinkNode) value).getRefNode();
}
public String name() {
return node.getName();
}
}

@ -0,0 +1,45 @@
/*
* Copyright 2013 (c) MuleSoft, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*/
package org.xbib.raml.internal.impl.commons.model;
import org.xbib.raml.internal.impl.commons.nodes.MethodNode;
import org.xbib.raml.internal.impl.commons.nodes.ResourceNode;
import org.xbib.raml.yagi.framework.nodes.Node;
public class Method extends Annotable<MethodNode> {
public Method(MethodNode node) {
super(node);
}
@Override
public Node getNode() {
return node.getValue();
}
public String method() {
return node.getName();
}
public Resource resource() {
Node parent = node.getParent();
if (parent != null) {
if (parent.getParent() instanceof ResourceNode) {
return new Resource((ResourceNode) parent.getParent());
}
}
return null;
}
}

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save