docs: prep for v2 documentation (#6710)

This PR includes documentation that preps for v2 docs (but doesn't introduce new docs).

_Note: The number of file changes in the PR is due to find-and-replace within the `references` which is unavoidable. Let me know if I should move it to another PR._

## Changes

- Change Medusa version in base OAS used for v2.
- Fix to docblock generator related to not catching all path parameters.
- Added typedoc plugin that generates ER Diagrams, which will be used specifically for data model references in commerce modules.
- Changed OAS tool to output references in `www/apps/api-reference/specs-v2` directory when the `--v2` option is used.
- Added a version switcher to the API reference to switch between V1 and V2. This switcher is enabled by an environment variable, so it won't be visible/usable at the moment.
- Upgraded docusaurus to v3.0.1
- Added new Vale rules to ensure correct spelling of Medusa Admin and module names.
- Added new components to the `docs-ui` package that will be used in future documentation changes.
This commit is contained in:
Shahed Nasser
2024-03-18 09:47:35 +02:00
committed by GitHub
parent 56a6ec0227
commit bb87db8342
2008 changed files with 15716 additions and 10536 deletions

View File

@@ -28,7 +28,7 @@ import OasSchemaHelper from "../helpers/oas-schema.js"
import formatOas from "../../utils/format-oas.js"
import { DEFAULT_OAS_RESPONSES } from "../../constants.js"
export const API_ROUTE_PARAM_REGEX = /\[(.+)\]/g
export const API_ROUTE_PARAM_REGEX = /\[(.+?)\]/g
const RES_STATUS_REGEX = /^res[\s\S]*\.status\((\d+)\)/
type SchemaDescriptionOptions = {
@@ -112,9 +112,12 @@ class OasKindGenerator extends FunctionKindGenerator {
// and the second of type `MedusaResponse`
return (
(functionNode.parameters.length === 2 &&
functionNode.parameters[0].type
(functionNode.parameters[0].type
?.getText()
.startsWith("MedusaRequest") &&
.startsWith("MedusaRequest") ||
functionNode.parameters[0].type
?.getText()
.startsWith("AuthenticatedMedusaRequest")) &&
functionNode.parameters[1].type
?.getText()
.startsWith("MedusaResponse")) ||
@@ -988,26 +991,32 @@ class OasKindGenerator extends FunctionKindGenerator {
*/
tagName?: string
}): OpenAPIV3.ParameterObject[] {
const pathParameters = API_ROUTE_PARAM_REGEX.exec(oasPath)?.slice(1)
// reset regex manually
API_ROUTE_PARAM_REGEX.lastIndex = 0
let pathParameters: string[] | undefined
const parameters: OpenAPIV3.ParameterObject[] = []
if (pathParameters?.length) {
pathParameters.forEach((parameter) =>
parameters.push(
this.getParameterObject({
type: "path",
name: parameter,
description: this.getSchemaDescription({
typeStr: parameter,
parentName: tagName,
}),
required: true,
schema: {
type: "string",
},
})
while (
(pathParameters = API_ROUTE_PARAM_REGEX.exec(oasPath)?.slice(1)) !==
undefined
) {
if (pathParameters.length) {
pathParameters.forEach((parameter) =>
parameters.push(
this.getParameterObject({
type: "path",
name: parameter,
description: this.getSchemaDescription({
typeStr: parameter,
parentName: tagName,
}),
required: true,
schema: {
type: "string",
},
})
)
)
)
}
}
return parameters