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

How to handle Enums with illegal characters #1769

Open
williamscs opened this issue Jan 24, 2025 · 1 comment
Open

How to handle Enums with illegal characters #1769

williamscs opened this issue Jan 24, 2025 · 1 comment

Comments

@williamscs
Copy link

I'm running into an issue where an OpenAPI spec has a '+' (plus) character in the middle of the text. I noticed in the enum conversion, it looks like the plus sign is handled if it's at the beginning of the string, but I may be misunderstanding. Are there any options or workarounds to handle the enum so that it could be named correctly? Thanks for your help!

Spec in question: https://api.snyk.io/rest/openapi/2024-10-15

Specific JSON:

      "Format": {
        "description": "The desired SBOM format of the response.",
        "in": "query",
        "name": "format",
        "schema": {
          "enum": [
            "cyclonedx1.6+json",
            "cyclonedx1.6+xml",
            "cyclonedx1.5+json",
            "cyclonedx1.5+xml",
            "cyclonedx1.4+json",
            "cyclonedx1.4+xml",
            "spdx2.3+json"
          ],
          "example": "cyclonedx1.6+json",
          "type": "string"
        }
      },

Generated Code which won't build:

    [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "10.0.22.0 (Newtonsoft.Json v11.0.0.0)")]
    public enum Format
    {
        [System.Runtime.Serialization.EnumMember(Value = @"cyclonedx1.6+json")]
        Cyclonedx1_6+json = 0,
    
        [System.Runtime.Serialization.EnumMember(Value = @"cyclonedx1.6+xml")]
        Cyclonedx1_6+xml = 1,
    
        [System.Runtime.Serialization.EnumMember(Value = @"cyclonedx1.5+json")]
        Cyclonedx1_5+json = 2,
    
        [System.Runtime.Serialization.EnumMember(Value = @"cyclonedx1.5+xml")]
        Cyclonedx1_5+xml = 3,
    
        [System.Runtime.Serialization.EnumMember(Value = @"cyclonedx1.4+json")]
        Cyclonedx1_4+json = 4,
    
        [System.Runtime.Serialization.EnumMember(Value = @"cyclonedx1.4+xml")]
        Cyclonedx1_4+xml = 5,
    
        [System.Runtime.Serialization.EnumMember(Value = @"spdx2.3+json")]
        Spdx2_3+json = 6,
    
    }
@williamscs
Copy link
Author

I looked through the history of the file, and it looks like there was conversion for + characters, but it was removed in a refactor. I don't speak regex fluently (🙃) so I'm not certain what the regex is doing now.

bf3ee3a

Happy to help, but unsure where the best spot for tests would be.

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

1 participant