Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: OpenAPI3 does not output correct names for unions declared within a namespace #4122

Closed
4 tasks done
jacobroschen opened this issue Aug 8, 2024 · 0 comments · Fixed by #4123
Closed
4 tasks done
Labels
bug Something isn't working needs-area

Comments

@jacobroschen
Copy link
Contributor

Describe the bug

Union types do not follow the same naming rules as other types such as Model when declared within a namespace. This appears to be a regression that was introduced in 0.51.0, specifically the conversion of OpenAPI3 to the EmitterFramework.

0.50.x playground (correct)
0.51.x playground (incorrect)

This also contradicts the TypeSpec OpenAPI3 Emitter documentation, which states the following.

Inline defined models will result in an inline schema. Explicitly declared models will be defined in the components/schemas section with the TypeSpec name qualified by any enclosing namespaces.

Tsp

import "@typespec/openapi3";

using OpenAPI;

namespace Space1 {
  model Bar {
    bar?: string;
  }

  union Foo {
    foo: int32,
  }
}

@service
namespace Space2 {
  op create(p1?: Space1.Bar, p2?: Space1.Foo): {};
}

Actual Specification

openapi: 3.0.0
info:
  title: (title)
  version: 0.0.0
tags: []
paths:
  /:
    post:
      operationId: create
      parameters: []
      responses:
        '200':
          description: The request has succeeded.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                p1:
                  $ref: '#/components/schemas/Space1.Bar'
                p2:
                  $ref: '#/components/schemas/Foo'
components:
  schemas:
    Foo:
      type: integer
      format: int32
    Space1.Bar:
      type: object
      properties:
        bar:
          type: string

Note that the union Foo is not prefixed with its namespace Space1 when included in components.schemas. I expected it to be included as Space1.Foo, like Space1.Bar.

Expected Specification

openapi: 3.0.0
info:
  title: (title)
  version: 0.0.0
tags: []
paths:
  /:
    post:
      operationId: create
      parameters: []
      responses:
        '200':
          description: The request has succeeded.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                p1:
                  $ref: '#/components/schemas/Space1.Bar'
                p2:
                  $ref: '#/components/schemas/Space1.Foo'
components:
  schemas:
    Space1.Foo:
      type: integer
      format: int32
    Space1.Bar:
      type: object
      properties:
        bar:
          type: string

Reproduction

https://cadlplayground.z22.web.core.windows.net/?c=aW1wb3J0ICJAdHlwZXNwZWMvb3BlbmFwaTMiOw0KDQp1c2luZyBPcGVuQVBJxRJuYW1lc3BhY2UgU8QGMSB7DQogIG1vZGVsIEJhcsYPICBiYXI%2FOiBzdHJpbmc7xBN9xD0gIHVuaW9uIEZvb8gpZm9vOiBpbnQzMizHJ8UqQHNlcnZpY2XRcTLGOW9wIGNyZWF0ZShwMT86xhsxLkJhciwgcDLKEUZvbyk6IHt9Ow0KfQ%3D%3D&e=%40typespec%2Fopenapi3&options=%7B%7D

Checklist

@jacobroschen jacobroschen added the bug Something isn't working label Aug 8, 2024
jacobroschen added a commit to jacobroschen/typespec that referenced this issue Aug 8, 2024
jacobroschen added a commit to jacobroschen/typespec that referenced this issue Aug 8, 2024
jacobroschen added a commit to jacobroschen/typespec that referenced this issue Aug 8, 2024
jacobroschen added a commit to jacobroschen/typespec that referenced this issue Aug 8, 2024
jacobroschen added a commit to jacobroschen/typespec that referenced this issue Aug 8, 2024
jacobroschen added a commit to jacobroschen/typespec that referenced this issue Aug 8, 2024
github-merge-queue bot pushed a commit that referenced this issue Aug 8, 2024
fix #4122

---------

Co-authored-by: Timothee Guerin <tiguerin@microsoft.com>
github-merge-queue bot pushed a commit that referenced this issue Aug 8, 2024
fix #4122

---------

Co-authored-by: Timothee Guerin <tiguerin@microsoft.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs-area
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant