orval-labs / orval

orval is able to generate client with appropriate type-signatures (TypeScript) from any valid OpenAPI v3 or Swagger v2 specification, either in yaml or json formats. 🍺
https://orval.dev
MIT License
3.18k stars 336 forks source link

Overwriting schema names #1658

Closed razzeee closed 3 days ago

razzeee commented 1 month ago

What are the steps to reproduce this issue?

  1. Write an orval config consuming two apis
import { InfoObject } from "openapi3-ts/oas30"

import { defineConfig } from "orval"

export default defineConfig({
  "one": {
    output: {
      workspace: "src/api",
      client: "react-query",
      mode: "tags-split",
      mock: true,
      prettier: true,
      clean: true,
      override: {
        query: {
          useQuery: true,
          useSuspenseQuery: true,
        },
        header: (info: InfoObject): string[] => [
          `Generated by orval 🍺`,
          `Do not edit manually.`,
          ...(info.title ? [info.title] : []),
          ...(info.description ? [info.description] : []),
          ...(info.version ? [`OpenAPI spec version: ${info.version}`] : []),
        ],
      },
    },
    input: {
      target: "./one.openapi.yaml",
    },
  },
  "two": {
    output: {
      workspace: "src/api",
      client: "react-query",
      mode: "tags-split",
      mock: true,
      prettier: true,
      clean: true,
      override: {
        query: {
          useQuery: true,
          useSuspenseQuery: true,
        },
        header: (info: InfoObject): string[] => [
          `Generated by orval 🍺`,
          `Do not edit manually.`,
          ...(info.title ? [info.title] : []),
          ...(info.description ? [info.description] : []),
          ...(info.version ? [`OpenAPI spec version: ${info.version}`] : []),
        ],
      },
    },
    input: {
      target: "./two.openapi.yaml",
    },
  }
  1. Run orval to generate

What happens?

Get errors in src/api/index.ts as the names are the same

What were you expecting to happen?

I can't find a way to change the generated schema names Operation names seem solveable by doing

{
 override: {
         operationName: (operation, route, verb) => {
          return `two${operation.operationId}`
        }
  }
}

What versions are you using?

System: OS: Linux 6.10 Fedora Linux 40 (Workstation Edition) CPU: (16) x64 AMD Ryzen 7 PRO 8840U w/ Radeon 780M Graphics Memory: 11.21 GB / 30.00 GB Container: Yes Shell: 5.9 - /usr/bin/zsh npmPackages: @tanstack/react-query: ^5.52.2 => 5.52.2 axios: ^1.7.2 => 1.7.5 msw: ^2.3.5 => 2.3.5 orval: ^7.0.1 => 7.0.1 react: ^18.3.1 => 18.3.1

melloware commented 3 days ago

@razzeee here you go : https://gurubase.io/g/orval/change-generated-schema-names-in-orval