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

Orval: Cannot resolve double linked $ref #1935

Open
atsoy opened this issue Feb 24, 2025 · 0 comments
Open

Orval: Cannot resolve double linked $ref #1935

atsoy opened this issue Feb 24, 2025 · 0 comments
Labels
bug Something isn't working

Comments

@atsoy
Copy link

atsoy commented Feb 24, 2025

Scenario

Setup / Config

The project has following setup. We maintain index.yaml in the schemas folder (contains $ref).

Folder structure

Expand
.
├── orval/
│ ├── path/
│ │ └── projects.yaml
│ ├── schemas/
│ │ ├── UserDTO.yaml
│ │ ├── UserProjectsDTO.yaml
│ │ └── index.yaml
│ └── parameters/
│ │ └── userId.yaml
├── src/
│ └── api/
│ └── generated // <-- orval generated files (hooks, models etc)
└── myApp.yaml // <-- OpenAPI 3.1 spec

Orval config

// orval.config.js

module.exports = {
  myApp: {
    output: {
      mode: 'tags-split',
      target: './generated/app.ts',
      schemas: './generated/model',
      client: 'react-query',
      mock: true,
      override: {
        useBigInt: true
      },
      clean: true,
      prettier: true
    },
    input: {
      target: './myApp.yaml'
    }
  }
};

./myApp.yaml

Expand
openapi: 3.1.0
info:
  title: My App REST API
  version: 1.0

paths:
  '/user/{userId}/projects':
    $ref: './orval/path/refPathA.yaml#/paths/~1projects'

orval/path/projects.yaml

Expand
openapi: 3.1.0
info:
  title: User Projects
  version: 1.0.0
paths:
  /projects:
    get:
      operationId: getUserProjects
      summary: Retrieve all related projects to the userId
      parameters:
        - $ref: '../parameters/userId.yaml#/components/parameters/userId'
      responses:
        '200':
          description: Default response
          content:
            application/json:
              schema:
                type: array
                  $ref: '../schemas/index.yaml#/components/schemas/UserProjectDTO'  # <-- 1st $ref
        '500':
          description: Error

orval/parameters/userId.yaml

Expand
openapi: 3.1.0
info:
  title: Query Param userId
  version: 1.0.0

components:
  parameters:
    userId:
      name: userId
      in: path
      required: true
      schema:
        type: string

orval/schemas/index.yaml

Expand
openapi: 3.1.0
info:
  title: My App REST Objects
  version: 1.0.0

components:
  schemas:
    UserDTO:
      $ref: './UserDTO.yaml#/components/schemas/User'
    UserProjectDTO:
      $ref: './UserProjectDTO.yaml#/components/schemas/UserProject' # <-- 2nd $ref

orval/schemas/UserDTO.yaml

Expand
openapi: 3.1.0
info:
  title: User DTO
  version: 1.0.0

components:
  schemas:
    User:
      type: object
      required:
        - id
        - firstName
        - lastName
        - age
        - address
      properties:
        id:
          type: string
        firstName:
          type: string
        lastName:
          type: string
        age:
          type: integer
        address:
          type: [string, 'null']

orval/schemas/UserProjectDTO.yaml

Expand
openapi: 3.1.0
info:
  title: User Project DTO
  version: 1.0.0

components:
  schemas:
    User:
      type: object
      required:
        - id
        - title
        - description
        - users
      properties:
        id:
          type: string
        title:
          type: string
        description:
          type: string
        users:
          type: array
            $ref: './index.yaml#/components/schemas/UserDTO'

Issue / Current

After we've updated to 7.x, double linked $ref doesn't work as expected anymore.

Running Orval task to generate Types and React-Query hooks throws the error

MyApp: Cleaning output folder
🛑 MyApp - Oops... 🍻. Ref not found: ../schemas/index.yaml#/components/schemas/UserProjectDTO

This message comes from orval/path/projects.yaml. Apparently double linked $refs canot be resolved properly. It was not the case with the version 6.15.0.

@melloware melloware added the bug Something isn't working label Feb 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants