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

fix: avoid duplicate variable name in genrated function for query clients #1131

Conversation

soartec-lab
Copy link
Collaborator

@soartec-lab soartec-lab commented Jan 1, 2024

Status

READY

Description

follow up #1130

When using query for an API parameter defined in OpenAPI, the name of the argument in the automatically generated function and the name of the argument within the function collide.
In that case, we changed the variable name query to _query.
Variables other than query are not considered because they are rarely used as parameters.

I also supported react-query, vue-query, and svelte-query with this PR

Related PRs

#1130

Todos

  • Tests
  • Documentation
  • Changelog Entry (unreleased)

Steps to Test or Reproduce

  1. Specify query in the parameter name as below:
openapi: '3.0.0'
info:
  version: 1.0.0
  title: Swagger
  license:
    name: MIT
paths:
  /pets/{query}:
    get:
      summary: Info for a specific pet
      operationId: showPetById
      tags:
        - pets
      parameters:
        - name: query
          in: path
          required: true
          description: The id of the pet to retrieve
          schema:
            type: string
      responses:
        '200':
          description: Expected response to a valid request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Pet'
        default:
          description: unexpected error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
components:
  schemas:
    Pet:
      type: object
      required:
        - id
        - name
      properties:
        id:
          type: integer
          format: int64
        name:
          type: string
        tag:
          type: string
    Error:
      type: object
      required:
        - code
        - message
      properties:
        code:
          type: integer
          format: int32
        message:
          type: string
  1. Specify swr for client in orval.config.js as bellow:
module.exports = {
  'petstore-file': {
    input: {
      target: './petstore.yaml',
    },
    output: {
      mode: 'tags-split',
      client: 'react-query', // or 'vue-query', 'svelte-query'
      target: 'src/gen/endpoints',
      schemas: 'src/gen/model',
      indexFiles: false,
    },
  },
};
  1. orval execute
orval
  1. The function is output where the name of the variable is replaced from query to _query

@melloware melloware merged commit dbfb2e5 into anymaniax:master Jan 1, 2024
2 checks passed
@soartec-lab soartec-lab added this to the 6.24.0 milestone Jan 28, 2024
@soartec-lab soartec-lab added the bug Something isn't working label Jan 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants