diff --git a/opapi/package.json b/opapi/package.json index 03d63e231..ed0cab95a 100644 --- a/opapi/package.json +++ b/opapi/package.json @@ -1,6 +1,6 @@ { "name": "@bpinternal/opapi", - "version": "0.18.0", + "version": "0.18.1", "description": "Opapi is a highly opinionated library to generate server, client and documentation from OpenAPI specification using typescript.", "main": "./dist/index.js", "module": "./dist/index.mjs", diff --git a/opapi/src/opapi.ts b/opapi/src/opapi.ts index 5041d47c9..58d4b4c2b 100644 --- a/opapi/src/opapi.ts +++ b/opapi/src/opapi.ts @@ -98,7 +98,7 @@ function exportClient(state: State) { options = propsOrEndpoint } - state = applyExportOptions(state, postProcessorsAndStateOpts) + state = applyExportOptions(state, options) if (options.generator === 'openapi-generator') { return generateClientWithOpenapiGenerator(state, dir, options.endpoint, options.postProcessors) diff --git a/opapi/test/api.ts b/opapi/test/api.ts index 9c39f55de..b0598ed2e 100644 --- a/opapi/test/api.ts +++ b/opapi/test/api.ts @@ -44,6 +44,14 @@ export const getMockApi = () => { type: 'FooNotFound', }, ], + defaultParameters: { + xFoo: { + in: 'header', + description: 'Foo', + type: 'string', + required: true, + }, + }, metadata: { title: 'Test API', description: 'Test API', diff --git a/opapi/test/client.test.ts b/opapi/test/client.test.ts index 809c924c7..2497687e7 100644 --- a/opapi/test/client.test.ts +++ b/opapi/test/client.test.ts @@ -1,8 +1,9 @@ -import { describe, it } from 'vitest' +import { describe, expect, it } from 'vitest' import { getMockApi } from './api' import { join } from 'path' import { getFiles } from '../src/file' import { validateTypescriptFile } from './util' +import fs from 'node:fs' describe('client generator', () => { it('should be able to generate a client with openapi-generator', async () => { @@ -38,4 +39,33 @@ describe('client generator', () => { } }) }) + + it('should not include defaultParameters when ignoreDefaultParameters: true', async () => { + const genClientFolder = join(__dirname, 'gen/client-opapi-no-default') + + const api = getMockApi() + + await api.exportClient(genClientFolder, { + generator: 'opapi', + ignoreDefaultParameters: true, + }) + + const files = getFiles(genClientFolder) + + files.forEach((file) => { + if (file.endsWith('.ts')) { + validateTypescriptFile(file) + } + }) + await Promise.all( + files + .filter((file) => file.includes('operations')) + .map(async (file) => { + const content = fs.readFileSync(file, { encoding: 'utf8' }) + if (content.includes('xFoo')) { + throw new Error(`'xFoo' parameter should not be included in ${file}`) + } + }), + ) + }) })