-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from CharlyJazz/fixtags
discover tags if there is not tags array
- Loading branch information
Showing
4 changed files
with
94 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { OpenAPIV3 } from "openapi-types"; | ||
|
||
const discoveryTagsFromPaths = ( | ||
openApiDocument: OpenAPIV3.Document | ||
): OpenAPIV3.TagObject[] => { | ||
const tags: OpenAPIV3.TagObject[] = []; | ||
|
||
if (openApiDocument.paths) { | ||
for (const pathKey in openApiDocument.paths) { | ||
const pathItem = openApiDocument.paths[ | ||
pathKey | ||
] as OpenAPIV3.PathItemObject; | ||
|
||
if (pathItem) { | ||
for (const methodKey in pathItem) { | ||
if (methodKey !== "parameters") { | ||
const method = (pathItem as any)[ | ||
methodKey | ||
] as OpenAPIV3.OperationObject; | ||
if (method.tags && Array.isArray(method.tags)) { | ||
method.tags.forEach((tag) => { | ||
const existingTag = tags.find((t) => t.name === tag); | ||
if (!existingTag) { | ||
tags.push({ | ||
name: tag, | ||
description: `Section grouped by ${tag}`, | ||
externalDocs: { | ||
url: "", | ||
description: "", | ||
}, | ||
}); | ||
} | ||
}); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
return tags; | ||
}; | ||
|
||
export default discoveryTagsFromPaths; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
export const getMissingAttributes = (jsonParsed: any): string[] => { | ||
const requiredAttributes = [ | ||
"openapi", | ||
"info", | ||
"info.title", | ||
"paths", | ||
"components", | ||
]; | ||
|
||
const missingAttributes: string[] = []; | ||
for (const attr of requiredAttributes) { | ||
const attrParts = attr.split("."); | ||
let currentObj = jsonParsed; | ||
let isValid = true; | ||
for (const part of attrParts) { | ||
if (!(part in currentObj)) { | ||
isValid = false; | ||
break; | ||
} | ||
currentObj = currentObj[part]; | ||
} | ||
if (!isValid) { | ||
missingAttributes.push(attr); | ||
} | ||
} | ||
return missingAttributes; | ||
}; | ||
|
||
export const validationReasons = (attr: string): string => { | ||
const reasons: Record<string, string> = { | ||
openapi: "It defines the OpenAPI version of the document.", | ||
info: "It provides metadata about the API.", | ||
"info.title": "It specifies the title of the API.", | ||
paths: "It defines the available API endpoints.", | ||
components: "It holds reusable components used in the specification.", | ||
}; | ||
return reasons[attr] || "Unknown reason."; | ||
}; |