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.12k stars 335 forks source link

Type alias exports missing when using cross-file $ref #1107

Open nhardy opened 11 months ago

nhardy commented 11 months ago

What are the steps to reproduce this issue?

  1. Create petstore.yml file using https://github.com/OAI/OpenAPI-Specification/blob/main/examples/v3.0/petstore.yaml
  2. Create openapi.yml file using cross-file $refs as:
    openapi: "3.0.0"
    info:
    version: 1.0.0
    title: Swagger Petstore
    license:
    name: MIT
    servers:
    - url: http://petstore.swagger.io/v1
    paths:
    /pets:
    $ref: "petstore.yml#/paths/~1pets"
    /pets/{petId}:
    $ref: "petstore.yml#/paths/~1pets~1{petId}"
    components:
    schemas:
    Pet:
      $ref: "petstore.yml#/components/schemas/Pet"
    Pets:
      $ref: "petstore.yml#/components/schemas/Pets"
    Error:
      $ref: "petstore.yml#/components/schemas/Error"
  3. Create orval.config.ts as:
    
    import { defineConfig } from "orval";
    import path from "path";

export default defineConfig({ api: { input: { target: path.join(__dirname, "openapi.yml"), }, output: { mode: "tags", target: ".generated/index.ts", schemas: ".generated/types", client: "react-query", }, }, });

4. Run `npx orval --config orval.config.ts`
5. Observe that for `.generated/types/error.ts` and `.generated/types/pet.ts` the type alias exports are missing for `Error` and `Pet`.

## What happens?

Some schema files are generated with missing type alias exports. e.g.

`.generated/types/pet.ts`:

```ts
/**
 * Generated by orval v6.22.1 🍺
 * Do not edit manually.
 * Swagger Petstore
 * OpenAPI spec version: 1.0.0
 */
import type { Pet } from './petstore.yml/pet';

What were you expecting to happen?

File to be generated with type alias exports, e.g.

.generated/types/pet.ts

/**
 * Generated by orval v6.22.1 🍺
 * Do not edit manually.
 * Swagger Petstore
 * OpenAPI spec version: 1.0.0
 */
import type { Pet as PetstoreYmlPet } from './petstore.yml/pet';

export type Pet = PetstoreYmlPet;

Any logs, error output, etc?

N/A

Any other comments?

This appears to have been broken since v6.17.0 with the change introduced here: https://github.com/anymaniax/orval/commit/3e46854fbb3965c8ac4aa46ebcd361d8fa113d30#diff-05706d9e4229657eff2f993788e246673cf6928f31befd281e0e484bad755240R66

What versions are you using?

Operating System: macOS Sonoma 14.1.2 Package Version: v6.22.1 (issue since v6.17.0) Browser Version: N/A

melloware commented 11 months ago

Is this similar to #1077 ?

nhardy commented 11 months ago

Is this similar to #1077 ?

I don't think so. This issue (#1107) seems to occur only when using cross-file $refs, whereas #1077 doesn't mention that in examples.