Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix for discriminated union transform #176

Merged
merged 2 commits into from
Jul 17, 2024
Merged

Conversation

lewisjkl
Copy link
Contributor

This fixes an issue with there being two shapes from different namespaces with the same name where one of them is a discriminated union. The discriminated union transformation added in #173 did not use a full ShapeId for determining which shape is which, but rather only a name. There is no direct way to handle this, thus I used the OpenAPI extensions to carry the ShapeId and used that. See the files for more commentary about this.

val componentSchemas: Map[String, Schema] = openapi
val componentSchemas: Map[ShapeId, Schema] = openapi
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change to using full ShapeId instead of just shape name

@@ -130,6 +137,7 @@ class DiscriminatedUnionMemberComponents() extends OpenApiMapper {
.asJava
)
schemaBuilder
.removeExtension(DiscriminatedUnionShapeId.SHAPE_ID_KEY)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the extension so it is not included in the final OpenAPI file


import software.amazon.smithy.model.node.Node

class DiscriminatedUnionShapeId() extends JsonSchemaMapper {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A JsonSchemaMapper has to be used to get access to the full ShapeId, OpenAPI mappers do not have this information available (as far as I can tell).

@lewisjkl lewisjkl requested a review from Baccata July 16, 2024 22:12
@Baccata Baccata merged commit 7745181 into main Jul 17, 2024
3 checks passed
@lewisjkl lewisjkl deleted the discriminated-unions-fix branch July 17, 2024 17:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants