Error in TypeSpec Code: duplicate-property: Model already has a property named #3531
-
When I write the code as below, I get an error import "@typespec/http";
using TypeSpec.Http;
@tag("Country")
@route("/countries")
interface Countries {
@route("{countryCode}/update") @post update(@path countryCode: string, ...Country): void | Error;
}
@doc("Country")
model Country {
@doc("countryCode")
countryCode: string;
@doc("countryName")
countryName: string;
}
Is it not possible to use a property name from the model as a path parameter? |
Beta Was this translation helpful? Give feedback.
Answered by
timotheeguerin
Jun 6, 2024
Replies: 1 comment 1 reply
-
Depending on what you exactly want to do here, there is 2 options import "@typespec/http";
using TypeSpec.Http;
// Option 1 - here you reuse the same property
@route("1/{countryCode}/update") op read1(...Country1): void;
model Country1 {
@path countryCode: string;
countryName: string;
}
// Option 2 - here the country is just the body and you still have an explicit path param
@route("2/{countryCode}/update") op read2(
@path countryCode: string,
@body country: Country2,
): void;
model Country2 {
countryCode: string;
countryName: string;
} |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
yasu7ri
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Depending on what you exactly want to do here, there is 2 options
Playground example