typespec icon indicating copy to clipboard operation
typespec copied to clipboard

tsp-openapi3 - prevent collisions when same name is used in Open API 3 components categories.

Open chrisradek opened this issue 1 year ago • 1 comments

Describe the bug

Open API 3 allows defining schemas, parameters, and other shared entities in #/components. It's valid to have a schema named Foo, and then a parameter also named Foo that references the schema.

When such collisions occur, tsp-openapi3 behaves unexpectedly by trying to merge the parameter-associated TypeSpec model with whatever the schema-associated TypeSpec type is. This can cause very confusing output when the referenced parameter schema is not an object.

Reproduction

openapi: 3.0.0
info:
  title: Widget Service
  version: 0.0.0
tags: []
paths:
  /{id}:
    get:
      operationId: Widgets_read
      parameters:
        - $ref: "#/components/parameters/Foo"
      responses:
        "200":
          description: The request has succeeded.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Foo"
components:
  schemas:
    Foo:
      type: string
  parameters:
    Foo:
      name: foo
      in: query
      required: true
      schema:
        type: arrray
        item:
          - $ref: "#/components/schemas/Foo"

This generates the following Foo:

scalar Foo extends string;
@query foo: unknown;

Checklist

chrisradek avatar Aug 12 '24 22:08 chrisradek

my vote here would be to get the Parameter suffix/namespace for parmaeters but keep schemas as they are

timotheeguerin avatar Aug 13 '24 18:08 timotheeguerin