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

Schemas that have a name with a '-' character in them cause invalid code to be generated #83

Closed
wxyangf opened this issue Apr 21, 2024 · 6 comments · Fixed by #84
Closed
Assignees
Labels
bug Something isn't working

Comments

@wxyangf
Copy link

wxyangf commented Apr 21, 2024

eg:

"Schema-Name": {
  "id": {
         "type": "integer",
          "title": "Id"
    }
   ...
}

Will generate code that looks like this:

export const $Schema-Name= {
    properties: {
        id: {
            type: 'integer',
            title: 'Id'
        }
        ...
     }

Dashes are not valid characters for javascript variable names, but are valid strings for json keys.

Not sure the best way to deal with this, maybe export an object instead, mangle to a _ or just explicitly not support having - in schema names and add a test for that.

@seriouslag
Copy link
Collaborator

Thank you for opening an issue.

If you don't need the schemas you can pass false to the generate schema option.

This was an issue with @hey-api/openapi-ts.
Fixed in version 0.39

We will need to update. They have changed many APIs in the meantime, may take some time.

@seriouslag seriouslag added the bug Something isn't working label Apr 21, 2024
@wxyangf
Copy link
Author

wxyangf commented Apr 21, 2024

Thanks for taking a look at this so quickly!

I was planning on working around this by changing my backend openapi generation -- but I figured it would be good to get the bug report in.

Sorry, but how do you disable schema generation? It doesn't seem to be an option in the cli invocation?

@seriouslag
Copy link
Collaborator

seriouslag commented Apr 22, 2024

Thanks for taking a look at this so quickly!

I was planning on working around this by changing my backend openapi generation -- but I figured it would be good to get the bug report in.

Sorry, but how do you disable schema generation? It doesn't seem to be an option in the cli invocation?

Sorry seems, we didn't expose that option.
I opened a PR #84 to update @hey-api/openapi-ts which fixes the schema issue.
I also added the CLI option, --noSchemas so we can disable schema generation in the future.

@Corepex
Copy link
Contributor

Corepex commented Apr 22, 2024

eg:

"Schema-Name": {
  "id": {
         "type": "integer",
          "title": "Id"
    }
   ...
}

Will generate code that looks like this:

export const $Schema-Name= {
    properties: {
        id: {
            type: 'integer',
            title: 'Id'
        }
        ...
     }

Dashes are not valid characters for javascript variable names, but are valid strings for json keys.

Not sure the best way to deal with this, maybe export an object instead, mangle to a _ or just explicitly not support having - in schema names and add a test for that.

faced the same issue for e.g. $AccessToken.jsonld-user.read

seriouslag added a commit that referenced this issue Apr 22, 2024
- Update to the latest `@hey-api/openapi-ts` version `0.42.1`
- Fixed a bug where types in mutation hooks were imported from a (non-relative) direct file import.
    - This is the same fix implemented in #61, which was done for query hooks.
- Fixed a bug where JSDocs were not being added to generated hooks.
- Add more unit tests

Fixes: #83
Enables work towards: #81
@seriouslag seriouslag self-assigned this Apr 22, 2024
seriouslag added a commit that referenced this issue Apr 23, 2024
- Update to the latest `@hey-api/openapi-ts` version `0.42.1`
  - fixes: #83,
  - Enables work towards #81
- Fixed a bug where types in mutation hooks were imported from a (non-relative) direct file import.
    - This is the same fix implemented in #61, which was done for query hooks.
    - Expand the match regex to take account of non-alphabetical file paths
      - fixes: #85
- Fixed a bug where JSDocs were not being added to generated hooks.
- Add more unit testing
@7nohe 7nohe closed this as completed in #84 Apr 23, 2024
@seriouslag
Copy link
Collaborator

This was fixed in 1.2.0

@Corepex
Copy link
Contributor

Corepex commented Apr 24, 2024

works now for me - updated yesterday 💯

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.

3 participants