Skip to content

Commit

Permalink
Remove doc hidden from struct fields (#2854)
Browse files Browse the repository at this point in the history
## Motivation and Context
Removes `#[doc(hidden)]` from struct fields.

## Testing
- [ ] Passed tests in CI

## Checklist
- [x] I have updated `CHANGELOG.next.toml` if I made changes to the
smithy-rs codegen or runtime crates

----

_By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice._

---------

Co-authored-by: ysaito1001 <[email protected]>
  • Loading branch information
ysaito1001 and ysaito1001 authored Jul 19, 2023
1 parent fabef2b commit 27df48f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 19 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.next.toml
Original file line number Diff line number Diff line change
Expand Up @@ -646,3 +646,9 @@ message = "The implementation `From<bytes_utils::segmented::SegmentedBuf>` for `
references = ["smithy-rs#2848"]
meta = { "breaking" = true, "tada" = false, "bug" = false, "target" = "client" }
author = "ysaito1001"

[[smithy-rs]]
message = "Public fields in structs are no longer marked as `#[doc(hidden)]`, and they are now visible."
references = ["smithy-rs#2854"]
meta = { "breaking" = false, "tada" = false, "bug" = false, "target" = "client" }
author = "ysaito1001"
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import software.amazon.smithy.model.shapes.StructureShape
import software.amazon.smithy.model.shapes.UnionShape
import software.amazon.smithy.model.traits.EnumTrait
import software.amazon.smithy.model.traits.SensitiveTrait
import software.amazon.smithy.model.traits.StreamingTrait
import software.amazon.smithy.rust.codegen.core.rustlang.Attribute
import software.amazon.smithy.rust.codegen.core.rustlang.RustMetadata
import software.amazon.smithy.rust.codegen.core.rustlang.Visibility
Expand Down Expand Up @@ -99,19 +98,7 @@ class BaseSymbolMetadataProvider(

override fun memberMeta(memberShape: MemberShape): RustMetadata =
when (val container = model.expectShape(memberShape.container)) {
is StructureShape -> {
// TODO(https://github.com/awslabs/smithy-rs/issues/943): Once streaming accessors are usable,
// then also make streaming members `#[doc(hidden)]`
if (memberShape.getMemberTrait(model, StreamingTrait::class.java).isPresent) {
RustMetadata(visibility = Visibility.PUBLIC)
} else {
RustMetadata(
// At some point, visibility _may_ be made `PRIVATE`, so make these `#[doc(hidden)]` for now.
visibility = Visibility.PUBLIC,
additionalAttributes = listOf(Attribute.DocHidden),
)
}
}
is StructureShape -> RustMetadata(visibility = Visibility.PUBLIC)

is UnionShape, is CollectionShape, is MapShape -> RustMetadata(visibility = Visibility.PUBLIC)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ package software.amazon.smithy.rust.codegen.core.smithy.generators

import io.kotest.matchers.string.shouldContainInOrder
import io.kotest.matchers.string.shouldNotContain
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test
import software.amazon.smithy.model.shapes.StructureShape
import software.amazon.smithy.rust.codegen.core.rustlang.Attribute
Expand Down Expand Up @@ -401,7 +400,7 @@ class StructureGeneratorTest {
}

@Test
fun `non-streaming fields are doc-hidden`() {
fun `fields are NOT doc-hidden`() {
val model = """
namespace com.test
structure MyStruct {
Expand All @@ -415,9 +414,9 @@ class StructureGeneratorTest {
val struct = model.lookup<StructureShape>("com.test#MyStruct")

val provider = testSymbolProvider(model, rustReservedWordConfig = rustReservedWordConfig)
RustWriter.forModule("test").let {
StructureGenerator(model, provider, it, struct, emptyList()).render()
assertEquals(6, it.toString().split("#[doc(hidden)]").size, "there should be 5 doc-hiddens")
RustWriter.forModule("test").let { writer ->
StructureGenerator(model, provider, writer, struct, emptyList()).render()
writer.toString().shouldNotContain("#[doc(hidden)]")
}
}

Expand Down

0 comments on commit 27df48f

Please sign in to comment.