Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added output.fileExtension option to possible specifying the extension for the generated file. #1320

Merged

Conversation

soartec-lab
Copy link
Member

@soartec-lab soartec-lab commented Apr 19, 2024

Status

READY

Description

I added output.fileExtension option to possible specifying the extension of the generated file. So, are able to change the automatically generated client code extension to like a pets.gen.ts. The default is still .ts.
Furthermore, by configuring the following settings, you will be able to generate code with both client and zod.

orval.config.js:

import { defineConfig } from "orval";

export default defineConfig({
  petstore: {
    input: {
      target: './petstore.yaml',
    },
    output: {
      client: 'swr',
      mode: 'tags-split',
      target: 'src/gen/endpoints',
      schemas: 'src/gen/model',
      mock: true
    },
  },
  petstoreZod: {
    input: {
      target: './petstore.yaml',
    },
    output: {
      client: 'zod',
      mode: 'tags-split',
      target: 'src/gen/endpoints',
      schemas: 'src/gen/model',
      fileExtension: '.zod.ts',
    },
  },
});

generated files:

src/gen/
├── endpoints
│   └── pets
│       ├── pets.msw.ts
│       ├── pets.ts
│       └── pets.zod.ts
└── model
    ├── error.ts
    ├── index.ts
    ├── listPetsParams.ts
    ├── pet.ts
    ├── pets.ts
    └── showPetByIdParams.ts

This further expands the convenience of orval for me.

Related PRs

none

Todos

  • Tests
  • Documentation
  • Changelog Entry (unreleased)

Steps to Test or Reproduce

Configure the following settings and check whether the automatically generated source code is broken.

import { defineConfig } from "orval";

export default defineConfig({
  petstore: {
    input: {
      target: './petstore.yaml',
    },
    output: {
      client: 'swr',
      mode: 'tags-split',
      target: 'src/gen/endpoints',
      schemas: 'src/gen/model',
      mock: true
    },
  },
  petstoreZod: {
    input: {
      target: './petstore.yaml',
    },
    output: {
      client: 'zod',
      mode: 'tags-split',
      target: 'src/gen/endpoints',
      schemas: 'src/gen/model',
      fileExtension: '.zod.ts',
    },
  },
});

Sorry, something went wrong.

@melloware melloware added this to the 6.28.0 milestone Apr 19, 2024
@melloware melloware added the enhancement New feature or request label Apr 19, 2024
@melloware melloware merged commit 913ac00 into orval-labs:master Apr 19, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants