-
-
Notifications
You must be signed in to change notification settings - Fork 584
Open
Labels
enhancementNew feature or requestNew feature or requestopenapi-fetchRelevant to the openapi-fetch libraryRelevant to the openapi-fetch library
Description
Description
I have an openapi schema that looks like this:
"/country/{country}/product/{productId}": {
"get": {
"operationId": "get_country_country_product_productId",
"parameters": [
{
"name": "country",
"in": "path",
"required": true,
"schema": {
"type": "string"
}
},
{
"name": "productId",
"in": "path",
"required": true,
"schema": {
"type": "string"
}
}
],
"responses": {
"200": {
"description": "Generated response for status 200",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"country": {
"type": "string"
},
"productId": {
"type": "string"
},
"availability": {
"type": "string"
},
"localizedPriceInCents": {
"type": "number"
}
},
"required": [
"country",
"productId",
"availability",
"localizedPriceInCents"
]
}
}
}
}
}
},
When I try to use it with openapi-fetch like this:
const client = createFetchClient<paths>({
baseUrl: "http://localhost:3000",
fetch: fetch,
});
const { data, error } = await client.GET("/country/{country}/product/{productId}", {
params: {
path: {
country: "US",
productId: "123",
},
},
});
Data and error can both be undefined at the same time, even though we don't define a non json response or 204/304 response on the schema.
This feels counter-intuitive and the user has to still have to check if the data is undefined or not even though the openapi schema guarantees that it can't be undefined for a successful response.
Proposal
When the schema doens't contain 204/304 responses and only specifies application/json as content-type, data and error should not be undefined at the same time.
Extra
- I’m willing to open a PR (see CONTRIBUTING.md)
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or requestopenapi-fetchRelevant to the openapi-fetch libraryRelevant to the openapi-fetch library