Skip to content
Merged
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
@@ -0,0 +1,7 @@
{
"type": "bugfix",
"description": "Fixed a bug in OpenAPI conversions where onErrorStatusConflict from mappers/protocols wasn't being respected.",
"pull_requests": [
"[#3123](https://github.com/smithy-lang/smithy/pull/3123)"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -187,13 +187,7 @@ private ConversionEnvironment<? extends Trait> createConversionEnvironment(Model
// Remove mixins from the model.
model = ModelTransformer.create().flattenAndRemoveMixins(model);

// Dejjjqconflict errors that share the same status code.
if (OpenApiConfig.ErrorStatusConflictHandlingStrategy.ONE_OF == config.getOnErrorStatusConflict()) {
model = ModelTransformer.create().deconflictErrorsWithSharedStatusCode(model, service);
}

JsonSchemaConverter.Builder jsonSchemaConverterBuilder = JsonSchemaConverter.builder();
jsonSchemaConverterBuilder.model(model);

// Discover OpenAPI extensions.
List<Smithy2OpenApiExtension> extensions = new ArrayList<>();
Expand All @@ -217,6 +211,14 @@ private ConversionEnvironment<? extends Trait> createConversionEnvironment(Model

// Update with protocol default values.
openApiProtocol.updateDefaultSettings(model, config);

// Deconflict errors that share the same status code. This must happen after
// updateDefaultSettings so that protocols can set onErrorStatusConflict.
if (OpenApiConfig.ErrorStatusConflictHandlingStrategy.ONE_OF == config.getOnErrorStatusConflict()) {
model = ModelTransformer.create().deconflictErrorsWithSharedStatusCode(model, service);
}

jsonSchemaConverterBuilder.model(model);
jsonSchemaConverterBuilder.config(config);

// Only convert shapes in the closure of the targeted service.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,32 @@ public void updateDefaultSettings(Model model, OpenApiConfig config) {
assertThat(config.getExtensions().getMember("hello"), not(Optional.empty()));
}

// Setting onErrorStatusConflict via updateDefaultSettings (rather than
// directly on the config) triggers error deconflicting in the output.
@Test
public void errorConflictStrategySetViaUpdateDefaultSettingsIsRespected() {
Model model = Model.assembler()
.addImport(getClass().getResource("protocols/error-code-collision-test.smithy"))
.discoverModels()
.assemble()
.unwrap();
OpenApiConfig config = new OpenApiConfig();
config.setService(ShapeId.from("example#Example"));
ObjectNode result = OpenApiConverter.create()
.config(config)
.addOpenApiMapper(new OpenApiMapper() {
@Override
public void updateDefaultSettings(Model m, OpenApiConfig c) {
c.setOnErrorStatusConflict(
OpenApiConfig.ErrorStatusConflictHandlingStrategy.ONE_OF);
}
})
.convertToNode(model);

String json = Node.printJson(result);
assertThat(json, containsString("oneOf"));
}

// The input structure needs a synthesized content structure. Since the
// path property is a "parameter" the synthesized structure must not list
// it as required because it is not part of the payload.
Expand Down
Loading