Loading codegen-core/common-test-models/constraints.smithy +41 −0 Original line number Diff line number Diff line Loading @@ -445,6 +445,11 @@ structure ConA { maxLengthString: MaxLengthString, fixedLengthString: FixedLengthString, lengthBlob: LengthBlob, minLengthBlob: MinLengthBlob, maxLengthBlob: MaxLengthBlob, fixedLengthBlob: FixedLengthBlob, rangeInteger: RangeInteger, minRangeInteger: MinRangeInteger, maxRangeInteger: MaxRangeInteger, Loading Loading @@ -486,6 +491,12 @@ structure ConA { // setOfLengthString: SetOfLengthString, mapOfLengthString: MapOfLengthString, listOfLengthBlob: ListOfLengthBlob, // TODO(https://github.com/awslabs/smithy-rs/issues/1401): a `set` shape is // just a `list` shape with `uniqueItems`, which hasn't been implemented yet. // setOfLengthBlob: SetOfLengthBlob, mapOfLengthBlob: MapOfLengthBlob, listOfRangeInteger: ListOfRangeInteger, // TODO(https://github.com/awslabs/smithy-rs/issues/1401): a `set` shape is // just a `list` shape with `uniqueItems`, which hasn't been implemented yet. Loading Loading @@ -532,6 +543,11 @@ structure ConA { // lengthSetOfPatternString: LengthSetOfPatternString, } map MapOfLengthBlob { key: String, value: LengthBlob, } map MapOfLengthString { key: LengthString, value: LengthString, Loading Loading @@ -640,6 +656,23 @@ string MaxLengthString @length(min: 69, max: 69) string FixedLengthString @length(min: 2, max: 8) list LengthListOfLengthBlob { member: LengthBlob } @length(min: 2, max: 70) blob LengthBlob @length(min: 2) blob MinLengthBlob @length(max: 70) blob MaxLengthBlob @length(min: 70, max: 70) blob FixedLengthBlob @pattern("[a-d]{5}") string PatternString Loading Loading @@ -732,6 +765,10 @@ set SetOfLengthString { member: LengthString } set SetOfLengthBlob { member: LengthBlob } set SetOfPatternString { member: PatternString } Loading @@ -749,6 +786,10 @@ list ListOfLengthString { member: LengthString } list ListOfLengthBlob { member: LengthBlob } // TODO(https://github.com/awslabs/smithy-rs/issues/1401): a `set` shape is // just a `list` shape with `uniqueItems`, which hasn't been implemented yet. // set SetOfRangeInteger { Loading codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/parse/JsonParserGenerator.kt +4 −1 Original line number Diff line number Diff line Loading @@ -28,12 +28,14 @@ import software.amazon.smithy.rust.codegen.core.rustlang.RustModule import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter import software.amazon.smithy.rust.codegen.core.rustlang.Writable import software.amazon.smithy.rust.codegen.core.rustlang.escape import software.amazon.smithy.rust.codegen.core.rustlang.render import software.amazon.smithy.rust.codegen.core.rustlang.rust import software.amazon.smithy.rust.codegen.core.rustlang.rustBlock import software.amazon.smithy.rust.codegen.core.rustlang.rustBlockTemplate import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate import software.amazon.smithy.rust.codegen.core.rustlang.withBlock import software.amazon.smithy.rust.codegen.core.rustlang.withBlockTemplate import software.amazon.smithy.rust.codegen.core.rustlang.writable import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext import software.amazon.smithy.rust.codegen.core.smithy.CodegenTarget import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType Loading @@ -49,6 +51,7 @@ import software.amazon.smithy.rust.codegen.core.smithy.isRustBoxed import software.amazon.smithy.rust.codegen.core.smithy.protocols.HttpBindingResolver import software.amazon.smithy.rust.codegen.core.smithy.protocols.HttpLocation import software.amazon.smithy.rust.codegen.core.smithy.protocols.deserializeFunctionName import software.amazon.smithy.rust.codegen.core.smithy.rustType import software.amazon.smithy.rust.codegen.core.util.PANIC import software.amazon.smithy.rust.codegen.core.util.dq import software.amazon.smithy.rust.codegen.core.util.hasTrait Loading Loading @@ -296,7 +299,7 @@ class JsonParserGenerator( private fun RustWriter.deserializeBlob(target: BlobShape) { rustTemplate( "#{expect_blob_or_null}(tokens.next())?#{ConvertFrom:W}", "ConvertFrom" to typeConversionGenerator.convertViaFrom(target), "ConvertFrom" to writable { RuntimeType.blob(runtimeConfig).toSymbol().rustType().render() }, *codegenScope, ) } Loading codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/ConstrainedShapeSymbolProvider.kt +2 −1 Original line number Diff line number Diff line Loading @@ -8,6 +8,7 @@ package software.amazon.smithy.rust.codegen.server.smithy import software.amazon.smithy.codegen.core.Symbol import software.amazon.smithy.model.Model import software.amazon.smithy.model.knowledge.NullableIndex import software.amazon.smithy.model.shapes.BlobShape import software.amazon.smithy.model.shapes.ByteShape import software.amazon.smithy.model.shapes.CollectionShape import software.amazon.smithy.model.shapes.IntegerShape Loading Loading @@ -99,7 +100,7 @@ class ConstrainedShapeSymbolProvider( } } is StringShape, is IntegerShape, is ShortShape, is LongShape, is ByteShape -> { is StringShape, is IntegerShape, is ShortShape, is LongShape, is ByteShape, is BlobShape -> { if (shape.isDirectlyConstrained(base)) { val rustType = RustType.Opaque(shape.contextName(serviceShape).toPascalCase()) symbolBuilder(shape, rustType).locatedIn(ModelsModule).build() Loading codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/ConstraintViolationSymbolProvider.kt +2 −1 Original line number Diff line number Diff line Loading @@ -7,6 +7,7 @@ package software.amazon.smithy.rust.codegen.server.smithy import software.amazon.smithy.codegen.core.Symbol import software.amazon.smithy.model.Model import software.amazon.smithy.model.shapes.BlobShape import software.amazon.smithy.model.shapes.ByteShape import software.amazon.smithy.model.shapes.CollectionShape import software.amazon.smithy.model.shapes.IntegerShape Loading Loading @@ -127,7 +128,7 @@ class ConstraintViolationSymbolProvider( .build() } is StringShape, is IntegerShape, is ShortShape, is LongShape, is ByteShape -> { is StringShape, is IntegerShape, is ShortShape, is LongShape, is ByteShape, is BlobShape -> { val module = shape.shapeModule() val rustType = RustType.Opaque(constraintViolationName, module.fullyQualifiedPath()) Symbol.builder() Loading codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/Constraints.kt +3 −0 Original line number Diff line number Diff line Loading @@ -8,6 +8,7 @@ package software.amazon.smithy.rust.codegen.server.smithy import software.amazon.smithy.codegen.core.SymbolProvider import software.amazon.smithy.model.Model import software.amazon.smithy.model.neighbor.Walker import software.amazon.smithy.model.shapes.BlobShape import software.amazon.smithy.model.shapes.ByteShape import software.amazon.smithy.model.shapes.CollectionShape import software.amazon.smithy.model.shapes.IntegerShape Loading Loading @@ -90,6 +91,7 @@ fun Shape.isDirectlyConstrained(symbolProvider: SymbolProvider): Boolean = when is StringShape -> this.hasTrait<EnumTrait>() || supportedStringConstraintTraits.any { this.hasTrait(it) } is CollectionShape -> supportedCollectionConstraintTraits.any { this.hasTrait(it) } is IntegerShape, is ShortShape, is LongShape, is ByteShape -> this.hasTrait<RangeTrait>() is BlobShape -> this.hasTrait<LengthTrait>() else -> false } Loading Loading @@ -118,6 +120,7 @@ fun Shape.hasPublicConstrainedWrapperTupleType(model: Model, publicConstrainedTy is StringShape -> !this.hasTrait<EnumTrait>() && (publicConstrainedTypes && supportedStringConstraintTraits.any(this::hasTrait)) is IntegerShape, is ShortShape, is LongShape, is ByteShape -> publicConstrainedTypes && this.hasTrait<RangeTrait>() is MemberShape -> model.expectShape(this.target).hasPublicConstrainedWrapperTupleType(model, publicConstrainedTypes) is BlobShape -> publicConstrainedTypes && this.hasTrait<LengthTrait>() else -> false } Loading Loading
codegen-core/common-test-models/constraints.smithy +41 −0 Original line number Diff line number Diff line Loading @@ -445,6 +445,11 @@ structure ConA { maxLengthString: MaxLengthString, fixedLengthString: FixedLengthString, lengthBlob: LengthBlob, minLengthBlob: MinLengthBlob, maxLengthBlob: MaxLengthBlob, fixedLengthBlob: FixedLengthBlob, rangeInteger: RangeInteger, minRangeInteger: MinRangeInteger, maxRangeInteger: MaxRangeInteger, Loading Loading @@ -486,6 +491,12 @@ structure ConA { // setOfLengthString: SetOfLengthString, mapOfLengthString: MapOfLengthString, listOfLengthBlob: ListOfLengthBlob, // TODO(https://github.com/awslabs/smithy-rs/issues/1401): a `set` shape is // just a `list` shape with `uniqueItems`, which hasn't been implemented yet. // setOfLengthBlob: SetOfLengthBlob, mapOfLengthBlob: MapOfLengthBlob, listOfRangeInteger: ListOfRangeInteger, // TODO(https://github.com/awslabs/smithy-rs/issues/1401): a `set` shape is // just a `list` shape with `uniqueItems`, which hasn't been implemented yet. Loading Loading @@ -532,6 +543,11 @@ structure ConA { // lengthSetOfPatternString: LengthSetOfPatternString, } map MapOfLengthBlob { key: String, value: LengthBlob, } map MapOfLengthString { key: LengthString, value: LengthString, Loading Loading @@ -640,6 +656,23 @@ string MaxLengthString @length(min: 69, max: 69) string FixedLengthString @length(min: 2, max: 8) list LengthListOfLengthBlob { member: LengthBlob } @length(min: 2, max: 70) blob LengthBlob @length(min: 2) blob MinLengthBlob @length(max: 70) blob MaxLengthBlob @length(min: 70, max: 70) blob FixedLengthBlob @pattern("[a-d]{5}") string PatternString Loading Loading @@ -732,6 +765,10 @@ set SetOfLengthString { member: LengthString } set SetOfLengthBlob { member: LengthBlob } set SetOfPatternString { member: PatternString } Loading @@ -749,6 +786,10 @@ list ListOfLengthString { member: LengthString } list ListOfLengthBlob { member: LengthBlob } // TODO(https://github.com/awslabs/smithy-rs/issues/1401): a `set` shape is // just a `list` shape with `uniqueItems`, which hasn't been implemented yet. // set SetOfRangeInteger { Loading
codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/parse/JsonParserGenerator.kt +4 −1 Original line number Diff line number Diff line Loading @@ -28,12 +28,14 @@ import software.amazon.smithy.rust.codegen.core.rustlang.RustModule import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter import software.amazon.smithy.rust.codegen.core.rustlang.Writable import software.amazon.smithy.rust.codegen.core.rustlang.escape import software.amazon.smithy.rust.codegen.core.rustlang.render import software.amazon.smithy.rust.codegen.core.rustlang.rust import software.amazon.smithy.rust.codegen.core.rustlang.rustBlock import software.amazon.smithy.rust.codegen.core.rustlang.rustBlockTemplate import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate import software.amazon.smithy.rust.codegen.core.rustlang.withBlock import software.amazon.smithy.rust.codegen.core.rustlang.withBlockTemplate import software.amazon.smithy.rust.codegen.core.rustlang.writable import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext import software.amazon.smithy.rust.codegen.core.smithy.CodegenTarget import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType Loading @@ -49,6 +51,7 @@ import software.amazon.smithy.rust.codegen.core.smithy.isRustBoxed import software.amazon.smithy.rust.codegen.core.smithy.protocols.HttpBindingResolver import software.amazon.smithy.rust.codegen.core.smithy.protocols.HttpLocation import software.amazon.smithy.rust.codegen.core.smithy.protocols.deserializeFunctionName import software.amazon.smithy.rust.codegen.core.smithy.rustType import software.amazon.smithy.rust.codegen.core.util.PANIC import software.amazon.smithy.rust.codegen.core.util.dq import software.amazon.smithy.rust.codegen.core.util.hasTrait Loading Loading @@ -296,7 +299,7 @@ class JsonParserGenerator( private fun RustWriter.deserializeBlob(target: BlobShape) { rustTemplate( "#{expect_blob_or_null}(tokens.next())?#{ConvertFrom:W}", "ConvertFrom" to typeConversionGenerator.convertViaFrom(target), "ConvertFrom" to writable { RuntimeType.blob(runtimeConfig).toSymbol().rustType().render() }, *codegenScope, ) } Loading
codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/ConstrainedShapeSymbolProvider.kt +2 −1 Original line number Diff line number Diff line Loading @@ -8,6 +8,7 @@ package software.amazon.smithy.rust.codegen.server.smithy import software.amazon.smithy.codegen.core.Symbol import software.amazon.smithy.model.Model import software.amazon.smithy.model.knowledge.NullableIndex import software.amazon.smithy.model.shapes.BlobShape import software.amazon.smithy.model.shapes.ByteShape import software.amazon.smithy.model.shapes.CollectionShape import software.amazon.smithy.model.shapes.IntegerShape Loading Loading @@ -99,7 +100,7 @@ class ConstrainedShapeSymbolProvider( } } is StringShape, is IntegerShape, is ShortShape, is LongShape, is ByteShape -> { is StringShape, is IntegerShape, is ShortShape, is LongShape, is ByteShape, is BlobShape -> { if (shape.isDirectlyConstrained(base)) { val rustType = RustType.Opaque(shape.contextName(serviceShape).toPascalCase()) symbolBuilder(shape, rustType).locatedIn(ModelsModule).build() Loading
codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/ConstraintViolationSymbolProvider.kt +2 −1 Original line number Diff line number Diff line Loading @@ -7,6 +7,7 @@ package software.amazon.smithy.rust.codegen.server.smithy import software.amazon.smithy.codegen.core.Symbol import software.amazon.smithy.model.Model import software.amazon.smithy.model.shapes.BlobShape import software.amazon.smithy.model.shapes.ByteShape import software.amazon.smithy.model.shapes.CollectionShape import software.amazon.smithy.model.shapes.IntegerShape Loading Loading @@ -127,7 +128,7 @@ class ConstraintViolationSymbolProvider( .build() } is StringShape, is IntegerShape, is ShortShape, is LongShape, is ByteShape -> { is StringShape, is IntegerShape, is ShortShape, is LongShape, is ByteShape, is BlobShape -> { val module = shape.shapeModule() val rustType = RustType.Opaque(constraintViolationName, module.fullyQualifiedPath()) Symbol.builder() Loading
codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/Constraints.kt +3 −0 Original line number Diff line number Diff line Loading @@ -8,6 +8,7 @@ package software.amazon.smithy.rust.codegen.server.smithy import software.amazon.smithy.codegen.core.SymbolProvider import software.amazon.smithy.model.Model import software.amazon.smithy.model.neighbor.Walker import software.amazon.smithy.model.shapes.BlobShape import software.amazon.smithy.model.shapes.ByteShape import software.amazon.smithy.model.shapes.CollectionShape import software.amazon.smithy.model.shapes.IntegerShape Loading Loading @@ -90,6 +91,7 @@ fun Shape.isDirectlyConstrained(symbolProvider: SymbolProvider): Boolean = when is StringShape -> this.hasTrait<EnumTrait>() || supportedStringConstraintTraits.any { this.hasTrait(it) } is CollectionShape -> supportedCollectionConstraintTraits.any { this.hasTrait(it) } is IntegerShape, is ShortShape, is LongShape, is ByteShape -> this.hasTrait<RangeTrait>() is BlobShape -> this.hasTrait<LengthTrait>() else -> false } Loading Loading @@ -118,6 +120,7 @@ fun Shape.hasPublicConstrainedWrapperTupleType(model: Model, publicConstrainedTy is StringShape -> !this.hasTrait<EnumTrait>() && (publicConstrainedTypes && supportedStringConstraintTraits.any(this::hasTrait)) is IntegerShape, is ShortShape, is LongShape, is ByteShape -> publicConstrainedTypes && this.hasTrait<RangeTrait>() is MemberShape -> model.expectShape(this.target).hasPublicConstrainedWrapperTupleType(model, publicConstrainedTypes) is BlobShape -> publicConstrainedTypes && this.hasTrait<LengthTrait>() else -> false } Loading