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

queries not working after upgrading from 0.5.3 to 1.0.6 #75

Closed
sourceful-mia opened this issue Apr 18, 2024 · 10 comments · Fixed by #74
Closed

queries not working after upgrading from 0.5.3 to 1.0.6 #75

sourceful-mia opened this issue Apr 18, 2024 · 10 comments · Fixed by #74
Labels
bug Something isn't working

Comments

@sourceful-mia
Copy link

Very cool repo! Love the work that's being done.

I have an issue with version 1.0 when trying to codegen for a very simple OpenAPI Spec.

When doing codegen with v0.5.3, I get content in my generated index.ts (eg: useDefaultServiceGetProjects)
However, when doing codegen with v1.0.6, none of the files contain the above hook.

My spec is generated with tsoa and valid according to https://editor.swagger.io/

Is something missing from my spec, or is there a bug in this repo?

Here's the spec

openapi: 3.0.0
components:
  examples: {}
  headers: {}
  parameters: {}
  requestBodies: {}
  responses: {}
  schemas:
    Project:
      properties:
        id:
          type: string
        name:
          type: string
        description:
          type: string
      required:
        - id
        - name
        - description
      type: object
      additionalProperties: false
    ProjectCreateParams:
      properties:
        name:
          type: string
      required:
        - name
      type: object
      additionalProperties: false
  securitySchemes: {}
info:
  title: projects-api
  version: 1.0.0
  description: Projects backend for frontend
  license:
    name: ISC
  contact: {}
paths:
  /v1/projects:
    get:
      operationId: GetProjects
      responses:
        "200":
          description: Ok
          content:
            application/json:
              schema:
                items:
                  $ref: "#/components/schemas/Project"
                type: array
      security: []
      parameters: []
    post:
      operationId: CreateProject
      responses:
        "201":
          description: Created
      security: []
      parameters: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/ProjectCreateParams"
  /v1/projects/{id}:
    get:
      operationId: GetProject
      responses:
        "200":
          description: Ok
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Project"
      security: []
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
servers:
  - url: /
@Jakob-Espersen
Copy link

I had a similar problem. For me upgrading my typescript version to the latest worked.

@sourceful-mia
Copy link
Author

I had a similar problem. For me upgrading my typescript version to the latest worked.

I'm on typescript 5.4.5, which is the latest version.

@seriouslag
Copy link
Collaborator

seriouslag commented Apr 18, 2024

@sourceful-mia, sorry you are facing some issues.
Thank you for opening an issue and providing the OpenAPI spec.
I was able to generate the service files and hooks using:

node: 21.x
typescript: 5.4.3
openapi-react-query-codegen: 1.0.6

with the spec file you provided

If you could provide:

  • an example repo,
  • the command you used to call openapi-react-query-codegen

I would gladly take a look further into your problem.

@gynekolog
Copy link

gynekolog commented Apr 18, 2024

The prettier implementation breaks the queries generation.
There's a reproduction: https://stackblitz.com/edit/tanstack-query-e7gu7z

Remove prettier from the dependencies, run npm run codegen and queries are back.

edit: The workaround is to add generated files to the .prettierignore

@seriouslag
Copy link
Collaborator

The prettier implementation breaks the queries generation.

There's a reproduction: https://stackblitz.com/edit/tanstack-query-e7gu7z

Remove prettier from the dependencies, run npm run codegen and queries are back.

edit: The workaround is to add generated files to the .prettierignore

I was able to generate the code using your example with prettier installed and no .prettierignore file. I will have to test more. If you have time to test more I would love more feedback to figure this out

@sourceful-mia
Copy link
Author

sourceful-mia commented Apr 19, 2024

@seriouslag https://github.com/sourceful-mia/rep-openapi-react-query
Here's my rep case repo.

Note: I use node16 because that's my current work env and what I need it to work in.

if you run

nvm install && nvm use
npm install
npm run codegen

then it works fine.

If you then run

npm i prettier
npm run codegen

then it stops working. I think @gynekolog might be right about prettier.

@gynekolog
Copy link

@seriouslag Have you tried it on stackblitz or you made a local clone? I tried to run npm run codegen again, in stackblitz terminal, and queries file contains just imports.

@seriouslag
Copy link
Collaborator

I reproduced the issue, and I will debug it. Thank you

@seriouslag
Copy link
Collaborator

seriouslag commented Apr 19, 2024

I debugged the issue and pushed the fix to #74

Prettier was switching quotes with double quotes and breaking our comparisons.
Changed our comparison to not care about quotes.

Thank you all for helping me debug this!

@seriouslag seriouslag added the bug Something isn't working label Apr 20, 2024
@seriouslag
Copy link
Collaborator

Released a test version with this patch under: @seriouslag/openapi-react-query-codegen@next
Until we merge the patches into this repo 😀

@7nohe 7nohe closed this as completed in #74 Apr 20, 2024
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

Successfully merging a pull request may close this issue.

4 participants