Skip to content

TopDownIndex doesn't retain order of operations #2699

@kubukoz

Description

@kubukoz

Related: #591 / #602 - the getOperations() method has been made to retain the order of operation in the service's original definition, but TopDownindex.getContainedOperations() didn't get the same treatment.

This results in unpredictable ordering, which has the same flaws as the previous behavior of getOperations.

For example, you can see the ordering change in the output of the following Scala script:

//> using scala 3.7.1
//> using dep software.amazon.smithy:smithy-model:1.60.3
//> using option -Wunused:all
import software.amazon.smithy.model.Model
import software.amazon.smithy.model.shapes.ShapeId
import software.amazon.smithy.model.knowledge.TopDownIndex
import software.amazon.smithy.model.shapes.ServiceShape

val m = Model
  .assembler()
  .addUnparsedModel(
    "test.smithy",
    """$version: "2"
      |namespace demo
      |
      |service DummyService {
      |    version: "0.0"
      |    operations: [
      |        DummyHostPrefix
      |        Dummy
      |        DummyPath
      |    ]
      |}
      |
      |
      |operation DummyHostPrefix {}
      |operation Dummy {}
      |operation DummyPath {}
      |""".stripMargin,
  )
  .assemble()
  .unwrap()
// m: Model = software.amazon.smithy.model.Model@90925b8

TopDownIndex
  .of(m)
  .getContainedOperations(ShapeId.from("demo#DummyService"))
// res0: Set[OperationShape] = [(operation: `demo#Dummy`), (operation: `demo#DummyHostPrefix`), (operation: `demo#DummyPath`)]

m.expectShape(ShapeId.from("demo#DummyService"), classOf[ServiceShape]).getOperations()
// res1: Set[ShapeId] = [demo#DummyHostPrefix, demo#Dummy, demo#DummyPath]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions