OpenAPITools / OpenAPITools/openapi-generator
AttributeError: module 'openapi_client' has no attribute 'DefaultApi'.What's wrong with openapi-generator-cli-6.6.0.jar?
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
when create client code and run,it runs wrong.
openapi-generator version
6.6.0
OpenAPI declaration file content or url
openapi: 3.0.1
info:
title: TODO Plugin
description: A plugin that allows the user to create and manage a TODO list using ChatGPT. If you do not know the user's username, ask them first before making queries to the plugin. Otherwise, use the username "global".
version: 'v1'
servers:
- url: http://192.168.0.1:5003
paths:
/todos/{username}:
get:
operationId: getTodos
summary: Get the list of todos
parameters:- in: path
name: username
schema:
type: string
required: true
description: The name of the user.
responses:
"200":
description: OK
content:
application/json:
schema:
$ref: '#/components/schemas/getTodosResponse'
post:
operationId: addTodo
summary: Add a todo to the list
parameters: - in: path
name: username
schema:
type: string
required: true
description: The name of the user.
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/addTodoRequest'
responses:
"200":
description: OK
delete:
operationId: deleteTodo
summary: Delete a todo from the list
parameters: - in: path
name: username
schema:
type: string
required: true
description: The name of the user.
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/deleteTodoRequest'
responses:
"200":
description: OK
- in: path
components:
schemas:
getTodosResponse:
type: object
properties:
todos:
type: array
items:
type: string
description: The list of todos.
addTodoRequest:
type: object
required:
- todo
properties:
todo:
type: string
description: The todo to add to the list.
required: true
deleteTodoRequest:
type: object
required:
- todo_idx
properties:
todo_idx:
type: integer
description: The index of the todo to delete.
required: true
Generation Details
I use java -jar openapi-generator-cli.jar generate -i openapi.yaml -g python -o . to create python code.It can create the code.But when I try to run the code ,it's wrong.
`import openapi_client # 这是生成的客户端库导入语句
设置服务器地址
configuration = openapi_client.Configuration(
host="http://127.0.0.1:5003"
)
创建 API 客户端实例
api_client = openapi_client.ApiClient(configuration)
api_instance = openapi_client.DefaultApi(api_client)
传入的 operationId
operation_id = "get_todos"
根据 operationId 获取对应的方法
operation_func = getattr(api_instance, operation_id, None)
if operation_func is not None and callable(operation_func):
# 调用方法
username = "your_username"
try:
response = operation_func(username)
print("Response:", response)
except openapi_client.ApiException as e:
print("Error:", e)
else:
print(f"Operation '{operation_id}' not found.")`
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the supplied openapi.yaml and the generated Python package in the output directory, then inspect the generated API class and its method names against operationId values such as getTodos. Reproduce with openapi-generator-cli 6.6.0 and confirm that the generated client exposes the expected API entry point and callable operation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi, python
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100