invopop / jsonschema

Generate JSON Schemas from Go types
MIT License
511 stars 86 forks source link

Kebab-case $id fields break Python jschon parser #81

Open gmlewis opened 1 year ago

gmlewis commented 1 year ago

Structs are currently rendered as kebab-case in the "$id" field. For example, TestUser becomes:

"$id": "https://github.com/invopop/jsonschema/test-user"

When another field attempts to reference this struct, the Python3.10 "jschon" package resports this error:

jschon.exc.CatalogError: A source is not available for "https://github.com/invopop/jsonschema/TestUser"

but if the "$id" line is changed from test-user to TestUser, then the "jschon" package parses the file successfully.

I will work on a PR for this issue.

samlown commented 1 year ago

Hi @gmlewis, surely this is an issue with the Python "jschon" package making assumptions about definition names? Generally speaking, snake-case is the preferred option for URLs as they avoid potential issues with file system case sensitivity and maintain coherence with the domain name. I'd be reluctant to make such a massive change without a rock-solid reason!

I would however be in favour of flexibility. If someone would like to override the default snake-case in the reflector configuration, then it makes sense to allow that. This may be a better approach for your PR.

gmlewis commented 1 year ago

I would however be in favour of flexibility. If someone would like to override the default snake-case in the reflector configuration, then it makes sense to allow that. This may be a better approach for your PR.

Thank you for the feedback, @samlown ! I've attempted to do this. PTAL.