Skip to content

Removed invalid tokens from generic type names #461

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

Closed
wants to merge 1 commit into from

Conversation

rkesters
Copy link
Contributor

@rkesters rkesters commented Jan 14, 2022

Please:

  • Make your pull request atomic, fixing one issue at a time unless there are many relevant issues that cannot be decoupled.
  • Provide a test case & update the documentation in the Readme.md

Fixes #454

Generics type names were being created with '<,>' characters when using theses as URI for the $ref fields they are invalid. Changing this also fixed #454 .

@rkesters rkesters force-pushed the rkesters/generics branch 2 times, most recently from a62cb19 to cb59f6b Compare January 14, 2022 18:45
@rkesters rkesters marked this pull request as ready for review January 14, 2022 18:55
@domoritz
Copy link
Collaborator

I don't want to make this major change. Please make a fork if you want this change.

@domoritz domoritz closed this Jan 14, 2022
@CaselIT
Copy link
Contributor

CaselIT commented Nov 4, 2024

@domoritz would you accept a PR that just url-escapes the url generated for the refs?
Meaning this line

$ref: `${this.args.id}#/definitions/` + fullTypeName,

would become

$ref: `${this.args.id}#/definitions/` + encodeURIComponent(fullTypeName),

or

$ref: encodeURI(`${this.args.id}#/definitions/` + fullTypeName),

@domoritz
Copy link
Collaborator

domoritz commented Nov 4, 2024

How would that affect what genetics look like? If the json schema spec says something about what's allowed, I'm happy to change things. But I want to make sure things remain readable.

@CaselIT
Copy link
Contributor

CaselIT commented Nov 4, 2024

the generics would remain the same in the definition, so Foo<string>, just the $ref to them would change to #/definitions/Foo%3Cstring%3E, since these are url and should ideally be url escaped.

Some json-schema library are strict about the fact that $ref are url, and error if they see an url with angle brackets since that's not a valid character for an url

@domoritz
Copy link
Collaborator

domoritz commented Nov 4, 2024

I have not seen a library that doesn't think these urls are valid. Would be libraries be open to change?

I think these days people expect urls to work even without escaped characters (as it does in browser address fields) even when the url is under the hood encoded.

@domoritz
Copy link
Collaborator

domoritz commented Nov 4, 2024

Having said that, I don't feel too strongly about the change you proposed and would be happy to accept it.

@CaselIT
Copy link
Contributor

CaselIT commented Nov 4, 2024

I have not seen a library that doesn't think these urls are valid. Would be libraries be open to change?

I'm having issues with this library, that triggered this discussion. They make uri interpretation strict recently: https://github.com/Stranger6667/jsonschema/blob/master/crates/jsonschema-py/CHANGELOG.md#changed-5

While annoying I feel like they are doing the correct thing here, since json schema defines $refs as URI, and uri do require percent encoding.

Having said that, I don't feel too strongly about the change you proposed and would be happy to accept it.

Ok, will do. Do you also prefer I open an issue to reference it in changelogs etc?

@domoritz
Copy link
Collaborator

domoritz commented Nov 4, 2024

Yes, issue and pull request would be great.

@DavideCanton
Copy link

I could work on this in these days. I'll open a new issue soon.

@DavideCanton
Copy link

Created #617

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

Successfully merging this pull request may close these issues.

v0.52.0 Unique Names causes generation to fail when using generics
4 participants