Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ public String toString() {
public Set<ApiParameterMetadata> getPathVariables() {
pathVariables = new LinkedHashSet<>();

// Add any Base Uri Parameters
parent.getDocument().getBaseUriParameters().stream()
.forEach(param -> pathVariables.add(new ApiParameterMetadata(param.getName(), param, null)));

RamlResource targetResource = action.getResource();

do {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ public interface RamlModelFactory {

RamlSecurityReference createRamlSecurityReference(Object securityReference);

List<RamlUriParameter> createRamlUriParameters(List<? extends Object> uriParameters);

RamlUriParameter createRamlUriParameter(Object uriParameters);

RamlParamType createRamlParamType(Object paramType);

default <SK, TK, SV, TV> Map<TK, TV> transformToUnmodifiableMap(Collection<SV> source, Map<TK, TV> target,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,6 @@ public interface RamlRoot extends RamlResourceRoot {
List<RamlSecurityReference> getSecuredBy();

List<RamlSecurityScheme> getSecuritySchemes();

List<RamlUriParameter> getBaseUriParameters();
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.phoenixnap.oss.ramlplugin.raml2code.raml.RamlRoot;
import com.phoenixnap.oss.ramlplugin.raml2code.raml.RamlSecurityReference;
import com.phoenixnap.oss.ramlplugin.raml2code.raml.RamlSecurityScheme;
import com.phoenixnap.oss.ramlplugin.raml2code.raml.RamlUriParameter;

/**
* @author aweisser
Expand Down Expand Up @@ -136,6 +137,16 @@ public RamlSecurityScheme createRamlSecurityScheme(Object securityReference) {
return new RJP10V2RamlSecurityScheme((SecurityScheme) securityReference);
}

@Override
public List<RamlUriParameter> createRamlUriParameters(List<? extends Object> uriParameters) {
return uriParameters.stream().map(this::createRamlUriParameter).collect(Collectors.toList());
}

@Override
public RamlUriParameter createRamlUriParameter(Object uriParameter) {
return new RJP10V2RamlUriParameter((TypeDeclaration) uriParameter);
}

@Override
public RamlParamType createRamlParamType(Object paramType) {
if (paramType == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.phoenixnap.oss.ramlplugin.raml2code.raml.RamlRoot;
import com.phoenixnap.oss.ramlplugin.raml2code.raml.RamlSecurityReference;
import com.phoenixnap.oss.ramlplugin.raml2code.raml.RamlSecurityScheme;
import com.phoenixnap.oss.ramlplugin.raml2code.raml.RamlUriParameter;

/**
* @author aweisser
Expand Down Expand Up @@ -139,4 +140,10 @@ public List<RamlSecurityReference> getSecuredBy() {
public List<RamlSecurityScheme> getSecuritySchemes() {
return ramlModelFactory.createRamlSecuritySchemes(this.api.securitySchemes());
}

@Override
public List<RamlUriParameter> getBaseUriParameters() {
return ramlModelFactory.createRamlUriParameters(this.api.baseUriParameters());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.phoenixnap.oss.ramlplugin.raml2code.github;

import org.junit.Test;

import com.phoenixnap.oss.ramlplugin.raml2code.data.ApiResourceMetadata;
import com.phoenixnap.oss.ramlplugin.raml2code.helpers.RamlParser;
import com.phoenixnap.oss.ramlplugin.raml2code.rules.ConfigurableRule;
import com.phoenixnap.oss.ramlplugin.raml2code.rules.GitHubAbstractRuleTestBase;
import com.phoenixnap.oss.ramlplugin.raml2code.rules.Spring4ControllerDecoratorRule;
import com.sun.codemodel.JCodeModel;
import com.sun.codemodel.JDefinedClass;

/**
* @author manikmagar
* @since 2.1.0
*/
public class Issue301RulesTest extends GitHubAbstractRuleTestBase {

private ConfigurableRule<JCodeModel, JDefinedClass, ApiResourceMetadata> rule;

public Issue301RulesTest() {
defaultRamlParser = new RamlParser("/v1/{somekey}");
}

@Test
public void verifyBaseUriParameters() throws Exception {
loadRaml("issue-301.raml");
rule = new Spring4ControllerDecoratorRule();
rule.apply(getControllerMetadata(), jCodeModel);
verifyGeneratedCode("Issue301Spring4Decorator");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import com.phoenixnap.oss.ramlplugin.raml2code.raml.RamlMimeType;
import com.phoenixnap.oss.ramlplugin.raml2code.raml.RamlResource;
import com.phoenixnap.oss.ramlplugin.raml2code.raml.RamlRoot;
import com.phoenixnap.oss.ramlplugin.raml2code.raml.RamlUriParameter;
import com.phoenixnap.oss.ramlplugin.raml2code.rules.AbstractRuleTestBase;
import com.phoenixnap.oss.ramlplugin.raml2code.rules.RamlLoader;

Expand All @@ -41,13 +42,14 @@
*/
public class RJP10V2RamlRootTest extends AbstractRuleTestBase {

private static RamlRoot ramlRoot, ramlRootEmptyValues, ramlSchemaRoot;
private static RamlRoot ramlRoot, ramlRootEmptyValues, ramlSchemaRoot, ramlRootBaseUriParams;

@BeforeClass
public static void initRamlRoot() throws InvalidRamlResourceException {
ramlRoot = RamlLoader.loadRamlFromFile(AbstractRuleTestBase.RESOURCE_BASE + "raml-root-test-v10.raml");
ramlRootEmptyValues = RamlLoader.loadRamlFromFile(AbstractRuleTestBase.RESOURCE_BASE + "raml-root-test-emptyValues-v10.raml");
ramlSchemaRoot = RamlLoader.loadRamlFromFile(AbstractRuleTestBase.RESOURCE_BASE + "raml-root-schemas-test-v10.raml");
ramlRootBaseUriParams = RamlLoader.loadRamlFromFile(AbstractRuleTestBase.RESOURCE_BASE + "raml-root-test-baseuriparam-v10.raml");
}

@Test
Expand Down Expand Up @@ -230,4 +232,11 @@ public void factoryShouldReflectDocumentation() {

}

@Test
public void ramlRootShouldHaveBaseUriParameters() {
List<RamlUriParameter> baseUriParameters = ramlRootBaseUriParams.getBaseUriParameters();
assertThat(baseUriParameters.get(0).getName(), equalTo("key"));
assertThat(baseUriParameters.get(0).getRawType(), equalTo("string"));
}

}
12 changes: 12 additions & 0 deletions src/test/resources/ramls/github/issue-301.raml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#%RAML 1.0
title: Amazon S3 REST API
version: 1
baseUri: /v1/{somekey}
baseUriParameters:
somekey:
description: The name of the bucket
type: string

/common:
/list:
get:
10 changes: 10 additions & 0 deletions src/test/resources/ramls/raml-root-test-baseuriparam-v10.raml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#%RAML 1.0
title: myapi
baseUri: api/{key}
baseUriParameters:
key: string
/songs:
get:
responses:
200:
body:
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
-----------------------------------com.gen.test.ListController.java-----------------------------------

package com.gen.test;

import org.springframework.http.ResponseEntity;


/**
* No description
* (Generated with springmvc-raml-parser v.2.1.0)
*
*/
public interface ListController {


/**
* No description
*
*/
public ResponseEntity<?> getObjectBySomekey(String somekey);

}
-----------------------------------com.gen.test.ListControllerDecorator.java-----------------------------------

package com.gen.test;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;


/**
* No description
* (Generated with springmvc-raml-parser v.2.1.0)
*
*/
@RestController
@RequestMapping("/v1/{somekey}/common/list")
@Validated
public class ListControllerDecorator
implements ListController
{

@Autowired
private ListController listControllerDelegate;

/**
* No description
*
*/
@RequestMapping(value = "", method = RequestMethod.GET)
public ResponseEntity<?> getObjectBySomekey(
@PathVariable
String somekey) {
return this.listControllerDelegate.getObjectBySomekey(somekey);
}

}