Skip to content

Commit

Permalink
Merge pull request #1472 from kubb-labs/fix/1470-enhance-jsdocs
Browse files Browse the repository at this point in the history
  • Loading branch information
stijnvanhulle authored Dec 16, 2024
2 parents 4eb9c46 + d8ffbfd commit 45ecf9f
Show file tree
Hide file tree
Showing 37 changed files with 240 additions and 146 deletions.
5 changes: 5 additions & 0 deletions .changeset/famous-keys-eat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@kubb/plugin-client": patch
---

baseURL could be undefined, do not throw error if that is the case
5 changes: 5 additions & 0 deletions .changeset/large-boxes-itch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@kubb/plugin-ts": patch
---

minLength, maxLength, pattern as part of the jsdocs
4 changes: 4 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ title: Changelog

# Changelog

## 3.3.4
- [`plugin-ts`](/plugins/plugin-ts): minLength, maxLength, pattern as part of the jsdocs
- [`plugin-client`](/plugins/plugin-client): baseURL could be undefined, do not throw error if that is the case

## 3.3.3
- [`react`](/helpers/react/): Use of `@kubb/react` as importSource for jsx(React 17, React 18, React 19 could be used next to Kubb)
- [`cli`](/helpers/cli/): Use of `@kubb/react` as importSource for jsx(React 17, React 18, React 19 could be used next to Kubb)
Expand Down
2 changes: 1 addition & 1 deletion e2e/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"@tanstack/svelte-query": "^5.62.7",
"@tanstack/vue-query": "^5.62.7",
"axios": "^1.7.9",
"msw": "^2.6.8",
"msw": "^2.6.9",
"react": "catalog:",
"solid-js": "^1.9.3",
"svelte": "^3.59.2",
Expand Down
4 changes: 2 additions & 2 deletions examples/advanced/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@
"@tanstack/solid-query": "^5.62.7",
"@tanstack/svelte-query": "^5.62.7",
"@tanstack/vue-query": "^5.62.7",
"axios": "^1.7.9",
"msw": "^2.6.8",
"@types/react": "^19.0.1",
"axios": "^1.7.9",
"msw": "^2.6.9",
"react": "^19.0.0",
"solid-js": "^1.9.3",
"svelte": "^3.59.2",
Expand Down
5 changes: 5 additions & 0 deletions examples/advanced/petStore.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -844,11 +844,16 @@ components:
xml:
name: user
tag.Tag:
deprecated: true
type: object
properties:
id:
type: integer
format: int64
minLength: 5
maxLength: 7
default: 1
deprecated: true
name:
type: string
xml:
Expand Down
12 changes: 6 additions & 6 deletions examples/advanced/src/gen/docs.html

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions examples/advanced/src/gen/models/ts/tag/Tag.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
/**
* @deprecated
*/
export type TagTag = {
/**
* @deprecated
* @minLength 5
* @maxLength 7
* @default 1
* @type integer | undefined, int64
*/
id?: number
Expand Down
6 changes: 5 additions & 1 deletion examples/advanced/src/gen/schemas/addPetRequest.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,12 @@
"type": "array",
"xml": { "wrapped": true },
"items": {
"deprecated": true,
"type": "object",
"properties": { "id": { "type": "integer", "format": "int64" }, "name": { "type": "string" } },
"properties": {
"id": { "type": "integer", "format": "int64", "minLength": 5, "maxLength": 7, "default": 1, "deprecated": true },
"name": { "type": "string" }
},
"xml": { "name": "tag" },
"x-readme-ref-name": "tag.Tag"
}
Expand Down
6 changes: 5 additions & 1 deletion examples/advanced/src/gen/schemas/pet.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,12 @@
"type": "array",
"xml": { "wrapped": true },
"items": {
"deprecated": true,
"type": "object",
"properties": { "id": { "type": "integer", "format": "int64" }, "name": { "type": "string" } },
"properties": {
"id": { "type": "integer", "format": "int64", "minLength": 5, "maxLength": 7, "default": 1, "deprecated": true },
"name": { "type": "string" }
},
"xml": { "name": "tag" },
"x-readme-ref-name": "tag.Tag"
}
Expand Down
6 changes: 5 additions & 1 deletion examples/advanced/src/gen/schemas/tagTag.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
{
"deprecated": true,
"type": "object",
"properties": { "id": { "type": "integer", "format": "int64" }, "name": { "type": "string" } },
"properties": {
"id": { "type": "integer", "format": "int64", "minLength": 5, "maxLength": 7, "default": 1, "deprecated": true },
"name": { "type": "string" }
},
"xml": { "name": "tag" },
"x-readme-ref-name": "tag.Tag"
}
6 changes: 5 additions & 1 deletion examples/advanced/src/gen/schemas2/addPetRequest.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,12 @@
"type": "array",
"xml": { "wrapped": true },
"items": {
"deprecated": true,
"type": "object",
"properties": { "id": { "type": "integer", "format": "int64" }, "name": { "type": "string" } },
"properties": {
"id": { "type": "integer", "format": "int64", "minLength": 5, "maxLength": 7, "default": 1, "deprecated": true },
"name": { "type": "string" }
},
"xml": { "name": "tag" },
"x-readme-ref-name": "tag.Tag"
}
Expand Down
6 changes: 5 additions & 1 deletion examples/advanced/src/gen/schemas2/pet.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,12 @@
"type": "array",
"xml": { "wrapped": true },
"items": {
"deprecated": true,
"type": "object",
"properties": { "id": { "type": "integer", "format": "int64" }, "name": { "type": "string" } },
"properties": {
"id": { "type": "integer", "format": "int64", "minLength": 5, "maxLength": 7, "default": 1, "deprecated": true },
"name": { "type": "string" }
},
"xml": { "name": "tag" },
"x-readme-ref-name": "tag.Tag"
}
Expand Down
6 changes: 5 additions & 1 deletion examples/advanced/src/gen/schemas2/tagTag.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
{
"deprecated": true,
"type": "object",
"properties": { "id": { "type": "integer", "format": "int64" }, "name": { "type": "string" } },
"properties": {
"id": { "type": "integer", "format": "int64", "minLength": 5, "maxLength": 7, "default": 1, "deprecated": true },
"name": { "type": "string" }
},
"xml": { "name": "tag" },
"x-readme-ref-name": "tag.Tag"
}
2 changes: 1 addition & 1 deletion examples/advanced/src/gen/zod/tag/tagSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { ToZod } from '@kubb/plugin-zod/utils'
import { z } from 'zod'

export const tagTagSchema = z.object({
id: z.number().int().optional(),
id: z.number().int().min(5).max(7).default(1),
name: z.string().optional(),
} satisfies ToZod<TagTag>)

Expand Down
1 change: 1 addition & 0 deletions examples/faker/src/gen/models/User.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export type User = {
*/
userStatus?: number
/**
* @pattern ^[A-Z]{2}$
* @type string | undefined
*/
nationalityCode?: string
Expand Down
2 changes: 1 addition & 1 deletion examples/msw/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"@kubb/plugin-oas": "workspace:*",
"@kubb/plugin-ts": "workspace:*",
"@mswjs/http-middleware": "^0.9.2",
"msw": "^2.6.8",
"msw": "^2.6.9",
"react": "^18.3.1",
"tsup": "^8.3.5"
},
Expand Down
2 changes: 1 addition & 1 deletion examples/react-query/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"unplugin-kubb": "workspace:*"
},
"devDependencies": {
"@types/react": "^18.3.16",
"@types/react": "^18.3.17",
"@types/react-dom": "^19.0.2",
"@vitejs/plugin-react": "^4.3.4",
"msw": "^1.3.5",
Expand Down
2 changes: 1 addition & 1 deletion examples/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
},
"devDependencies": {
"@kubb/config-ts": "workspace:*",
"@types/react": "^18.3.16",
"@types/react": "^18.3.17",
"react": "^18.3.1",
"tsup": "^8.3.5",
"typescript": "^5.7.2"
Expand Down
1 change: 1 addition & 0 deletions examples/zod/src/gen/ts/PetType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export type PetType = {
*/
id?: number
/**
* @pattern ^[0-9]{1,19}$
* @type string | undefined
*/
internalId?: string
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
"natural-orderby": "^5.0.0",
"object-hash": "^3.0.0",
"p-queue": "^8.0.1",
"remeda": "^2.17.4",
"remeda": "^2.18.0",
"seedrandom": "^3.0.5",
"semver": "^7.6.3"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/oas/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
"oas": "^25.1.0",
"oas-normalize": "^11.1.4",
"openapi-types": "^12.1.3",
"remeda": "^2.17.4",
"remeda": "^2.18.0",
"swagger2openapi": "^7.0.8",
"ts-toolbelt": "^9.6.0"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/parser-ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
},
"dependencies": {
"prettier": "^3.4.2",
"remeda": "^2.17.4",
"remeda": "^2.18.0",
"typescript": "catalog:"
},
"devDependencies": {
Expand Down
8 changes: 4 additions & 4 deletions packages/parser-ts/src/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,12 +269,12 @@ export function createInterfaceDeclaration({
export function createTypeDeclaration({
syntax,
isExportable,
description,
comments,
name,
type,
}: {
syntax: 'type' | 'interface'
description?: string
comments: Array<string | undefined>
isExportable?: boolean
name: string | ts.Identifier
type: ts.TypeNode
Expand All @@ -289,7 +289,7 @@ export function createTypeDeclaration({

return appendJSDocToNode({
node,
comments: [description ? `@description ${description}` : undefined].filter(Boolean),
comments,
})
}

Expand All @@ -302,7 +302,7 @@ export function createTypeDeclaration({

return appendJSDocToNode({
node,
comments: [description ? `@description ${description}` : undefined].filter(Boolean),
comments,
})
}

Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-client/src/clients/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export type ResponseConfig<TData = unknown> = {
}

export const fetchClient = async <TData, TError = unknown, TVariables = unknown>(config: RequestConfig<TVariables>): Promise<ResponseConfig<TData>> => {
const response = await fetch(`${config.baseURL}${config.url}`, {
const response = await fetch([config.baseURL, config.url].filter(Boolean).join(''), {
method: config.method.toUpperCase(),
body: JSON.stringify(config.data),
signal: config.signal,
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-oas/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
"@kubb/oas": "workspace:*",
"@kubb/react": "workspace:*",
"@stoplight/yaml": "^4.3.0",
"remeda": "^2.17.4"
"remeda": "^2.18.0"
},
"devDependencies": {
"@kubb/config-ts": "workspace:*",
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-react-query/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
"@kubb/plugin-ts": "workspace:*",
"@kubb/plugin-zod": "workspace:*",
"@kubb/react": "workspace:*",
"remeda": "^2.17.4"
"remeda": "^2.18.0"
},
"devDependencies": {
"@kubb/config-ts": "workspace:*",
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-solid-query/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
"@kubb/plugin-ts": "workspace:*",
"@kubb/plugin-zod": "workspace:*",
"@kubb/react": "workspace:*",
"remeda": "^2.17.4"
"remeda": "^2.18.0"
},
"devDependencies": {
"@kubb/config-ts": "workspace:*",
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-svelte-query/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
"@kubb/plugin-ts": "workspace:*",
"@kubb/plugin-zod": "workspace:*",
"@kubb/react": "workspace:*",
"remeda": "^2.17.4"
"remeda": "^2.18.0"
},
"devDependencies": {
"@kubb/config-ts": "workspace:*",
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-swr/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
"@kubb/plugin-ts": "workspace:*",
"@kubb/plugin-zod": "workspace:*",
"@kubb/react": "workspace:*",
"remeda": "^2.17.4"
"remeda": "^2.18.0"
},
"devDependencies": {
"@kubb/config-ts": "workspace:*",
Expand Down
35 changes: 31 additions & 4 deletions packages/plugin-ts/src/__snapshots__/parser.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -634,8 +634,20 @@ NodeObject {
"kind": 187,
"localSymbol": undefined,
"members": [
NodeObject {
"emitNode": undefined,
{
"emitNode": {
"leadingComments": [
{
"end": -1,
"hasTrailingNewLine": true,
"kind": 3,
"pos": -1,
"text": "*
* @minLength 2
",
},
],
},
"end": -1,
"flags": 16,
"id": 0,
Expand Down Expand Up @@ -795,6 +807,7 @@ NodeObject {
"pos": -1,
"text": "*
* @deprecated
* @minLength 2
* @default test
",
},
Expand Down Expand Up @@ -849,6 +862,7 @@ NodeObject {
"kind": 3,
"pos": -1,
"text": "*
* @minLength 3
* @default 2
* @example 2
",
Expand Down Expand Up @@ -1340,6 +1354,7 @@ NodeObject {
"pos": -1,
"text": "*
* @description Your address
* @minLength 4
* @type string, string
",
},
Expand Down Expand Up @@ -1421,8 +1436,20 @@ NodeObject {
"kind": 187,
"localSymbol": undefined,
"members": [
NodeObject {
"emitNode": undefined,
{
"emitNode": {
"leadingComments": [
{
"end": -1,
"hasTrailingNewLine": true,
"kind": 3,
"pos": -1,
"text": "*
* @minLength 2
",
},
],
},
"end": -1,
"flags": 16,
"id": 0,
Expand Down
Loading

0 comments on commit 45ecf9f

Please sign in to comment.