question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

service code is not generated when paths are $refs

See original GitHub issue

What are the steps to reproduce this issue?

  1. set the value of a path to $ref
  2. run generate command
  3. models are generated but hooks and services are not.

What happens?

orval generate command finishes successfully. however the generated files only contain models, no mocks, services, hooks, etc.

What were you expecting to happen?

all code should be generated.

Any logs, error output, etc?

File A (petstore.yaml):

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: "services/pets.yaml#/paths/~1pets"
  /pets/{petId}:
    $ref: "services/pets.yaml#/paths/~1pets-petId"

File B (services/pets.yaml):

openapi: '3.0.0'
info:
  version: 1.0.0
  title: Swagger Petstore
  license:
    name: MIT
servers:
  - url: http://petstore.swagger.io/v1
paths:
  /pets:
    get:
      summary: List all pets
      operationId: listPets
      tags:
        - pets
      parameters:
        - name: limit
          in: query
          description: How many items to return at one time (max 100)
          required: false
          schema:
            type: string
      responses:
        '200':
          description: A paged array of pets
          headers:
            x-next:
              description: A link to the next page of responses
              schema:
                type: string
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Pets'
        default:
          description: unexpected error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
    post:
      summary: Create a pet
      operationId: createPets
      tags:
        - pets
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - 'name'
                - 'tag'
              properties:
                name:
                  type: string
                tag:
                  type: string
      responses:
        '200':
          description: Created Pet
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Pet'
        default:
          description: unexpected error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
  /pets-petId:
    get:
      summary: Info for a specific pet
      operationId: showPetById
      tags:
        - pets
      parameters:
        - name: petId
          in: path
          required: true
          description: The id of the pet to retrieve
          schema:
            type: string
        - name: testId
          in: path
          required: true
          description: The id of the pet to retrieve
          schema:
            type: string
      responses:
        '200':
          description: Expected response to a valid request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Pet'
        default:
          description: unexpected error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
components:
  schemas:
    Pet:
      type: object
      required:
        - id
        - name
      properties:
        '@id':
          type: string
          format: iri-reference
        id:
          type: integer
          format: int64
        name:
          type: string
        tag:
          type: string
        email:
          type: string
          format: email
        callingCode:
          type: string
          enum: ['+33', '+420', '+33'] # intentional duplicated value
        country:
          type: string
          enum: ["People's Republic of China", 'Uruguay']
    Pets:
      type: array
      items:
        $ref: '#/components/schemas/Pet'
    Error:
      type: object
      required:
        - code
        - message
      properties:
        code:
          type: integer
          format: int32
        message:
          type: string

Any other comments?

I discovered this while implementing #260 , turns out there were two similar issues related to refs that I uncovered in my schema.

What versions are you using?

Operating System: MacOS Big Sur 11.6.1 Package Version: 6.3.0 (latest at time of writing) Browser Version: n/a

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
anymaniaxcommented, Nov 24, 2022

You need to use useListPets instead. useListPetsHook is used to be able to pass a custom client or a custom instance of axios to be able to easily add a token for example

1reaction
anymaniaxcommented, Nov 24, 2022

Hello @ravikiranr26 can you try with 6.11.0-alpha.7

Read more comments on GitHub >

github_iconTop Results From Across the Web

Open Api 3 generator does not generate classes for paths ...
When I copy code from /paths/employees.yaml and paste it into employee.yaml paths everything is generated correctly. I dont think this is a ...
Read more >
"ref not found" after new branch pushed (#326066) · Issues
This is an attempt to keep forcibly clearing the cache inside the PostReceive worker until it includes the branches we're looking for. This...
Read more >
Troubleshoot broken references - Visual Studio - Microsoft Learn
Visual Studio for Mac no Visual Studio Code. If your application attempts to use a broken reference, an exception error is generated.
Read more >
Branch 'refs/heads/master' not found in git - SonarQube
Hi, The scanner will try to access the reference branch using git to be able to compute the new code in the branch...
Read more >
OpenAPI Specification - Version 3.0.3 - Swagger
An OpenAPI definition can then be used by documentation generation tools to display the API, code generation tools to generate servers and clients...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found