microsoft / typespec

https://typespec.io/
MIT License
4.5k stars 216 forks source link

Cannot provide allowEmptyValue/deprecated/example/examples/content on Openapi3 parameters #3928

Open skywing918 opened 3 months ago

skywing918 commented 3 months ago

Describe the bug

{The problematic object} failed to {describe the problem}.

TSP

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

using TypeSpec.Http;
using OpenAPI;

@service({
  title: "Style and Explode"
})
namespace StyleAndExplode;

model Widget {
  @visibility("read")
  id: string;
  weight?: int32;
  color?: "red" | "blue";
}

// TypeSpec supports certain combinations of the style and explode
// fields of parameter objects.

@tag("Widgets")
@route("/widgets")
namespace Widgets {
  // Header parameters
  @post op create(
    // has no style or explode
    @header apiVersion?: string,

    // has style: simple and no explode
    @header({format: "simple"}) xMsClientRequestId?: string,
  ): Widget;
}

Actual Specification

https://typespec.io/docs/getting-started/typespec-for-openapi-dev#openapi-v3 image image

openapi: 3.0.0
info:
  title: Style and Explode
  version: 0.0.0
tags:
  - name: Widgets
paths:
  /widgets:
    post:
      tags:
        - Widgets
      operationId: Widgets_create
      parameters:
        - name: api-version
          in: header
          required: false
          schema:
            type: string
        - name: x-ms-client-request-id
          in: header
          required: false
          schema:
            type: string
          style: simple
      responses:
        '200':
          description: The request has succeeded.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Widget'
components:
  schemas:
    Widget:
      type: object
      required:
        - id
      properties:
        id:
          type: string
          readOnly: true
        weight:
          type: integer
          format: int32
        color:
          type: string
          enum:
            - red
            - blue

Expected Specification

https://spec.openapis.org/oas/v3.0.0#parameter-object

Reproduction

  1. git clone https://github.com/skywing918/typespec-workaround.git
  2. tsp compile parameter.tsp
  3. Open /tsp-output/@typespec/openapi3 to get the result

Checklist

Arithmomaniac commented 2 weeks ago

The inability to add examples to parameters is discussed in #3873.

wanlwanl commented 1 week ago

Summary: