Conversation
| @SmithyUnstableApi | ||
| public final class TraitCodegenSettings { | ||
| private static final String SMITHY_KEYWORD = "smithy"; | ||
| private static final Set<String> RESERVED_NAMESPACES = SetUtils.of("smithy.api", "smithy.waiters", "smithy.test"); |
There was a problem hiding this comment.
You are missing some, the full list as of now is:
smithy.api
smithy.framework
smithy.mqtt
smithy.openapi
smithy.protocols
smithy.rules
smithy.test
smithy.waiters
There was a problem hiding this comment.
Ack. Are these from just the github search? Or some other mechanism you used?
There was a problem hiding this comment.
A shell script:
find . -name \*.smithy | xargs egrep '^namespace ' | grep ' smithy.' | cut -d: -f2 | grep -v ' test' | grep -v example | sort | uniq | cut -d ' ' -f2 | cut -d '.' -f1,2 | uniq
There was a problem hiding this comment.
I have updated the namespace list.
| @SmithyUnstableApi | ||
| public final class TraitCodegenSettings { | ||
| private static final String SMITHY_KEYWORD = "smithy"; | ||
| private static final Set<String> RESERVED_NAMESPACES = SetUtils.of("smithy.api", "smithy.waiters", "smithy.test"); |
There was a problem hiding this comment.
This needs several other sub-namespaces: .mqtt, .openapi, .protocols, .rules, .framework
There was a problem hiding this comment.
I have updated the namespace list.
…w smithy specific namespaces.
3e8765f to
757fc0d
Compare
| * @return true if the namespace is reserved, false otherwise | ||
| */ | ||
| private static boolean isReservedNamespace(String namespace) { | ||
| String namespaceLowerCase = namespace.toLowerCase(Locale.ROOT); |
There was a problem hiding this comment.
Let's remove this conversion, namespaces are case sensitive.
There was a problem hiding this comment.
Confirmed offline that this needs to be case sensitive.
There was a problem hiding this comment.
Yeah, while namespaces are case-sensitive, the rationale of this was anyone should be forbidden from creating a trait with SMITHY or SMITHY.API or other versions of it as it conflicts with our reserved namespaces.
I am leaning towards blocking those case-insensitively. @mtdowling and I discussed, the reasoning for case-insensitive checking is that shapes are case-insensitive.
FWIW, for future record putting this here from our docs :
While shape ID references within the semantic model are case-sensitive, no two shapes in the semantic model can have the same case-insensitive shape ID. This restriction makes it easier to use Smithy models for code generation in programming languages that do not support case-sensitive identifiers or that perform some kind of normalization on generated identifiers (for example, a Python code generator might convert all member names to lower snake case). To illustrate, com.Foo#baz and com.foo#BAZ are not allowed in the same semantic model. This restriction also extends to member names: com.foo#Baz$bar and com.foo#Baz$BAR are in conflict.
Background
• What do these changes do?
Adds validation to prevent trait code generation on
smithykeyword itself or reserved Smithy namespaces (smithy.api,smithy.waiters,smithy.test) and their sub-namespaces but we still want to allow namespaces likesmithy.fooorsmithy.rules.This change adds a RESERVED_NAMESPACES set to act as a deny list for future extensibility.
For instance:
smithy-> not allowedsmithy.api,smithy.waiters, andsmithy.test-> not allowedsmithy.foo,smithyfoo.bar, -> allowed• Why are they important?
Prevents namespace conflicts with core Smithy functionality and protects framework integrity by blocking user code generation on reserved namespaces.
Testing
• How did you test these changes?
Added comprehensive unit tests covering reserved namespace validation, case-insensitive matching, edge cases, and legitimate namespace acceptance.
Links
• No related issues
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.