swagger-api / swagger-codegen

swagger-codegen contains a template-driven engine to generate documentation, API clients and server stubs in different languages by parsing your OpenAPI / Swagger definition.
http://swagger.io
Apache License 2.0
17.04k stars 6.03k forks source link

[typescript/angular2] Handling custom-made exceptions #4371

Open jeusdi opened 7 years ago

jeusdi commented 7 years ago
Description

I don't know whether it's been written down previously.

I've created this endpoint:

@Path(value = "/users")
@Produces({"application/json"})
@Api(value = "/users")
public interface IUserCommtyEndpoint {

    @PUT
    @ApiOperation(value = "Add user")
    public abstract Response create(
        @HeaderParam("user")
        @ApiParam(value = "username", required = true)
        @NotNull(message = "user.username.notnull")
        @Pattern(regexp="[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?", message="{user.username.email}")
            String username,
        @HeaderParam("passwd")
        @ApiParam(value = "passwd", required = true)
        @NotNull(message = "user.passwd.notnull")
        @Size(min = 6, max = 20, message = "{username.passwd.size}")
            String passwd
    ) throws UsernameAlreadyExistsCommtyException, RepositorySystemException;

    @GET
    @ApiOperation(value = "User exists", response = Boolean.class)
    public abstract Response exists(
        @HeaderParam("user")
        @ApiParam(value = "username", required = true)
        @NotNull(message = "user.username.notnull")
        @Pattern(regexp="[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?", message="{user.username.email}")
            String username
    );

}

As you can see this method throws two custom made exceptions UsernameAlreadyExistsCommtyException and RepositorySystemException.

I'm not able to figure out how codegen deals with that. I've tried to generate artifacts setting typescript-angular2 as language. Nevertheless, it doesn't generate any exception-like class or artifact.

Please, is there some approach over there?

Swagger-codegen version

2.2.3

Swagger declaration file content or url
swagger: '2.0'
info:
  description: desc
  version: 1.0.2
  title: Living API
  termsOfService: 'http://swagger.io/terms/'
  contact:
    name: apiteam@swagger.io
  license:
    name: Apache 2.0
    url: 'http://www.apache.org/licenses/LICENSE-2.0.html'
host: localhost
basePath: /commty/cmng
tags:
  - name: users
schemes:
  - http
paths:
  /users:
    get:
      tags:
        - users
      summary: User exists
      description: ''
      operationId: exists
      produces:
        - application/json
      parameters:
        - name: user
          in: header
          description: username
          required: true
          type: string
      responses:
        '200':
          description: successful operation
          schema:
            type: boolean
    put:
      tags:
        - users
      summary: Add user
      description: ''
      operationId: create
      produces:
        - application/json
      parameters:
        - name: user
          in: header
          description: username
          required: true
          type: string
        - name: passwd
          in: header
          description: passwd
          required: true
          type: string
          maxItems: 20
          minItems: 6
wing328 commented 7 years ago

I don't think the spec has a way to describe the exceptions (UsernameAlreadyExistsCommtyException, RepositorySystemException) that you put in the ocde (without using vendor extensions)