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

Optional args if no query param is required #69

Closed
paveltobias opened this issue Sep 1, 2018 · 0 comments
Closed

Optional args if no query param is required #69

paveltobias opened this issue Sep 1, 2018 · 0 comments
Assignees
Labels
enhancement Request for a change or improvement of existing functionality
Milestone

Comments

@paveltobias
Copy link
Contributor

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. 😄

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,
} = {},
@paveltobias paveltobias added the enhancement Request for a change or improvement of existing functionality label Sep 1, 2018
@vmasek vmasek added this to the 5.x milestone Sep 1, 2018
@vmasek vmasek modified the milestones: 5.x, 4.x Nov 23, 2019
@vmasek vmasek modified the milestones: 4.x, 5.0 Dec 19, 2020
@vmasek vmasek closed this as completed in 9b77d74 Dec 22, 2020
@vmasek vmasek moved this to Done in Main board Aug 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Request for a change or improvement of existing functionality
Projects
Archived in project
Development

No branches or pull requests

2 participants