flowup / api-client-generator

Angular REST API client generator from Swagger YAML or JSON file with camel case settigs
MIT License
115 stars 21 forks source link

Optional `args` if no query param is required #69

Closed paveltobias closed 3 years ago

paveltobias commented 6 years ago

Please examine the following example.

Chunk of input swagger-file:

get: 
  operationId: GetItems
  responses: 
    '200':
      description: ''
      schema:
        type: array
        items:
          $ref: '#/definitions/Item'
  parameters:
  - name: color
    in: query
    required: false
    type: string
  - name: shape
    in: query
    required: false
    type: string

Corresponding chunk of output API client interface:

getItems(
  args: {
    color?: string,
    shape?: string,
  },
  requestHttpOptions?: HttpOptions
): Observable<models.Item[]>;

Notice that if one wants to make the API call without any query parameters (which is valid, since none of them is required), they need to call the method like .getItems({}), i. e. pass an empty object to the args parameter. It works but could be prettier. :smile:

Proposal: If all of args's properties are optional, so should be the parameter itself, e. g. by having an empty object as its default value:

args: {
  color?: string,
  shape?: string,
} = {},