docs-util: fix query params not retrieved correctly for some routes (#10708)
This commit is contained in:
1 parent
c804ae575b
commit
9a05888538
2 files changed
+33
-13
No files matched your search
@@ -680,14 +680,6 @@
|
|||||||
* type: string
|
* type: string
|
||||||
* title: category_id
|
* title: category_id
|
||||||
* description: A product category's ID.
|
* description: A product category's ID.
|
||||||
* - name: currency_code
|
|
||||||
* in: query
|
|
||||||
* description: The currency code to retrieve prices in.
|
|
||||||
* required: false
|
|
||||||
* schema:
|
|
||||||
* type: string
|
|
||||||
* title: currency_code
|
|
||||||
* description: The currency code to retrieve prices in.
|
|
||||||
* - name: variants
|
* - name: variants
|
||||||
* in: query
|
* in: query
|
||||||
* description: Filter the products' variants.
|
* description: Filter the products' variants.
|
||||||
@@ -712,6 +704,22 @@
|
|||||||
* type: string
|
* type: string
|
||||||
* title: value
|
* title: value
|
||||||
* description: Filter by a value of the option.
|
* description: Filter by a value of the option.
|
||||||
|
* - name: country_code
|
||||||
|
* in: query
|
||||||
|
* description: The product's country code.
|
||||||
|
* required: false
|
||||||
|
* schema:
|
||||||
|
* type: string
|
||||||
|
* title: country_code
|
||||||
|
* description: The product's country code.
|
||||||
|
* - name: cart_id
|
||||||
|
* in: query
|
||||||
|
* description: The product's cart id.
|
||||||
|
* required: false
|
||||||
|
* schema:
|
||||||
|
* type: string
|
||||||
|
* title: cart_id
|
||||||
|
* description: The product's cart id.
|
||||||
* x-codeSamples:
|
* x-codeSamples:
|
||||||
* - lang: Shell
|
* - lang: Shell
|
||||||
* label: cURL
|
* label: cURL
|
||||||
|
|||||||
@@ -67,6 +67,7 @@ class OasKindGenerator extends FunctionKindGenerator {
|
|||||||
"AuthenticatedMedusaRequest",
|
"AuthenticatedMedusaRequest",
|
||||||
"MedusaStoreRequest",
|
"MedusaStoreRequest",
|
||||||
]
|
]
|
||||||
|
readonly REQUEST_CHECK_QUERY_ARGS = ["RequestWithContext"]
|
||||||
// as it's not always possible to detect authenticated request
|
// as it's not always possible to detect authenticated request
|
||||||
// use this to override the default detection logic.
|
// use this to override the default detection logic.
|
||||||
readonly AUTH_REQUESTS: AuthRequests[] = [
|
readonly AUTH_REQUESTS: AuthRequests[] = [
|
||||||
@@ -1081,17 +1082,26 @@ class OasKindGenerator extends FunctionKindGenerator {
|
|||||||
|
|
||||||
const requestTypeArguments =
|
const requestTypeArguments =
|
||||||
requestType.typeArguments || requestType.aliasTypeArguments
|
requestType.typeArguments || requestType.aliasTypeArguments
|
||||||
|
const shouldCheckTypeArgumentForQuery =
|
||||||
|
this.REQUEST_CHECK_QUERY_ARGS.includes(
|
||||||
|
node.parameters[0].type.typeName.getText()
|
||||||
|
)
|
||||||
|
|
||||||
if (!requestTypeArguments || requestTypeArguments.length < 2) {
|
if (
|
||||||
|
!requestTypeArguments ||
|
||||||
|
(requestTypeArguments.length < 2 && !shouldCheckTypeArgumentForQuery)
|
||||||
|
) {
|
||||||
return {
|
return {
|
||||||
queryParameters,
|
queryParameters,
|
||||||
requestSchema,
|
requestSchema,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const checkQueryIndex = requestTypeArguments.length >= 2 ? 1 : 0
|
||||||
// Not all routes support a second type argument yet,
|
// Not all routes support a second type argument yet,
|
||||||
// so the query param may be passed in the first type argument
|
// so the query param may be passed in the first type argument
|
||||||
const hasQueryParams = requestTypeArguments[1].getProperties().length > 0
|
const hasQueryParams =
|
||||||
|
requestTypeArguments[checkQueryIndex].getProperties().length > 0
|
||||||
// Not all routes support a second type argument yet,
|
// Not all routes support a second type argument yet,
|
||||||
// so we have to support routes that pass the query parameters type
|
// so we have to support routes that pass the query parameters type
|
||||||
// in the first type argument
|
// in the first type argument
|
||||||
@@ -1103,7 +1113,7 @@ class OasKindGenerator extends FunctionKindGenerator {
|
|||||||
})
|
})
|
||||||
const zodObjectQueryTypeName = getCorrectZodTypeName({
|
const zodObjectQueryTypeName = getCorrectZodTypeName({
|
||||||
typeReferenceNode: node.parameters[0].type,
|
typeReferenceNode: node.parameters[0].type,
|
||||||
itemType: requestTypeArguments[1],
|
itemType: requestTypeArguments[checkQueryIndex],
|
||||||
})
|
})
|
||||||
|
|
||||||
const requestBodyParameterSchema = this.typeToSchema({
|
const requestBodyParameterSchema = this.typeToSchema({
|
||||||
@@ -1118,10 +1128,12 @@ class OasKindGenerator extends FunctionKindGenerator {
|
|||||||
})
|
})
|
||||||
const queryParameterSchema = hasQueryParams
|
const queryParameterSchema = hasQueryParams
|
||||||
? this.typeToSchema({
|
? this.typeToSchema({
|
||||||
itemType: requestTypeArguments[1],
|
itemType: requestTypeArguments[checkQueryIndex],
|
||||||
descriptionOptions: {
|
descriptionOptions: {
|
||||||
parentName: tagName,
|
parentName: tagName,
|
||||||
rawParentName: this.checker.typeToString(requestTypeArguments[1]),
|
rawParentName: this.checker.typeToString(
|
||||||
|
requestTypeArguments[checkQueryIndex]
|
||||||
|
),
|
||||||
},
|
},
|
||||||
zodObjectTypeName: zodObjectQueryTypeName,
|
zodObjectTypeName: zodObjectQueryTypeName,
|
||||||
context: "query",
|
context: "query",
|
||||||
|
|||||||
Reference in new issue
Block a user