Skip to content

Generated code has duplicate constructors for different enum variants #104

Open
@schoettl

Description

@schoettl

Hi there, thanks for this great code gen! I'd just like to hear some opinions how to best fix this issue:

In the Xentral ERP OpenAPI spec they use this inline declaration of a "Loose boolean type".

"/api/products": {
 "requestBody": {
   "content": {
     "schema": {
       "properties": {
                
                  "allowPurchaseFromAllSuppliers": {
                    "description": "Loose boolean type which accepts boolean, number 0 or 1 and string 'true' or 'false'",
                    "example": "'true'",
                    "oneOf": [
                      {
                        "type": "boolean"
                      },
                      {
                        "type": "number",
                        "enum": [
                          0,
                          1
                        ]
                      },
                      {
                        "type": "string",
                        "enum": [
                          "true",
                          "false",
                          "True",
                          "False",
                          "TRUE",
                          "FALSE"
                        ]
                      }
                    ]
                  },

which translates to

data ExternalReference'createRequestBodyIsActive'OneOf3 =
   ExternalReference'createRequestBodyIsActive'OneOf3Other Data.Aeson.Types.Internal.Value -- ^ This case is used if the value encountered during decoding does not match any of the provided cases in the specification.
  | ExternalReference'createRequestBodyIsActive'OneOf3Typed Data.Text.Internal.Text -- ^ This constructor can be used to send values to the server which are not present in the specification yet.
  | ExternalReference'createRequestBodyIsActive'OneOf3EnumTrue -- ^ Represents the JSON value @"true"@
  | ExternalReference'createRequestBodyIsActive'OneOf3EnumFalse -- ^ Represents the JSON value @"false"@
  | ExternalReference'createRequestBodyIsActive'OneOf3EnumTrue -- ^ Represents the JSON value @"True"@
  | ExternalReference'createRequestBodyIsActive'OneOf3EnumFalse -- ^ Represents the JSON value @"False"@
  | ExternalReference'createRequestBodyIsActive'OneOf3EnumTRUE -- ^ Represents the JSON value @"TRUE"@
  | ExternalReference'createRequestBodyIsActive'OneOf3EnumFALSE -- ^ Represents the JSON value @"FALSE"@

where we have duplicate names in the type constructors.

I think it boils down to issue #85.

But in this case the enum is defined inline, not DRY in a scheme. So I'd need to patch dozens of generated files.

I didn't find an command line option to fix it.

As the request body is made by me and I will use Bool instead of some strings it should be save to delete the enum from the oneOf section. Maybe this can be done with jq. Or I just use sed but that might remove some occasions where it shouldn't.

Are there better ideas?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions