Skip to content

error decorator should be added to error response schema when importing from OpenAPI #10785

@baywet

Description

@baywet

Importing the following OpenAPI description

openapi: 3.0.0
info:
  title: (title)
  version: 0.0.0
tags: []
paths:
  /:
    get:
      operationId: myOp
      parameters: []
      responses:
        '200':
          description: The request has succeeded.
        4XX:
          description: Client error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/MyError'
components:
  schemas:
    MyError:
      type: object

Results in the following TypeSpec definition

import "@typespec/http";

using TypeSpec.Http;

model MyError {

}

model MyResponse {

}

op myOp (): MyResponse | {
  @maxValue(499)
  @minValue(400)
  @statusCode
  statusCode: int32;

  @body
  error: MyError;
};

Note the absence of @error decorator on the MyError model.

This is also a problem without ranges

openapi: 3.0.0
info:
  title: (title)
  version: 0.0.0
tags: []
paths:
  /:
    get:
      operationId: myOp
      parameters: []
      responses:
        '200':
          description: The request has succeeded.
        '401':
          description: Access is unauthorized.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/MyError'
components:
  schemas:
    MyError:
      type: object

The import tool should add the error decorator when a model is used as the response body for an error response (specific code between 400 and 599 included, 400 to 499 or 500 to 599 ranges, etc...)

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingopenapi3:converterIssues for @typespec/openapi3 openapi to typespec converter

Type

No fields configured for Bug.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions