Skip to content

Commit 38dcc8b

Browse files
Chase Coalwellkstich
Chase Coalwell
authored andcommitted
Simplify suffix logic, add docs
1 parent d46a938 commit 38dcc8b

File tree

4 files changed

+36
-2
lines changed

4 files changed

+36
-2
lines changed

docs/source/1.0/guides/converting-to-openapi.rst

+20
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,26 @@ forbidGreedyLabels (``boolean``)
354354
}
355355
}
356356
357+
.. _generate-openapi-setting-removeGreedyParameterSuffix:
358+
359+
removeGreedyParameterSuffix (``boolean``)
360+
Set to true to remove the ``+`` suffix on the parameter name. By default, greedy
361+
labels will have a corresponding parameter name generated that will include
362+
the ``+`` suffix. Given a label "/{foo+}", the parameter name will be "foo+".
363+
If enabled, the parameter name will instead be "foo".
364+
365+
.. code-block:: json
366+
367+
{
368+
"version": "1.0",
369+
"plugins": {
370+
"openapi": {
371+
"service": "smithy.example#Weather",
372+
"removeGreedyParameterSuffix": true
373+
}
374+
}
375+
}
376+
357377
.. _generate-openapi-setting-onHttpPrefixHeaders:
358378

359379
onHttpPrefixHeaders (``string``)

smithy-aws-apigateway-openapi/src/main/java/software/amazon/smithy/aws/apigateway/openapi/AddDefaultRestConfigSettings.java

+3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222

2323
/**
2424
* REST APIs require that name parameters for greedy labels are not suffixed with "+".
25+
* @see <a href="https://docs.aws.amazon.com/apigateway/latest/developerguide/setup-http-integrations.html">REST APIs</a>
26+
* which is counter to the default, like for
27+
* <a href="https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-http.html">HTTP APIs</a>.
2528
*/
2629
final class AddDefaultRestConfigSettings implements ApiGatewayMapper {
2730
@Override

smithy-openapi/src/main/java/software/amazon/smithy/openapi/OpenApiConfig.java

+9
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,15 @@ public boolean getRemoveGreedyParameterSuffix() {
223223
return removeGreedyParameterSuffix;
224224
}
225225

226+
/**
227+
* Set to true to remove the "+" suffix that is added to the generated
228+
* parameter name for greedy labels.
229+
*
230+
* <p>By default, greedy labels will have a parameter name generated that
231+
* matches the label, including the "+" suffix.</p>
232+
* @param removeGreedyParameterSuffix Set to true to remove the "+" suffix
233+
* on generated parameter name.
234+
*/
226235
public void setRemoveGreedyParameterSuffix(boolean removeGreedyParameterSuffix) {
227236
this.removeGreedyParameterSuffix = removeGreedyParameterSuffix;
228237
}

smithy-openapi/src/main/java/software/amazon/smithy/openapi/fromsmithy/protocols/AbstractRestProtocol.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,10 @@ private List<ParameterObject> createPathParameters(Context<T> context, Operation
141141
// Some vendors/tooling, require the "+" suffix be excluded in the generated parameter.
142142
// If required, the setRemoveGreedyParameterSuffix config option should be set to `true`.
143143
// When this option is enabled, given "/{foo+}", the parameter name will be "foo".
144-
String name = (label.isGreedyLabel() && !context.getConfig().getRemoveGreedyParameterSuffix())
145-
? label.getContent() + "+" : label.getContent();
144+
String name = label.getContent();
145+
if (label.isGreedyLabel() && !context.getConfig().getRemoveGreedyParameterSuffix()) {
146+
name = name + "+";
147+
}
146148

147149
result.add(ModelUtils.createParameterMember(context, binding.getMember())
148150
.name(name)

0 commit comments

Comments
 (0)