typespec icon indicating copy to clipboard operation
typespec copied to clipboard

[Bug]: Confusion on field annotation for inherited models (protobuf)

Open 0237h opened this issue 1 year ago • 0 comments

Describe the bug

The annotation of fields for inherited models targeting a protobuf emitter is a bit confusing.

import "@typespec/protobuf";

using TypeSpec.Protobuf;

@package({
  name: "test",
})
namespace test;

model Parent {
    id: int64
}

model Child1 is Parent {} // Not working
@@field(Child1.id, 1);

model Child2 extends Parent {} // Outputs empty `message`
@@field(Child2.id, 1);

model Child3 { // Correct
    ...Parent
}
@@field(Child3.id, 1);

I couldn't figure out from the documentation why only Child3 would yield the correct result. From what I've tested, it seems that for Child1 and Child2 there is a failure to recognize and tag the id field appropriately.

This is especially confusing since I'm using this for generating openapi3 specs (through @typespec/http) as well, with syntax of Child1 working as expected.

Any insights as to whether this is a bug or just a misunderstanding of the language would be appreciated thanks !

Reproduction

https://typespec.io/playground?options=%7B%22linterRuleSet%22%3A%7B%22extends%22%3A%5B%22%40typespec%2Fhttp%2Fall%22%5D%7D%7D&c=aW1wb3J0ICJAdHlwZXNwZWMvcHJvdG9idWYiOwoKdXNpbmcgVHlwZVNwZWMuUMcbOwoKQHBhY2thZ2UoewogIG5hbWU6ICJ0ZXN0IiwKfSkKxBFzcGFjZSDEFDsKCm1vZGVsIFBhcmVudCB7CglpZDogaW50NjQKfcgdQ2hpbGQxIGlzySd9CkBAZmllbGQoxhwuaWQsIDEpyU%2FFFjIgZXh0ZW5k2Tcy1Tcz5ACGLi4uxjUKzzQzyDQ%3D&e=%40typespec%2Fprotobuf

Checklist

0237h avatar May 03 '24 19:05 0237h