Skip to content

Commit

Permalink
Add support for Astro 5 (#58)
Browse files Browse the repository at this point in the history
  • Loading branch information
HiDeoo authored Dec 17, 2024
1 parent b227244 commit f91f2f4
Show file tree
Hide file tree
Showing 21 changed files with 2,740 additions and 2,481 deletions.
9 changes: 9 additions & 0 deletions .changeset/mighty-horses-beam.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
'starlight-openapi': minor
---

Adds support for Astro v5, drops support for Astro v4.

⚠️ **BREAKING CHANGE:** The minimum supported version of Starlight is now `0.30.0`.

Please follow the [upgrade guide](https://github.com/withastro/starlight/releases/tag/%40astrojs/starlight%400.30.0) to update your project.
2 changes: 1 addition & 1 deletion .node-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v18.14.1
v18.17.1
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"eslint.experimental.useFlatConfig": true,
"eslint.useFlatConfig": true,
"eslint.validate": [
"javascript",
"javascriptreact",
Expand Down
13 changes: 0 additions & 13 deletions docs/.prettierignore

This file was deleted.

16 changes: 8 additions & 8 deletions docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,17 @@
"build": "astro build",
"preview": "astro preview",
"astro": "astro",
"lint": "eslint . --cache --max-warnings=0",
"format": "prettier -w --cache --ignore-unknown ."
"lint": "eslint . --cache --max-warnings=0"
},
"dependencies": {
"@astrojs/starlight": "0.26.0",
"@hideoo/starlight-plugins-docs-components": "^0.2.2",
"astro": "4.11.1",
"sharp": "0.32.6",
"@astrojs/starlight": "^0.30.2",
"@hideoo/starlight-plugins-docs-components": "^0.3.0",
"astro": "^5.0.9",
"sharp": "^0.33.5",
"starlight-openapi": "workspace:*"
},
"engines": {
"node": ">=18.14.1"
"node": ">=18.17.1"
},
"packageManager": "[email protected]",
"private": true,
Expand All @@ -38,7 +37,8 @@
"homepage": "https://github.com/HiDeoo/starlight-openapi",
"repository": {
"type": "git",
"url": "https://github.com/HiDeoo/starlight-openapi.git"
"url": "https://github.com/HiDeoo/starlight-openapi.git",
"directory": "docs"
},
"bugs": "https://github.com/HiDeoo/starlight-openapi/issues"
}
7 changes: 7 additions & 0 deletions docs/src/content.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { docsLoader } from '@astrojs/starlight/loaders'
import { docsSchema } from '@astrojs/starlight/schema'
import { defineCollection } from 'astro:content'

export const collections = {
docs: defineCollection({ loader: docsLoader(), schema: docsSchema() }),
}
7 changes: 0 additions & 7 deletions docs/src/content/config.ts

This file was deleted.

2 changes: 1 addition & 1 deletion docs/src/content/docs/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ hero:
icon: rocket
- text: Demo
link: /api/petstore/operations/addpet/
icon: external
icon: right-arrow
variant: minimal
---

Expand Down
File renamed without changes.
27 changes: 14 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,25 @@
"type": "module",
"scripts": {
"test": "pnpm --stream -r test",
"lint": "pnpm -r lint",
"format": "pnpm -r format",
"lint": "astro check --noSync && pnpm -r lint",
"format": "prettier -w --cache --ignore-unknown .",
"version": "pnpm changeset version && pnpm i --no-frozen-lockfile"
},
"devDependencies": {
"@changesets/changelog-github": "0.5.0",
"@changesets/cli": "2.27.10",
"@hideoo/eslint-config": "3.0.0",
"@hideoo/prettier-config": "2.0.0",
"@hideoo/tsconfig": "2.0.1",
"astro": "4.11.1",
"eslint": "8.56.0",
"prettier": "3.0.3",
"prettier-plugin-astro": "0.12.0",
"typescript": "5.1.6"
"@astrojs/check": "^0.9.4",
"@changesets/changelog-github": "^0.5.0",
"@changesets/cli": "^2.27.10",
"@hideoo/eslint-config": "^4.0.0",
"@hideoo/prettier-config": "^2.0.0",
"@hideoo/tsconfig": "^2.0.1",
"astro": "^5.0.9",
"eslint": "^9.17.0",
"prettier": "^3.4.2",
"prettier-plugin-astro": "^0.14.1",
"typescript": "^5.7.2"
},
"engines": {
"node": ">=18.14.1"
"node": ">=18.17.1"
},
"packageManager": "[email protected]",
"private": true,
Expand Down
12 changes: 0 additions & 12 deletions packages/starlight-openapi/.prettierignore

This file was deleted.

10 changes: 7 additions & 3 deletions packages/starlight-openapi/components/Items.astro
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
import { getBound, getType, type Items } from '../libs/items'
import { isSchemaObjectObject } from '../libs/schemaObject'
import { isSchemaObjectObject, type SchemaObject as SchemaObjectType } from '../libs/schemaObject'
import SchemaObject from './schema/SchemaObject.astro'
import Tag from './Tag.astro'
Expand All @@ -11,7 +11,7 @@ interface Props {
items: Items
negated?: boolean | undefined
nullable?: boolean | undefined
parents?: SchemaObject[]
parents?: SchemaObjectType[]
}
const { hideExample, items, negated, nullable, parents = [] } = Astro.props
Expand Down Expand Up @@ -47,7 +47,11 @@ const enumItems = items.enum ?? items.items?.enum
/>

{enumItems && <Tags label="Allowed values:" tags={enumItems} />}
{items.items && isSchemaObjectObject(items.items) && <SchemaObject {parents} nested schemaObject={items.items} {hideExample} />}
{
items.items && isSchemaObjectObject(items.items) && (
<SchemaObject {parents} nested schemaObject={items.items} {hideExample} />
)
}

<style>
.type {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import {
getNullable,
getSchemaObjects,
isSchemaObject,
isSchemaObjectAllOf,
isSchemaObjectObject,
type SchemaObject,
Expand All @@ -28,13 +29,12 @@ const { hideExample = false, negated, nested = false, parents = [], schemaObject
const schemaObjects = getSchemaObjects(schemaObject)
const hasMany = schemaObjects !== undefined
const isNegated = schemaObject.not !== undefined
---

{
hasMany ? (
<SchemaObjects {parents} discriminator={schemaObject.discriminator} {nested} {schemaObjects} />
) : isNegated ? (
) : isSchemaObject(schemaObject.not) ? (
<Astro.self negated schemaObject={schemaObject.not} />
) : (
<>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
import { Tabs, TabItem } from '@astrojs/starlight/components'
import { getType } from '../../libs/items'
import type { Discriminator, SchemaObjects } from '../../libs/schemaObject'
import type { Discriminator, SchemaObjects, SchemaObject as SchemaObjectType } from '../../libs/schemaObject'
import Tag from '../Tag.astro'
import SchemaObject from './SchemaObject.astro'
interface Props {
discriminator: Discriminator
nested: boolean
parents?: SchemaObject[]
parents?: SchemaObjectType[]
schemaObjects: SchemaObjects
}
Expand All @@ -25,8 +25,8 @@ const discriminatorPropertyName =
typeof discriminator === 'string'
? discriminator
: typeof discriminator === 'object'
? discriminator.propertyName
: undefined
? discriminator.propertyName
: undefined
const humanReadableType: Record<SchemaObjects['type'], string> = {
anyOf: 'Any of',
Expand Down
12 changes: 6 additions & 6 deletions packages/starlight-openapi/libs/operation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export function getOperationsByTag(document: Schema['document']) {
}

const allOperationIds = operationHttpMethods.map((method) => {
return isPathItemOperation(pathItem, method) ? pathItem[method].operationId ?? pathItemPath : undefined
return isPathItemOperation(pathItem, method) ? (pathItem[method].operationId ?? pathItemPath) : undefined
})

for (const [index, method] of operationHttpMethods.entries()) {
Expand Down Expand Up @@ -106,7 +106,7 @@ export function getWebhooksOperations(document: Schema['document']): PathItemOpe
export function isPathItemOperation<TMethod extends OperationHttpMethod>(
pathItem: PathItem,
method: TMethod,
): pathItem is { [key in TMethod]: Operation } {
): pathItem is Record<TMethod, Operation> {
return method in pathItem
}

Expand All @@ -126,10 +126,10 @@ export function getOperationURLs(document: Document, { operation, path, pathItem
'servers' in operation
? operation.servers
: 'servers' in pathItem
? pathItem.servers
: 'servers' in document
? document.servers
: []
? pathItem.servers
: 'servers' in document
? document.servers
: []

for (const server of servers) {
let url = server.url
Expand Down
25 changes: 11 additions & 14 deletions packages/starlight-openapi/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,23 @@
},
"scripts": {
"test": "playwright install --with-deps chromium && playwright test",
"lint": "eslint . --cache --max-warnings=0",
"format": "prettier -w --cache --ignore-unknown ."
"lint": "eslint . --cache --max-warnings=0"
},
"dependencies": {
"@readme/openapi-parser": "2.5.0",
"github-slugger": "2.0.0"
"@readme/openapi-parser": "^2.5.0",
"github-slugger": "^2.0.0"
},
"devDependencies": {
"@astrojs/starlight": "0.26.0",
"@playwright/test": "1.36.2",
"@types/node": "18.17.3",
"astro": "4.11.1",
"openapi-types": "12.1.3"
"@playwright/test": "^1.49.1",
"@types/node": "^18.19.68",
"openapi-types": "^12.1.3"
},
"peerDependencies": {
"@astrojs/markdown-remark": ">=4.2.0",
"@astrojs/starlight": ">=0.26.0",
"astro": ">=4.8.6"
"@astrojs/markdown-remark": ">=6.0.0",
"@astrojs/starlight": ">=0.30.0"
},
"engines": {
"node": ">=18.14.1"
"node": ">=18.17.1"
},
"packageManager": "[email protected]",
"publishConfig": {
Expand All @@ -51,7 +47,8 @@
"homepage": "https://github.com/HiDeoo/starlight-openapi",
"repository": {
"type": "git",
"url": "https://github.com/HiDeoo/starlight-openapi.git"
"url": "https://github.com/HiDeoo/starlight-openapi.git",
"directory": "packages/starlight-openapi"
},
"bugs": "https://github.com/HiDeoo/starlight-openapi/issues"
}
2 changes: 1 addition & 1 deletion packages/starlight-openapi/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default defineConfig({
},
webServer: [
{
command: 'pnpm run dev',
command: 'pnpm build && pnpm preview',
cwd: '../../docs',
reuseExistingServer: !process.env['CI'],
url: 'http://localhost:4321',
Expand Down
2 changes: 1 addition & 1 deletion packages/starlight-openapi/tests/fixtures/DocPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export class DocPage {
}

getParameters(location: string) {
return this.page.locator(`h3:text-is("${`${capitalize(location)} Parameters`}") + div > div`)
return this.page.locator(`h3:text-is("${capitalize(location)} Parameters") + div > div`)
}

getRequestBody() {
Expand Down
Loading

0 comments on commit f91f2f4

Please sign in to comment.