Return types are not unique across services. They conflict.
ianberdin opened this issue · comments
Description
Hi, thanks again for your huge contribution to Open Source with this package.
It seems like we're doing something wrong because the type in JSDoc doesn't match the actual return type. As a result, the return type, like CreateResponse
, is the same for all services.
We're trying to make an SDK that works like this using tags (users, carts, bookings) and operationIds (create):
api.users.create() -> UsersCreateResponse
api.carts.create() -> CartsCreateResponse
api.bookings.create() -> BookingsCreateResponse
But what we get is (always CreateResponse
and CreateData
):
/**
* Create
* No description
* @param data The data for the request.
* @param data.requestBody
* @returns UsersCreateResponseDto Created
* @throws ApiError
*/
public create(data: CreateData): CancelablePromise<CreateResponse> {
return this.httpRequest.request({
method: 'POST',
url: '/api/v1/users/create',
body: data.requestBody,
mediaType: 'application/json',
});
}
OpenAPI specification (optional)
"/api/v1/users/create": {
"post": {
"operationId": "create",
"summary": "Create",
"description": "Create an user",
"parameters": [],
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/UsersCreateRequestDto"
}
}
}
},
"responses": {
"201": {
"description": "Created",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/UsersCreateResponseDto"
}
}
}
},
},
"tags": [
"Users"
]
}
},
"/api/v1/carts/create": {
"post": {
"operationId": "create",
"summary": "Create",
"description": "Create a cart",
"parameters": [],
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/CartsCreateRequestDto"
}
}
}
},
"responses": {
"201": {
"description": "Created",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/CartsCreateResponseDto"
}
}
}
},
},
"tags": [
"Carts"
]
}
}
Configuration
@hey-api/openapi-ts \
--input "${swagger_url}" \
--output "${output_dir}" \
--client fetch \
--name "Api"
System information (optional)
No response
If we don't specify an operationId, the API will look like this:
api.users.usersControllerCreate() -> UsersControllerCreateResponse
api.carts.cartsControllerCreate() -> CartsControllerCreateResponse
api.bookings.bookingsControllerCreate() -> BookingsControllerCreateResponse
Hey @ianberdin, is this a regression?
No, it's not. I can't use the next version 0.46.* because it breaks completely, so I'm using 0.45.3.
Not that I'm aware, will need to look at this. Thanks for reporting!
Are you on Discord @ianberdin? Would like to understand your use case better
I've sent you a request in Discord.
@ianberdin mine username.
I think you can resolve this with services.methodNameBuilder(), let me know if not