openapi-react-query-codegen icon indicating copy to clipboard operation
openapi-react-query-codegen copied to clipboard

A missing `prettier` formatter is silently ignored

Open sschuberth opened this issue 1 year ago • 3 comments

Describe the bug

Generated files under "requests" have tabs instead of spaces although prettier is configured otherwise.

To Reproduce

I have a .prettierrc with

{
    "useTabs": false
}

and run openapi-rq -i http://localhost:8080/swagger-ui/api.json -o src/api --format prettier.

The generated *.ts files have tabs instead of spaces.

OpenAPI spec file

n/a

Expected behavior

Spaces instead of tabs should be used according to the prettier configuration.

Additional context

  • OS: Fedora Linux 40
  • Version 1.3.0

sschuberth avatar May 12 '24 06:05 sschuberth

Ok, seems like the problem simply was that prettier was not installed. Manually installing it and rerunning openapi-rq fixes the problem.

Would it be possible to either:

  • install prettier automatically if configured as a formatter but not present yet on the system, or
  • warn / error out if prettier is configured but not present?

Same for Biome, I guess.

sschuberth avatar May 12 '24 06:05 sschuberth

This you for opening an issue.

This library passes the values provided to @hey-api/openapi-ts to run the formatting.

It would/could become a maintenance burden to add the checks in this library, opening a ticket in @hey-api/openapi-ts package may be helpful.

I personal do not believe a cli command should install a package automatically.

A console warning would be good.

seriouslag avatar May 12 '24 13:05 seriouslag

I am starting to believe we should remove the options for consumers to interface with the format and linter options as this library's generated code will be covered. And change in the underlying service generators formatted would have to maintained in this libraries. Feels hard to maintain. Would be consistent for the consumer to run their own linter and formatted after generating the files.

seriouslag avatar May 15 '24 14:05 seriouslag

I am starting to believe we should remove the options for consumers to interface with the format and linter options as this library's generated code will be covered. And change in the underlying service generators formatted would have to maintained in this libraries. Feels hard to maintain. Would be consistent for the consumer to run their own linter and formatted after generating the files.

I completely agree with you. I think it will also be challenging to keep up with future changes in both Prettier and Biome.

7nohe avatar May 18 '24 07:05 7nohe

I completely agree with you.

For the record, I agree as well, and we have already switched from using the --format to running prettier as a post-processing step.

sschuberth avatar May 18 '24 09:05 sschuberth

So, given that I believe no work is planned to address this as instead the --format option is going to be removed, let me close this.

sschuberth avatar May 18 '24 09:05 sschuberth