openapi-generators / openapi-generators/openapi-python-client

Generates SyntaxError if a path parameter without a default value follows another that has a default value

Đang mở
#1,281 0 bình luận 2 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Ngôn ngữ chính
Python
Star
2k
Fork
293
Merge trung bình
34 phút
Pull request đã merge (30 ngày)
1

Mô tả

Describe the bug
Fails to generate client when a path parameter without a default value follows another one that has a default value.

Message:

Error(s) encountered while generating, client was not created
ruff failed
SyntaxError: Parameter without a default cannot follow a parameter with a default

OpenAPI Spec File
Motivating api: https://avaandmed.keskkonnaportaal.ee/swagger/index.html ("File of document")
Minimum example:

openapi: 3.0.0
info:
  title: Minimal Repro for Parameter Order Bug
  version: 1.0.0
paths:
  /test/{has_default}/{no_default}:
    get:
      summary: Test endpoint with required path params, some with defaults
      parameters:
        - name: has_default
          in: path
          required: true
          schema:
            type: string
            default: default_value
          description: Required path param with default
        - name: no_default
          in: path
          required: true
          schema:
            type: integer
          description: Required path param, no default
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  result:
                    type: string

Desktop (please complete the following information):

  • OS: Ubuntu 22.04.5 LTS
  • Python Version: 3.10.12
  • openapi-python-client version 0.25.2

Additional context
The generated function signature for _get_kwargs looks like this:

def _get_kwargs(
    has_default: str = 'default_value',
    no_default: int,
) -> dict[str, Any]:

The issue does not occur for query parameters, as the generator emits keyword-only arguments (*) for them. It only occurs for path parameters, which are emitted as positional-or-keyword arguments.

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Tái hiện vấn đề với đặc tả OpenAPI tối thiểu trong báo cáo và kiểm tra đường dẫn của generator tạo ra chữ ký _get_kwargs được sinh cho các tham số đường dẫn. Xác nhận bản sửa bằng cách tạo client thành công và kiểm tra rằng các tham số đường dẫn bắt buộc có thể đứng sau các tham số có giá trị mặc định mà không gây ra Python SyntaxError.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
openapi, python
Lĩnh vực
api, tooling
Loại issue
Lỗi
Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Đặc tả rõ ràng
Mức phù hợp với người mới
50/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.