diff --git a/.vscode/settings.json b/.vscode/settings.json index 56c6035d5..45fcd3d5a 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,3 +1,3 @@ { - "cSpell.words": ["listitem", "Petstore", "tanstack"] + "cSpell.words": ["listitem", "openapi", "Orval", "Petstore", "tanstack"] } diff --git a/docs/src/pages/reference/configuration/full-example.md b/docs/src/pages/reference/configuration/full-example.md index 4812d5d07..3468a3e74 100644 --- a/docs/src/pages/reference/configuration/full-example.md +++ b/docs/src/pages/reference/configuration/full-example.md @@ -46,6 +46,8 @@ module.exports = { delay: 500, }, }, + allParamsOptional: true, + urlEncodeParameters: true, }, input: { target: './petstore.yaml', diff --git a/docs/src/pages/reference/configuration/output.md b/docs/src/pages/reference/configuration/output.md index 69e575749..cb07f03ff 100644 --- a/docs/src/pages/reference/configuration/output.md +++ b/docs/src/pages/reference/configuration/output.md @@ -1379,3 +1379,39 @@ module.exports = { }, }; ``` + +### allParamsOptional + +Type: `Boolean` + +Valid values: true or false. Defaults to false. Applies to all clients, but probably only makes sense for Tanstack Query. + +Use this property to make all parameters optional. This is useful to take advantage of the Orval's auto-enable feature for Tanstack Query, see https://github.com/anymaniax/orval/pull/894 + +```js +module.exports = { + petstore: { + output: { + allParamsOptional: true, + }, + }, +}; +``` + +### urlEncodeParameters + +Type: `Boolean` + +Valid values: true or false. Defaults to false. **Note:** this only works for Tanstack Query clients for now. + +Use this property to enable URL encoding of path/query parameters. This is highly recommended, and will probably become a default in the future, see https://github.com/anymaniax/orval/pull/895 + +```js +module.exports = { + petstore: { + output: { + urlEncodeParameters: true, + }, + }, +}; +``` diff --git a/packages/core/src/types.ts b/packages/core/src/types.ts index 477d33018..933b62687 100644 --- a/packages/core/src/types.ts +++ b/packages/core/src/types.ts @@ -9,6 +9,7 @@ import { ResponsesObject, SchemaObject, } from 'openapi3-ts'; +// @ts-ignore // FIXME when running `yarn test` getting `orval:test: ../core/src/types.ts(12,34): error TS7016: Could not find a declaration file for module 'swagger2openapi'. '/home/maxim/orval/node_modules/swagger2openapi/index.js' implicitly has an 'any' type.` import swagger2openapi from 'swagger2openapi'; import type { allLocales } from '@faker-js/faker'; @@ -55,6 +56,7 @@ export type NormalizedOutputOptions = { indexFiles: boolean; baseUrl?: string; allParamsOptional: boolean; + urlEncodeParameters: boolean; }; export type NormalizedParamsSerializerOptions = { @@ -172,6 +174,7 @@ export type OutputOptions = { indexFiles?: boolean; baseUrl?: string; allParamsOptional?: boolean; + urlEncodeParameters?: boolean; }; export type SwaggerParserOptions = Omit & { @@ -197,6 +200,7 @@ export const OutputClient = { SVELTE_QUERY: 'svelte-query', VUE_QUERY: 'vue-query', SWR: 'swr', + ZOD: 'zod', } as const; export type OutputClient = typeof OutputClient[keyof typeof OutputClient]; @@ -606,6 +610,7 @@ export type ClientBuilder = ( verbOptions: GeneratorVerbOptions, options: GeneratorOptions, outputClient: OutputClient | OutputClientFunc, + output?: NormalizedOutputOptions, ) => GeneratorClient | Promise; export type ClientHeaderBuilder = (params: { @@ -818,6 +823,7 @@ export type GeneratorClientTitle = (data: { outputClient?: OutputClient | OutputClientFunc; title: string; customTitleFunc?: (title: string) => string; + output: NormalizedOutputOptions; }) => GeneratorClientExtra; export type GeneratorClientHeader = (data: { @@ -828,6 +834,7 @@ export type GeneratorClientHeader = (data: { provideIn: boolean | 'root' | 'any'; hasAwaitedType: boolean; titles: GeneratorClientExtra; + output: NormalizedOutputOptions; }) => GeneratorClientExtra; export type GeneratorClientFooter = (data: { @@ -836,6 +843,7 @@ export type GeneratorClientFooter = (data: { hasMutator: boolean; hasAwaitedType: boolean; titles: GeneratorClientExtra; + output: NormalizedOutputOptions; }) => GeneratorClientExtra; export type GeneratorClientImports = (data: { @@ -851,6 +859,7 @@ export type GeneratorClientImports = (data: { hasGlobalMutator: boolean; hasParamsSerializerOptions: boolean; packageJson?: PackageJson; + output: NormalizedOutputOptions; }) => string; export type GenerateMockImports = (data: { diff --git a/packages/core/src/writers/single-mode.ts b/packages/core/src/writers/single-mode.ts index ef14382b4..e8752a6f2 100644 --- a/packages/core/src/writers/single-mode.ts +++ b/packages/core/src/writers/single-mode.ts @@ -65,6 +65,7 @@ export const writeSingleMode = async ({ hasGlobalMutator: !!output.override.mutator, hasParamsSerializerOptions: !!output.override.paramsSerializerOptions, packageJson: output.packageJson, + output, }); if (output.mock) { diff --git a/packages/core/src/writers/split-mode.ts b/packages/core/src/writers/split-mode.ts index 633a7bd45..65385c0e3 100644 --- a/packages/core/src/writers/split-mode.ts +++ b/packages/core/src/writers/split-mode.ts @@ -57,6 +57,7 @@ export const writeSplitMode = async ({ hasGlobalMutator: !!output.override.mutator, hasParamsSerializerOptions: !!output.override.paramsSerializerOptions, packageJson: output.packageJson, + output, }); mockData += builder.importsMock({ implementation: implementationMock, diff --git a/packages/core/src/writers/split-tags-mode.ts b/packages/core/src/writers/split-tags-mode.ts index f1ae3d112..31de74052 100644 --- a/packages/core/src/writers/split-tags-mode.ts +++ b/packages/core/src/writers/split-tags-mode.ts @@ -62,6 +62,7 @@ export const writeSplitTagsMode = async ({ hasGlobalMutator: !!output.override.mutator, hasParamsSerializerOptions: !!output.override.paramsSerializerOptions, packageJson: output.packageJson, + output, }); mockData += builder.importsMock({ implementation: implementationMock, diff --git a/packages/core/src/writers/tags-mode.ts b/packages/core/src/writers/tags-mode.ts index 891f68c1e..bda37f7ae 100644 --- a/packages/core/src/writers/tags-mode.ts +++ b/packages/core/src/writers/tags-mode.ts @@ -68,6 +68,7 @@ export const writeTagsMode = async ({ hasGlobalMutator: !!output.override.mutator, hasParamsSerializerOptions: !!output.override.paramsSerializerOptions, packageJson: output.packageJson, + output, }); if (output.mock) { diff --git a/packages/core/src/writers/target-tags.ts b/packages/core/src/writers/target-tags.ts index b823530a8..1fd0e3054 100644 --- a/packages/core/src/writers/target-tags.ts +++ b/packages/core/src/writers/target-tags.ts @@ -118,6 +118,7 @@ export const generateTargetForTags = ( outputClient: options.client, title: pascal(tag), customTitleFunc: options.override.title, + output: options, }); const footer = builder.footer({ @@ -126,6 +127,7 @@ export const generateTargetForTags = ( hasMutator: !!target.mutators?.length, hasAwaitedType, titles, + output: options, }); const header = builder.header({ @@ -136,6 +138,7 @@ export const generateTargetForTags = ( provideIn: options.override.angular.provideIn, hasAwaitedType, titles, + output: options, }); acc[tag] = { diff --git a/packages/core/src/writers/target.ts b/packages/core/src/writers/target.ts index 9aef8f4d6..25e8df17b 100644 --- a/packages/core/src/writers/target.ts +++ b/packages/core/src/writers/target.ts @@ -20,6 +20,7 @@ export const generateTarget = ( outputClient: options.client, title: pascal(builder.info.title), customTitleFunc: options.override.title, + output: options, }); const target = Object.values(builder.operations).reduce( @@ -67,6 +68,7 @@ export const generateTarget = ( provideIn: options.override.angular.provideIn, hasAwaitedType, titles, + output: options, }); acc.implementation = header.implementation + acc.implementation; acc.implementationMock.handler = @@ -78,6 +80,7 @@ export const generateTarget = ( hasMutator: !!acc.mutators.length, hasAwaitedType, titles, + output: options, }); acc.implementation += footer.implementation; acc.implementationMock.handler += footer.implementationMock; diff --git a/packages/orval/package.json b/packages/orval/package.json index eb456d744..00f6aed79 100644 --- a/packages/orval/package.json +++ b/packages/orval/package.json @@ -44,7 +44,8 @@ "build": "tsup ./src/bin/orval.ts ./src/index.ts --target node12 --clean --dts", "dev": "tsup ./src/bin/orval.ts ./src/index.ts --target node12 --clean --watch ./src --onSuccess 'yarn generate-api'", "lint": "eslint src/**/*.ts", - "generate-api": "node ./dist/bin/orval.js --config ../../samples/react-query/basic/orval.config.ts" + "generate-api": "node ./dist/bin/orval.js --config ../../samples/react-query/basic/orval.config.ts", + "test": "tsc --noEmit && vitest --passWithNoTests" }, "devDependencies": { "@types/inquirer": "^9.0.6", diff --git a/packages/orval/src/api.ts b/packages/orval/src/api.ts index a52a95e87..2fd333a6f 100644 --- a/packages/orval/src/api.ts +++ b/packages/orval/src/api.ts @@ -111,8 +111,10 @@ export const getApiBuilder = async ({ override: output.override, context: resolvedContext, mock: output.mock, + // @ts-expect-error // FIXME output: output.target, }, + output, ); acc.schemas.push(...schemas); diff --git a/packages/orval/src/client.ts b/packages/orval/src/client.ts index 0937526a1..8584b2338 100644 --- a/packages/orval/src/client.ts +++ b/packages/orval/src/client.ts @@ -13,6 +13,7 @@ import { GeneratorVerbOptions, GeneratorVerbsOptions, isFunction, + NormalizedOutputOptions, OutputClient, OutputClientFunc, pascal, @@ -24,18 +25,21 @@ import zod from '@orval/zod'; const DEFAULT_CLIENT = OutputClient.AXIOS; -export const GENERATOR_CLIENT: GeneratorClients = { - axios: axios({ type: 'axios' })(), - 'axios-functions': axios({ type: 'axios-functions' })(), - angular: angular()(), - 'react-query': query({ type: 'react-query' })(), - 'svelte-query': query({ type: 'svelte-query' })(), - 'vue-query': query({ type: 'vue-query' })(), - swr: swr()(), - zod: zod()(), -}; +const getGeneratorClient = ( + outputClient: OutputClient | OutputClientFunc, + output: NormalizedOutputOptions, +) => { + const GENERATOR_CLIENT: GeneratorClients = { + axios: axios({ type: 'axios' })(), + 'axios-functions': axios({ type: 'axios-functions' })(), + angular: angular()(), + 'react-query': query({ output, type: 'react-query' })(), + 'svelte-query': query({ output, type: 'svelte-query' })(), + 'vue-query': query({ output, type: 'vue-query' })(), + swr: swr()(), + zod: zod()(), + }; -const getGeneratorClient = (outputClient: OutputClient | OutputClientFunc) => { const generator = isFunction(outputClient) ? outputClient(GENERATOR_CLIENT) : GENERATOR_CLIENT[outputClient]; @@ -57,8 +61,9 @@ export const generateClientImports: GeneratorClientImports = ({ hasGlobalMutator, hasParamsSerializerOptions, packageJson, + output, }) => { - const { dependencies } = getGeneratorClient(client); + const { dependencies } = getGeneratorClient(client, output); return generateDependencyImports( implementation, dependencies @@ -85,8 +90,9 @@ export const generateClientHeader: GeneratorClientHeader = ({ provideIn, hasAwaitedType, titles, + output, }) => { - const { header } = getGeneratorClient(outputClient); + const { header } = getGeneratorClient(outputClient, output); return { implementation: header ? header({ @@ -108,8 +114,9 @@ export const generateClientFooter: GeneratorClientFooter = ({ hasMutator, hasAwaitedType, titles, + output, }) => { - const { footer } = getGeneratorClient(outputClient); + const { footer } = getGeneratorClient(outputClient, output); if (!footer) { return { @@ -155,8 +162,9 @@ export const generateClientTitle: GeneratorClientTitle = ({ outputClient = DEFAULT_CLIENT, title, customTitleFunc, + output, }) => { - const { title: generatorTitle } = getGeneratorClient(outputClient); + const { title: generatorTitle } = getGeneratorClient(outputClient, output); if (!generatorTitle) { return { @@ -196,18 +204,27 @@ const generateMock = ( return options.mock(verbOption, options); } - return mock.generateMock(verbOption, options); + return mock.generateMock( + verbOption, + options as typeof options & { + mock: Exclude; + }, + ); }; export const generateOperations = ( outputClient: OutputClient | OutputClientFunc = DEFAULT_CLIENT, verbsOptions: GeneratorVerbsOptions, options: GeneratorOptions, + output: NormalizedOutputOptions, ): Promise => { return asyncReduce( verbsOptions, async (acc, verbOption) => { - const { client: generatorClient } = getGeneratorClient(outputClient); + const { client: generatorClient } = getGeneratorClient( + outputClient, + output, + ); const client = await generatorClient(verbOption, options, outputClient); const generatedMock = generateMock(verbOption, options); @@ -218,7 +235,9 @@ export const generateOperations = ( acc[verbOption.operationId] = { implementation: verbOption.doc + client.implementation, imports: client.imports, + // @ts-expect-error // FIXME implementationMock: generatedMock.implementation, + // @ts-expect-error // FIXME importsMock: generatedMock.imports, tags: verbOption.tags, mutator: verbOption.mutator, diff --git a/packages/orval/src/import-open-api.ts b/packages/orval/src/import-open-api.ts index 9fb9dba45..e207ef9bb 100644 --- a/packages/orval/src/import-open-api.ts +++ b/packages/orval/src/import-open-api.ts @@ -33,6 +33,7 @@ export const importOpenApi = async ({ const schemas = getApiSchemas({ output, target, workspace, specs }); const api = await getApiBuilder({ + // @ts-expect-error // FIXME input, output, context: { diff --git a/packages/orval/src/import-specs.ts b/packages/orval/src/import-specs.ts index 0458aa50e..474647db9 100644 --- a/packages/orval/src/import-specs.ts +++ b/packages/orval/src/import-specs.ts @@ -63,6 +63,7 @@ export const importSpecs = async ( if (isObject(input.target)) { return importOpenApi({ data: { [workspace]: input.target }, + // @ts-expect-error // FIXME input, output, target: workspace, @@ -70,9 +71,11 @@ export const importSpecs = async ( }); } + // @ts-expect-error // FIXME const isPathUrl = isUrl(input.target); const data = await resolveSpecs( + // @ts-expect-error // FIXME input.target, input.parserOptions, isPathUrl, @@ -81,8 +84,10 @@ export const importSpecs = async ( return importOpenApi({ data, + // @ts-expect-error // FIXME input, output, + // @ts-expect-error // FIXME target: input.target, workspace, }); diff --git a/packages/orval/src/utils/options.ts b/packages/orval/src/utils/options.ts index 35249bee7..10ce3380c 100644 --- a/packages/orval/src/utils/options.ts +++ b/packages/orval/src/utils/options.ts @@ -215,6 +215,7 @@ export const normalizeOptions = async ( useNativeEnums: outputOptions.override?.useNativeEnums ?? false, }, allParamsOptional: outputOptions.allParamsOptional ?? false, + urlEncodeParameters: outputOptions.urlEncodeParameters ?? false, }, hooks: options.hooks ? normalizeHooks(options.hooks) : {}, }; diff --git a/packages/query/src/index.ts b/packages/query/src/index.ts index 81d0b11e4..1153b779e 100644 --- a/packages/query/src/index.ts +++ b/packages/query/src/index.ts @@ -33,6 +33,7 @@ import { GetterQueryParam, compareVersions, getRouteAsArray, + NormalizedOutputOptions, } from '@orval/core'; import omitBy from 'lodash.omitby'; import { @@ -369,14 +370,20 @@ const generateQueryRequestFunction = ( }: GeneratorVerbOptions, { route: _route, context }: GeneratorOptions, outputClient: OutputClient | OutputClientFunc, + output?: NormalizedOutputOptions, ) => { let props = _props; + let route = _route; + if (isVue(outputClient)) { props = vueWrapTypeWithMaybeRef(_props); + route = vueMakeRouteReactive(_route); } - const route: string = makeRouteSafe( - isVue(outputClient) ? vueMakeRouteReactive(_route) : _route, - ); + + if (output?.urlEncodeParameters) { + route = makeRouteSafe(route); + } + const isRequestOptions = override.requestOptions !== false; const isFormData = override.formData !== false; const isFormUrlEncoded = override.formUrlEncoded !== false; @@ -1480,12 +1487,14 @@ export const generateQuery: ClientBuilder = async ( verbOptions, options, outputClient, + output, ) => { const imports = generateVerbImports(verbOptions); const functionImplementation = generateQueryRequestFunction( verbOptions, options, outputClient, + output, ); const { implementation: hookImplementation, mutators } = await generateQueryHook(verbOptions, options, outputClient); @@ -1510,9 +1519,11 @@ export const builder = ({ type = 'react-query', options: queryOptions, + output, }: { type?: 'react-query' | 'vue-query' | 'svelte-query'; options?: QueryOptions; + output?: NormalizedOutputOptions; } = {}) => () => { const client: ClientBuilder = (verbOptions, options, outputClient) => { @@ -1539,7 +1550,7 @@ export const builder = verbOptions.override.query, ); } - return generateQuery(verbOptions, options, outputClient); + return generateQuery(verbOptions, options, outputClient, output); }; return { diff --git a/samples/react-query/basic/src/api/endpoints/petstoreFromFileSpecWithTransformer.ts b/samples/react-query/basic/src/api/endpoints/petstoreFromFileSpecWithTransformer.ts index a04df2dc3..e8fa79cdd 100644 --- a/samples/react-query/basic/src/api/endpoints/petstoreFromFileSpecWithTransformer.ts +++ b/samples/react-query/basic/src/api/endpoints/petstoreFromFileSpecWithTransformer.ts @@ -76,7 +76,7 @@ type Awaited = O extends AwaitedInput ? T : never; */ export const listPets = (params?: ListPetsParams, version: number = 1) => { return customInstance({ - url: `/v${encodeURIComponent(String(version))}/pets`, + url: `/v${version}/pets`, method: 'GET', params, }); @@ -423,7 +423,7 @@ export const createPets = ( version: number = 1, ) => { return customInstance({ - url: `/v${encodeURIComponent(String(version))}/pets`, + url: `/v${version}/pets`, method: 'POST', headers: { 'Content-Type': 'application/json' }, data: createPetsBody, @@ -490,7 +490,7 @@ export const useCreatePets = < */ export const updatePets = (pet: NonReadonly, version: number = 1) => { return customInstance({ - url: `/v${encodeURIComponent(String(version))}/pets`, + url: `/v${version}/pets`, method: 'PUT', headers: { 'Content-Type': 'application/json' }, data: pet, @@ -561,9 +561,7 @@ export const showPetById = ( signal?: AbortSignal, ) => { return customInstance({ - url: `/v${encodeURIComponent(String(version))}/pets/${encodeURIComponent( - String(petId), - )}`, + url: `/v${version}/pets/${petId}`, method: 'GET', signal, }); diff --git a/samples/react-query/custom-client/src/api/endpoints/petstoreFromFileSpecWithTransformer.ts b/samples/react-query/custom-client/src/api/endpoints/petstoreFromFileSpecWithTransformer.ts index b8efe9367..96e533b3c 100644 --- a/samples/react-query/custom-client/src/api/endpoints/petstoreFromFileSpecWithTransformer.ts +++ b/samples/react-query/custom-client/src/api/endpoints/petstoreFromFileSpecWithTransformer.ts @@ -39,7 +39,7 @@ export const useListPetsHook = () => { signal?: AbortSignal, ) => { return listPets({ - url: `/v${encodeURIComponent(String(version))}/pets`, + url: `/v${version}/pets`, method: 'GET', params, signal, @@ -132,7 +132,7 @@ export const useCreatePetsHook = () => { return (createPetsBody: BodyType, version: number = 1) => { return createPets({ - url: `/v${encodeURIComponent(String(version))}/pets`, + url: `/v${version}/pets`, method: 'POST', headers: { 'Content-Type': 'application/json' }, data: createPetsBody, @@ -205,9 +205,7 @@ export const useShowPetByIdHook = () => { return (petId: string, version: number = 1, signal?: AbortSignal) => { return showPetById({ - url: `/v${encodeURIComponent(String(version))}/pets/${encodeURIComponent( - String(petId), - )}`, + url: `/v${version}/pets/${petId}`, method: 'GET', signal, }); diff --git a/samples/react-query/hook-mutator/endpoints.ts b/samples/react-query/hook-mutator/endpoints.ts index 133a2442f..75d7575d1 100644 --- a/samples/react-query/hook-mutator/endpoints.ts +++ b/samples/react-query/hook-mutator/endpoints.ts @@ -180,11 +180,7 @@ export const useShowPetByIdHook = () => { const showPetById = useCustomInstance(); return (petId: string, signal?: AbortSignal) => { - return showPetById({ - url: `/pets/${encodeURIComponent(String(petId))}`, - method: 'GET', - signal, - }); + return showPetById({ url: `/pets/${petId}`, method: 'GET', signal }); }; }; diff --git a/samples/svelte-query/src/api/endpoints/petstoreFromFileSpecWithTransformer.ts b/samples/svelte-query/src/api/endpoints/petstoreFromFileSpecWithTransformer.ts index 9c2303a69..7c67b5ae1 100644 --- a/samples/svelte-query/src/api/endpoints/petstoreFromFileSpecWithTransformer.ts +++ b/samples/svelte-query/src/api/endpoints/petstoreFromFileSpecWithTransformer.ts @@ -31,7 +31,7 @@ export const listPets = ( signal?: AbortSignal, ) => { return customInstance({ - url: `/v${encodeURIComponent(String(version))}/pets`, + url: `/v${version}/pets`, method: 'GET', params, signal, @@ -122,7 +122,7 @@ export const createPets = ( version: number = 1, ) => { return customInstance({ - url: `/v${encodeURIComponent(String(version))}/pets`, + url: `/v${version}/pets`, method: 'POST', headers: { 'Content-Type': 'application/json' }, data: createPetsBody, @@ -190,9 +190,7 @@ export const showPetById = ( signal?: AbortSignal, ) => { return customInstance({ - url: `/v${encodeURIComponent(String(version))}/pets/${encodeURIComponent( - String(petId), - )}`, + url: `/v${version}/pets/${petId}`, method: 'GET', signal, }); diff --git a/samples/vue-query/orval.config.ts b/samples/vue-query/orval.config.ts index 3fb22df4b..5f3773da7 100644 --- a/samples/vue-query/orval.config.ts +++ b/samples/vue-query/orval.config.ts @@ -48,6 +48,7 @@ export default defineConfig({ }, }, allParamsOptional: true, // TODO: this this not a default, maybe consider creating a separate sample to test default behaviour still works; There is a generated test tho (same as named-params for other clients) + urlEncodeParameters: true, // TODO: this this not a default, maybe consider creating a separate sample to test default behaviour still works; There is a generated test tho (same as named-params for other clients) }, input: { target: './petstore.yaml', diff --git a/scripts/update-samples.mjs b/scripts/update-samples.mjs index 10afabd23..00b0d2886 100644 --- a/scripts/update-samples.mjs +++ b/scripts/update-samples.mjs @@ -1,18 +1,25 @@ #!/usr/bin/env zx -await $`cd ./samples/angular-app && yarn && yarn generate-api`; -await $`cd ./samples/basic && yarn && yarn example`; -await $`cd ./samples/react-app && yarn && yarn generate-api`; -await $`cd ./samples/react-query/basic && yarn && yarn generate-api`; -await $`cd ./samples/react-query/custom-client && yarn && yarn generate-api`; -await $`cd ./samples/react-query/form-data && yarn && yarn generate-api`; -await $`cd ./samples/react-query/form-data-mutator && yarn && yarn generate-api`; -await $`cd ./samples/react-query/form-url-encoded && yarn && yarn generate-api`; -await $`cd ./samples/react-query/form-url-encoded-mutator && yarn && yarn generate-api`; -await $`cd ./samples/react-query/hook-mutator && yarn && yarn generate-api`; -await $`cd ./samples/react-app-with-swr && yarn && yarn generate-api`; -await $`cd ./samples/svelte-query && yarn && yarn generate-api`; -await $`cd ./samples/vue-query && yarn && yarn generate-api`; +let result = ''; +result += await $`cd ./samples/angular-app && yarn && yarn generate-api`; +result += await $`cd ./samples/basic && yarn && yarn example`; +result += await $`cd ./samples/react-app && yarn && yarn generate-api`; +result += await $`cd ./samples/react-query/basic && yarn && yarn generate-api`; +result += + await $`cd ./samples/react-query/custom-client && yarn && yarn generate-api`; +result += + await $`cd ./samples/react-query/form-data && yarn && yarn generate-api`; +result += + await $`cd ./samples/react-query/form-data-mutator && yarn && yarn generate-api`; +result += + await $`cd ./samples/react-query/form-url-encoded && yarn && yarn generate-api`; +result += + await $`cd ./samples/react-query/form-url-encoded-mutator && yarn && yarn generate-api`; +result += + await $`cd ./samples/react-query/hook-mutator && yarn && yarn generate-api`; +result += await $`cd ./samples/react-app-with-swr && yarn && yarn generate-api`; +result += await $`cd ./samples/svelte-query && yarn && yarn generate-api`; +result += await $`cd ./samples/vue-query && yarn && yarn generate-api`; /** NOTE: use below to create a sample for `useNamedParameters: true` with code that is supposed to work and pass tests, but it will require changes in Orval code generation * // clean ./samples/vue-query-useNamedParameters @@ -28,6 +35,10 @@ await $`cd ./samples/vue-query && yarn && yarn generate-api`; * // and replace `useShowPetById(petId)` in `samples/vue-query-useNamedParameters/src/components/pet.vue` with `useShowPetById({ version: 1 }, petId)` * await $`sed -i 's/useShowPetById(petId)/useShowPetById({ version: 1 }, petId)/' ./samples/vue-query-useNamedParameters/src/components/pet.vue`; */ -// await $`cd ./samples/vue-query-useNamedParameters && yarn && yarn generate-api`; // TODO: enable this once useNamedParameters actually works with vue-query reactivity +// result += await $`cd ./samples/vue-query-useNamedParameters && yarn && yarn generate-api`; // TODO: enable this once useNamedParameters actually works with vue-query reactivity -// await $`cd ./samples/nx-fastify-react && yarn && yarn generate-api`; // TODO: Fix error `Cannot send the message - the message port has been closed for the process 5163` and re-enable +// result += await $`cd ./samples/nx-fastify-react && yarn && yarn generate-api`; // TODO: Fix error `Cannot send the message - the message port has been closed for the process 5163` and re-enable + +if (result.includes('🛑')) { + throw new Error('Unable to update some samples, see log above for details.'); +} diff --git a/tests/configs/vue-query.config.ts b/tests/configs/vue-query.config.ts index c2f98b446..b0fcaaa2b 100644 --- a/tests/configs/vue-query.config.ts +++ b/tests/configs/vue-query.config.ts @@ -59,6 +59,32 @@ export default defineConfig({ target: '../specifications/petstore.yaml', }, }, + urlEncodeParameters: { + output: { + target: '../generated/vue-query/url-encode-parameters/endpoints.ts', + schemas: '../generated/vue-query/url-encode-parameters/model', + client: 'vue-query', + mock: true, + urlEncodeParameters: true, + }, + input: { + target: '../specifications/petstore.yaml', + }, + }, + combinationUsedByMaximMazurok: { + output: { + target: + '../generated/vue-query/combination-used-by-maxim-mazurok/endpoints.ts', + schemas: '../generated/vue-query/combination-used-by-maxim-mazurok/model', + client: 'vue-query', + mock: true, + allParamsOptional: true, + urlEncodeParameters: true, + }, + input: { + target: '../specifications/petstore.yaml', + }, + }, // Unsupported for now, see for context: https://github.com/anymaniax/orval/pull/931#issuecomment-1752355686 // namedParameters: { // output: {