typespec
typespec copied to clipboard
tsp-openapi3 - prevent collisions when same name is used in Open API 3 components categories.
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
- [X] Follow our Code of Conduct
- [X] Check that there isn't already an issue that request the same bug to avoid creating a duplicate.
- [X] Check that this is a concrete bug. For Q&A open a GitHub Discussion.
- [X] The provided reproduction is a minimal reproducible example of the bug.
my vote here would be to get the Parameter suffix/namespace for parmaeters but keep schemas as they are