docs-util: fix clean script removing Auth tags (#8911)

* docs-util: fix clean script removing Auth tags

* fix removal of response types other than json
This commit is contained in:
Shahed Nasser authored and GitHub committed 2024-08-30 17:02:02 +03:00
1 parent b9eac4402b
commit dea5af085a
3 files changed
+34 -4

No files matched your search

@@ -76,7 +76,11 @@ class SchemaFactory {
let schema = Object.assign({}, schemasFactory[key]) let schema = Object.assign({}, schemasFactory[key])
if (additionalData) { if (additionalData) {
schema = Object.assign(schema, additionalData) schema = Object.assign(schema, {
...additionalData,
// keep the description
description: schema.description || additionalData.description
})
} }
return schema return schema
@@ -506,8 +506,11 @@ class OasKindGenerator extends FunctionKindGenerator {
} }
updatedResponseSchema = newResponseSchema updatedResponseSchema = newResponseSchema
} else if (oas.responses && !newResponseSchema) { } else if (oas.responses && !newResponseSchema) {
// remove response schema by only keeping the default responses // check if it has a success response of a type other than JSON
oas.responses = DEFAULT_OAS_RESPONSES if (!this.hasResponseType(node, oas)) {
// remove response schema by only keeping the default responses
oas.responses = DEFAULT_OAS_RESPONSES
}
} else { } else {
// check if response status should be changed // check if response status should be changed
const oldResponseStatus = Object.keys(oas.responses!).find( const oldResponseStatus = Object.keys(oas.responses!).find(
@@ -2070,6 +2073,24 @@ class OasKindGenerator extends FunctionKindGenerator {
) )
} }
hasResponseType(node: FunctionNode, oas: OpenApiOperation): boolean {
const oldResponseStatus = Object.keys(oas.responses!).find(
(status) => !Object.keys(DEFAULT_OAS_RESPONSES).includes(status)
)
if (!oldResponseStatus) {
return false
}
const responseContent = (oas.responses![oldResponseStatus] as OpenAPIV3.ResponseObject).content
if (!responseContent) {
return false
}
const fnText = node.getText()
return Object.keys(responseContent).some((responseType) => fnText.includes(responseType))
}
private removeStringRegExpTypeOverlaps(types: ts.Type[]): ts.Type[] { private removeStringRegExpTypeOverlaps(types: ts.Type[]): ts.Type[] {
return types.filter((itemType) => { return types.filter((itemType) => {
// remove overlapping string / regexp types // remove overlapping string / regexp types
@@ -26,6 +26,11 @@ const ignoreSchemas = [
"AuthStoreSessionResponse", "AuthStoreSessionResponse",
] ]
const ignoreTags = {
admin: ["Auth"],
store: ["Auth"]
}
export default async function () { export default async function () {
const oasOutputBasePath = getOasOutputBasePath() const oasOutputBasePath = getOasOutputBasePath()
const oasOperationsPath = path.join(oasOutputBasePath, "operations") const oasOperationsPath = path.join(oasOutputBasePath, "operations")
@@ -225,7 +230,7 @@ export default async function () {
const lengthBefore = parsedBaseYaml.tags?.length || 0 const lengthBefore = parsedBaseYaml.tags?.length || 0
parsedBaseYaml.tags = parsedBaseYaml.tags?.filter((tag) => parsedBaseYaml.tags = parsedBaseYaml.tags?.filter((tag) =>
areaTags.has(tag.name) areaTags.has(tag.name) || ignoreTags[area].includes(tag.name)
) )
if (lengthBefore !== (parsedBaseYaml.tags?.length || 0)) { if (lengthBefore !== (parsedBaseYaml.tags?.length || 0)) {