Skip to content

[Bug]: @defaultResponse model included in return type union generates anyOf with duplicate $ref #10092

@happenslol

Description

@happenslol

Describe the bug

I wrap every return type in a Result alias, since it's not possible to define a global default error type, see #3082.

Since 1.7.0, this generates the following:

default:
  description: Server error
  content:
    application/json:
      schema:
        anyOf:
          - $ref: '#/components/schemas/DefaultError'
          - $ref: '#/components/schemas/DefaultError'

This is rejected by my OpenAPI codegen because of the duplicate indentical refs.

Here's what was generated on 1.6.0:

default:
  description: An unexpected error response.
  content:
    application/json:
      schema:
        $ref: '#/components/schemas/DefaultError'

The culprit seems to be @typespec/openapi3 v1.7.0 from what I can tell.

Reproduction

import "@typespec/http";
import "@typespec/openapi";
import "@typespec/openapi3";

using TypeSpec.Http;
using TypeSpec.OpenAPI;

@service(#{ title: "Repro" })
namespace Repro;

@error
model Error<Status> {
	@statusCode _: Status;
	message: string;
}

@error
@defaultResponse
model DefaultError is Error<500>;

alias Result<T> = T | DefaultError;

model Thing {
	id: string;
	name: string;
}

@route("/things")
namespace Things {
	@get op list(): Result<Thing[]>;
}

With the following versions:

"@typespec/compiler": "1.7.0",
"@typespec/http": "1.7.0",
"@typespec/openapi": "1.7.0",
"@typespec/openapi3": "1.7.0"

This generates the above with tsp compile ./main.tsp. Changing to openapi3@1.6.0 generates the correct version.

Checklist

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions