Skip to content

Commit

Permalink
fix: use of baseURL for Zodios (#631)
Browse files Browse the repository at this point in the history
  • Loading branch information
stijnvanhulle authored Nov 12, 2023
1 parent 426a3ff commit f5dbd2f
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion examples/advanced/src/gen/zodios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,6 @@ const endpoints = makeApi([
},
])

export const api = new Zodios(endpoints)
export const api = new Zodios('https://petstore3.swagger.io/api/v3', endpoints)

export default api
2 changes: 1 addition & 1 deletion examples/zodios/src/gen/zodios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,6 @@ const endpoints = makeApi([
},
])

export const api = new Zodios(endpoints)
export const api = new Zodios('https://petstore3.swagger.io/api/v3', endpoints)

export default api
13 changes: 11 additions & 2 deletions packages/swagger-zodios/src/generators/OperationGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import type { KubbFile } from '@kubb/core'
import type { HttpMethod, OpenAPIV3, Operation, Resolver } from '@kubb/swagger'

type Options = {
baseURL?: string
output: string
}

Expand Down Expand Up @@ -353,13 +354,21 @@ export class OperationGenerator extends Generator<Options> {

const sources: string[] = []

sources.push(`
const endpoints = makeApi([${definitions.join(',')}]);
sources.push(`const endpoints = makeApi([${definitions.join(',')}]);`)

if (this.options.baseURL) {
sources.push(`
export const api = new Zodios('${this.options.baseURL}', endpoints);
export default api;
`)
} else {
sources.push(`
export const api = new Zodios(endpoints);
export default api;
`)
}

return {
path: zodios.path,
Expand Down
1 change: 1 addition & 0 deletions packages/swagger-zodios/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export const definePlugin = createPlugin<PluginOptions>((options) => {

const operationGenerator = new OperationGenerator(
{
baseURL: await swaggerPlugin.api.getBaseURL(),
output,
},
{
Expand Down
1 change: 1 addition & 0 deletions release-please-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
],
"packages": {
".": {
"component": "kubb",
"changelog-path": "CHANGELOG.md",
"release-type": "node",
"bump-minor-pre-major": false,
Expand Down

1 comment on commit f5dbd2f

@vercel
Copy link

@vercel vercel bot commented on f5dbd2f Nov 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

kubb – ./

kubb-git-main-kubb.vercel.app
www.kubb.dev
kubb-kubb.vercel.app
kubb.dev
beta.kubb.dev

Please sign in to comment.