Skip to content

[Bug]: Unhelpful error message when missing @added decorator #3920

@mario-guerra

Description

@mario-guerra

Describe the bug

I'm revising the pet store example and encountered a cryptic error when I forgot to consistently use the '@added' decorator to specify versioning in operations added for the toy resource.

This code uses two instances of the @added decorator:

   // Operations under the 'toys' namespace are only available in v2 of the API
    @route("{petId}/toys/{toyId}")
    namespace Toys {
        @added(Versions.v2)
        @get
        op getToy(@path petId: int32, @path toyId: int32): OkResponse & {
            @body toy: Toy;
        } | NotFoundResponse & {
            @body error: NotFoundError;
        };
        
        @added(Versions.v2)
        @useAuth(BearerAuth)
        @put
        op updateToy(@path petId: int32, @path toyId: int32, @body toy: Toy): OkResponse & {
            @body updatedToy: Toy;
        } | NotFoundResponse & {
            @body error: NotFoundError;
        };
    }

If I remove the second @added decorator, I get the following error, which doesn't help me determine what the issue is:
error @typespec/openapi3/invalid-schema Couldn't get schema for type never <unknown location>:1:1

Can the error checking be improved to correctly identify the cause?

Reproduction

playground link to error case

playground link to working case

Checklist

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions