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

Sub-types naming conflicts #695

Open
jandremarais opened this issue Oct 30, 2024 · 1 comment
Open

Sub-types naming conflicts #695

jandremarais opened this issue Oct 30, 2024 · 1 comment

Comments

@jandremarais
Copy link

The following definitions will result in both an Enum and a Struct named AaBb:

"Aa": {
  "properties": {
    "bb": {
      "anyOf": [
        {
          "$ref": "#/definitions/AaBb"
        },
        {
          "type": "string"
        }
      ]
    }
  }
},
"AaBb": {
  "enum": [
    "A",
    "B"
  ],
  "type": "string"
}

We might need an alternative way to name types in types. Maybe AaSubBb or AaBbProp, idk.

@ahl
Copy link
Collaborator

ahl commented Oct 30, 2024

Yeah. Naming is hard. See #1.

What I'd like to do is defer naming until after we've added all items to a "namespace". Then the namespace would be responsible for choosing names. Previously, I was of the opinion that we should try to use context and heuristics to choose good names. I'm increasingly of the opinion that we will want or need a mechanism that allows users to resolve name conflicts. Consider, for example, this schema we get from a GitHub OpenAPI document:

{
  "type": "string",
  "enum": [
    "+1",       
    "-1",       
    "laugh",    
    "confused", 
    "heart",    
    "hooray",   
    "rocket",   
    "eyes"      
  ]
}

How would we produce variant names for -1 and +1? What if the options were -2, -1, 0, +1, +2? Seems like we might want different names in those cases.

My current (background) focus is to have a more complete handling of references to external files and non-$def JSON paths. I believe that this will allow us to include more useful path information throughout. This will be useful for errors, but also to allow manual intervention in these cases. One could imagine an ancillary file to help resolve names, or one could imagine extensions (and first-class JSON patch support to add them). For example:

{
  "type": "string",
  "enum": [
    "+1",       
    "-1",       
    "laugh",    
    "confused", 
    "heart",    
    "hooray",   
    "rocket",   
    "eyes"      
  ],
  "x-code-rename": {
    "+1": "plusOne",
    "-1": "minusOne"
  }
}

In your particular case, I'd love typify to identify the name conflict, produce a meaningful error:

Sorry, but I don't know what to name the type found at #/definitions/Aa/properties/bb such that it doesn't conflict with the type found at #/definitions/AaBb. Could you please help me out? For example, you could make a JSON patch file that looks like this...

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