Skip to content

Commit

Permalink
docs: prep for v2 documentation (medusajs#6710)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
shahednasser authored Mar 18, 2024
1 parent 56a6ec0 commit bb87db8
Show file tree
Hide file tree
Showing 2,008 changed files with 15,758 additions and 10,578 deletions.
5 changes: 5 additions & 0 deletions .changeset/sixty-kids-divide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@medusajs/oas-github-ci": patch
---

feat(oas-github-ci): output specs into `specs-v2` directory when the `--v2` option is passed
1 change: 1 addition & 0 deletions .vale.ini
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ write-good.E-Prime=No
write-good.So=No
write-good.ThereIs=No
Vale.Terms=No
BlockIgnores={/\* [\s\S]+ \*/}

[formats]
mdx = md
2 changes: 1 addition & 1 deletion docs-util/oas-output/base-v2/admin.oas.base.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
openapi: 3.0.0
info:
version: 1.0.0
version: 2.0.0
title: Medusa Admin API
license:
name: MIT
Expand Down
2 changes: 1 addition & 1 deletion docs-util/oas-output/base-v2/store.oas.base.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
openapi: 3.0.0
info:
version: 1.0.0
version: 2.0.0
title: Medusa Storefront API
license:
name: MIT
Expand Down
51 changes: 30 additions & 21 deletions docs-util/packages/docblock-generator/src/classes/kinds/oas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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")) ||
Expand Down Expand Up @@ -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
Expand Down
14 changes: 6 additions & 8 deletions docs-util/packages/typedoc-config/_merger.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,8 @@ module.exports = {
showCommentsAsHeader: true,
sections: baseSectionsOptions,
parameterStyle: "component",
parameterComponent: "ParameterTypes",
mdxImports: [
`import ParameterTypes from "@site/src/components/ParameterTypes"`,
],
parameterComponent: "TypeList",
mdxImports: [`import TypeList from "@site/src/components/TypeList"`],
},
internal: {
maxLevel: 1,
Expand Down Expand Up @@ -231,7 +229,7 @@ npx medusa develop
reflectionTitle: {
kind: false,
typeParameters: false,
suffix: " Reference",
suffix: "Reference",
},
},

Expand Down Expand Up @@ -638,7 +636,7 @@ npx medusa develop
reflectionTitle: {
kind: false,
typeParameters: false,
suffix: " Reference",
suffix: "Reference",
},
},

Expand Down Expand Up @@ -681,7 +679,7 @@ npx medusa develop
reflectionTitle: {
kind: false,
typeParameters: false,
suffix: " Reference",
suffix: "Reference",
},
},

Expand Down Expand Up @@ -780,7 +778,7 @@ npx medusa develop
reflectionTitle: {
kind: false,
typeParameters: false,
suffix: " Reference",
suffix: "Reference",
},
},

Expand Down
2 changes: 2 additions & 0 deletions docs-util/packages/typedoc-plugin-custom/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { load as parseOasSchemaPlugin } from "./parse-oas-schema-plugin"
import { load as apiIgnorePlugin } from "./api-ignore"
import { load as eslintExamplePlugin } from "./eslint-example"
import { load as signatureModifierPlugin } from "./signature-modifier"
import { MermaidDiagramGenerator } from "./mermaid-diagram-generator"
import { load as parentIgnorePlugin } from "./parent-ignore"
import { GenerateNamespacePlugin } from "./generate-namespace"

Expand All @@ -18,4 +19,5 @@ export function load(app: Application) {
parentIgnorePlugin(app)

new GenerateNamespacePlugin(app)
new MermaidDiagramGenerator(app)
}
Loading

0 comments on commit bb87db8

Please sign in to comment.