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

unable to generate when ref name contains illegal characters #1

Closed
joepjoosten opened this issue Jun 26, 2024 · 3 comments
Closed

unable to generate when ref name contains illegal characters #1

joepjoosten opened this issue Jun 26, 2024 · 3 comments

Comments

@joepjoosten
Copy link

I'm parsing the spec for opensearch (https://github.com/opensearch-project/opensearch-api-specification/releases/download/main-latest/opensearch-openapi.yaml) which contains schemas with names like: "cat._common:CatPitSegmentsRecord" or "_common:AcknowledgedResponseBase", which will result in incorrect typescript code because the schemaId generated is invalid.

export const _common:AcknowledgedResponseBase = S.Struct({

  /** For a successful response, this value is always true. On failure, an exception is returned instead. */
  acknowledged: S.Boolean,
}); 
export type _common:AcknowledgedResponseBase = S.Schema.Type<typeof _common:AcknowledgedResponseBase>;
export const _common:AcknowledgedResponseBaseEncoded = S.encodedSchema(_common:AcknowledgedResponseBase);
export type _common:AcknowledgedResponseBaseEncoded = S.Schema.Encoded<typeof _common:AcknowledgedResponseBase>;
@mkrause
Copy link
Collaborator

mkrause commented Jun 26, 2024

You're right, the generator was assuming that schemas have names that are valid JS identifiers. I pushed a fix that:

  1. Encodes names as valid JS identifiers
  2. Adds proper parsing for JSON pointers so that names with special characters (/ and ~) don't cause parse errors.

Also added a test for it. Published as v0.7.0. Let me know if this resolves the issue for you.

@mkrause mkrause closed this as completed Jun 26, 2024
@joepjoosten
Copy link
Author

I will check

@joepjoosten
Copy link
Author

JS identifiers are ok now, but found a new issue #2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants