7nohe / openapi-react-query-codegen

Node.js library that generates React Query (also called TanStack Query) hooks based on an OpenAPI specification file.
253 stars 25 forks source link

Create a test and example using enums. #110

Open seriouslag opened 4 months ago

seriouslag commented 4 months ago

Is your feature request related to a problem? Please describe. There are consumers of this library that use enums, we have no tests or examples showing their generation/usage.

Describe the solution you'd like A unit test or snapshot showing their creation.

Describe alternatives you've considered None,

sschuberth commented 4 months ago

I also struggle to get back the behavior from version 0.5.3 which e.g. generated

export namespace CreateRepository {

    export enum type {
        GIT = 'GIT',
        GIT_REPO = 'GIT_REPO',
        MERCURIAL = 'MERCURIAL',
        SUBVERSION = 'SUBVERSION',
        CVS = 'CVS',
    }

}

instead of version 1.3.0 now generating

export type CreateRepository = {
    type: 'GIT' | 'GIT_REPO' | 'MERCURIAL' | 'SUBVERSION' | 'CVS';
    url: string;
};

Using --enums typescript does not seems to have any effect.

Edit: Here's an excerpt from the used API spec:

      "CreateRepository" : {
        "required" : [ "type", "url" ],
        "type" : "object",
        "properties" : {
          "type" : {
            "type" : "string",
            "enum" : [ "GIT", "GIT_REPO", "MERCURIAL", "SUBVERSION", "CVS" ]
          },
          "url" : {
            "type" : "string"
          }
        }
      },
sschuberth commented 4 months ago

Using --enums typescript does not seems to have any effect.

Maybe this could be related to https://github.com/hey-api/openapi-ts/issues/547?

seriouslag commented 4 months ago

Using --enums typescript does not seems to have any effect.

Maybe this could be related to hey-api/openapi-ts#547?

That does seem related. When they patch @hey-api/openapi-ts, we will need to write some tests to determine whether it is safe to update in the future.

There are lots of moving parts. We would appreciate the help if you have time to write tests that satisfy your use case.

Maybe fallback to an old version of this library until the new release of @hey-api/openapi-ts

primeapple commented 4 months ago

The new version 0.44.0 of openapi-ts fixes this problem and generates enums again.