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 synthetic schema naming #695

Merged
merged 5 commits into from
Jan 28, 2021

Conversation

srchase
Copy link
Contributor

@srchase srchase commented Jan 26, 2021

Some vendors, including Amazon API Gateway, require that shape names are alphanumeric only.

This PR assures that the synthesized ResponseContent and RequestContent shapes have alphanumeric names when the alphanumericOnlyRefs configuration setting has been set to true, as with smithy-aws-apigateway-openapi. The descriptions on schemas are updated to match when non-alphanumeric characters have been removed.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@srchase srchase requested review from mtdowling and JordonPhillips and removed request for mtdowling January 26, 2021 22:35
String pointer = context.putSynthesizedSchema(synthesizedName, schema);
MediaTypeObject mediaTypeObject = MediaTypeObject.builder()
.schema(Schema.builder().ref(pointer).build())
.build();

responseBuilder.putContent(mediaType, mediaTypeObject);
}

private String stripNonAlphaNumericCharsIfNecessary(Context<T> context, String name) {
return context.getConfig().getAlphanumericOnlyRefs()
Copy link
Contributor

Choose a reason for hiding this comment

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

Gonna want to at least log an info / warning here saying what's happening

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added logging in cd8a781.

InputStream openApiStream = getClass().getResourceAsStream(openApiModel);

if (openApiStream == null) {
LOGGER.warning("OpenAPI model not found for test case: " + openApiModel);
Copy link
Contributor

Choose a reason for hiding this comment

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

you should fail the test here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I updated all the cases to fail in 5333705.

Copy link
Contributor

@JordonPhillips JordonPhillips left a comment

Choose a reason for hiding this comment

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

Feel free to merge when the log message is updated

: name;
String alphanumericOnly = NON_ALPHA_NUMERIC.matcher(name).replaceAll("");
if (context.getConfig().getAlphanumericOnlyRefs() && !alphanumericOnly.equals(name)) {
LOGGER.info("Removing non-alphanumeric characters from " + name);
Copy link
Contributor

Choose a reason for hiding this comment

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

This should say why you're doing that

@srchase srchase merged commit aee706f into smithy-lang:main Jan 28, 2021
@srchase srchase deleted the fix-synthetic-schema-naming branch January 28, 2021 18:17
@kstich kstich mentioned this pull request Feb 22, 2021
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