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

Incorrect import path when schema begins with underscore #1874

Open
ryanlaney opened this issue Feb 4, 2025 · 7 comments · Fixed by #1946
Open

Incorrect import path when schema begins with underscore #1874

ryanlaney opened this issue Feb 4, 2025 · 7 comments · Fixed by #1946
Labels
tanstack-query TanStack Query related issue
Milestone

Comments

@ryanlaney
Copy link

Using output mode = tags, if a schema begin with an underscore, the following occurs:

  • A schema .ts file is generated, whose name also begins with an underscore
  • The other schema .ts files attempt to import the generated TypeScript interface at the incorrect path (without an underscore)

Example schema.yaml ("Pets" has been changed to "_Pets")

openapi: 3.0.3
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/PetsArray'
        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:
        '201':
          description: Null response
        default:
          description: unexpected error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
  /pets-nested-array:
    get:
      summary: List all pets as nested array
      operationId: listPetsNestedArray
      tags:
        - pets, pets-nested-array
      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/PetsNestedArray'
        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: integer
          format: int64
        name:
          type: string
          description: 'Name of pet'
          maxLength: 0
          minLength: 40
        age:
          type: integer
          format: int32
          minimum: 0
          maximum: 30
          exclusiveMinimum: true
          exclusiveMaximum: true
        tag:
          type: string
          pattern: '^\\d{3}-\\d{2}-\\d{4}$'
          nullable: true
        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']
    PetsNestedArray:
      type: object
      required:
        - pets
      properties:
        data:
          type: array
          items:
            $ref: '#/components/schemas/_Pet'
    PetsArray:
      type: array
      minItems: 1
      maxItems: 20
      items:
        $ref: '#/components/schemas/_Pet'
    Error:
      type: object
      required:
        - code
        - message
      properties:
        code:
          type: integer
          format: int32
        message:
          type: string

orval.config.ts

module.exports = {
  'api-file': {
    input: {
      target: "schema.yaml",
    },
    output: {
      mode: "tags",
      target: "./src/orval/api",
      schemas: "./src/orval/schema",
      client: "react-query",
      override: {
        header: (info) => [
          `Generated by orval 🍺`,
          `Do not edit manually.`,
          ...(info.title ? [info.title] : []),
          ...(info.description ? [info.description] : []),
          ...(info.version ? [`OpenAPI spec version: ${info.version}`] : []),
          "eslint-disable"
        ],
      }
    }
  },
};

Output:

Image

This seems to be an issue in 7.5.0, but 7.4.1 works fine!

@melloware melloware added the tanstack-query TanStack Query related issue label Feb 13, 2025
@maastrich
Copy link

Same problem on my side 👀

@pierresisson
Copy link

hello, same :D

@melloware
Copy link
Collaborator

Can you guys look through the tickets fixed between 7.4.1 and 7.5.0 and narrow down the culprit?

@maastrich
Copy link

I see two possibilites (I have not looked much into it yet)

feat: Sanitize model names in #1859
fix(core): fallback to non-pascaled name #1847

@melloware
Copy link
Collaborator

Agreed i saw those also.

@AllieJonsson
Copy link
Contributor

Is this fixed by #1946 ?

@melloware
Copy link
Collaborator

Yes @maastrich can you try 7.6.0 and report back?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tanstack-query TanStack Query related issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants