Skip to content
This repository was archived by the owner on Aug 8, 2018. It is now read-only.

Commit fc54474

Browse files
author
Kevin Yarosh
committedDec 6, 2016
Created requestParameters Maps in createResources to be passed to createMethod method
1 parent fea51c9 commit fc54474

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed
 

‎src/com/amazonaws/service/apigateway/importer/impl/sdk/ApiGatewaySdkRamlApiImporter.java

+17-9
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ public String createApi(Raml raml, String name, JSONObject config) {
8282
final Resource rootResource = getRootResource(api).get();
8383
deleteDefaultModels(api);
8484
createModels(api, raml.getSchemas(), false);
85-
createResources(api, createResourcePath(api, rootResource, raml.getBasePath()), raml.getResources(), false);
85+
createResources(api, createResourcePath(api, rootResource, raml.getBasePath()),
86+
new HashMap<String, UriParameter>(), raml.getResources(), false);
8687
} catch (Throwable t) {
8788
LOG.error("Error creating API, rolling back", t);
8889
rollback(api);
@@ -99,7 +100,8 @@ public void updateApi(String apiId, Raml raml, JSONObject config) {
99100
Optional<Resource> rootResource = getRootResource(api);
100101

101102
createModels(api, raml.getSchemas(), true);
102-
createResources(api, createResourcePath(api, rootResource.get(), raml.getBasePath()), raml.getResources(), true);
103+
createResources(api, createResourcePath(api, rootResource.get(), raml.getBasePath()),
104+
new HashMap<String, UriParameter>(), raml.getResources(), true);
103105

104106
cleanupResources(api, this.paths);
105107
cleanupModels(api, this.models);
@@ -143,13 +145,17 @@ private void createModel(RestApi api, String schemaName, String schemaValue) {
143145
createModel(api, schemaName, null, schemaValue, isJson ? "application/json" : "text/xml");
144146
}
145147

146-
private void createResources(RestApi api, Resource rootResource, Map<String, org.raml.model.Resource> resources, boolean update) {
148+
private void createResources(RestApi api, Resource rootResource, Map<String, UriParameter> ancestorRequestParameters,
149+
Map<String, org.raml.model.Resource> resources, boolean update) {
147150
for (Map.Entry<String, org.raml.model.Resource> entry : resources.entrySet()) {
148151
final org.raml.model.Resource resource = entry.getValue();
149152
final Resource parentResource = createResourcePath(api, rootResource, entry.getKey());
150153

151-
createMethods(api, parentResource, resource.getActions(), update);
152-
createResources(api, parentResource, resource.getResources(), update);
154+
Map<String, UriParameter> requestParameters = new HashMap<String, UriParameter>(resource.getUriParameters());
155+
requestParameters.putAll(ancestorRequestParameters);
156+
157+
createMethods(api, parentResource, requestParameters, resource.getActions(), update);
158+
createResources(api, parentResource, requestParameters, resource.getResources(), update);
153159
}
154160
}
155161

@@ -179,9 +185,10 @@ private Resource createResourcePath(RestApi api, Resource resource, String fullP
179185
return parentResource;
180186
}
181187

182-
private void createMethods(RestApi api, Resource resource, Map<ActionType, Action> actions, boolean update) {
188+
private void createMethods(RestApi api, Resource resource, Map<String, UriParameter> requestParameters,
189+
Map<ActionType, Action> actions, boolean update) {
183190
for (Map.Entry<ActionType, Action> entry : actions.entrySet()) {
184-
createMethod(api, resource, entry.getKey(), entry.getValue(), update);
191+
createMethod(api, resource, entry.getKey(), entry.getValue(), requestParameters, update);
185192
}
186193

187194
if (update) {
@@ -207,7 +214,8 @@ private void cleanupMethods (Resource resource, Map<ActionType, Action> actions)
207214
}
208215
}
209216

210-
private void createMethod(final RestApi api, final Resource resource, final ActionType httpMethod, final Action action, boolean update) {
217+
private void createMethod(final RestApi api, final Resource resource, final ActionType httpMethod, final Action action,
218+
final Map<String, UriParameter> requestParameters, boolean update) {
211219
Method method;
212220

213221
if (update && methodExists(resource, httpMethod.toString())) {
@@ -257,7 +265,7 @@ private void createMethod(final RestApi api, final Resource resource, final Acti
257265
method = resource.putMethod(input, httpMethod.toString());
258266
}
259267

260-
for (Map.Entry<String, UriParameter> entry : action.getResource().getUriParameters().entrySet()) {
268+
for (Map.Entry<String, UriParameter> entry : requestParameters.entrySet()) {
261269
updateMethod(api, method, "path", entry.getKey(), entry.getValue().isRequired());
262270
}
263271

0 commit comments

Comments
 (0)
This repository has been archived.