Openapi-generator: [BUG] [Elm] elmPrefixCustomTypeVariants

Created on 29 Apr 2019  路  1Comment  路  Source: OpenAPITools/openapi-generator

Bug Report Checklist

  • [x] Have you provided a full/minimal spec to reproduce the issue?
  • [ ] Have you validated the input using an OpenAPI validator (example)?
  • [x] What's the version of OpenAPI Generator used?
  • [ ] Have you search for related issues/PRs?
  • [x] What's the actual output vs expected output?
  • [ ] [Optional] Bounty to sponsor the fix (example)
Description
    "Answers": {
      "type": "object",
      "required": [
        "houseLiving",
        "liabilityLegalProtection",
        "pets"
      ],
      "properties": {
        "houseLiving": {
          "type": "string",
          "enum": [
            "RENTED",
            "OWN_HOUSE",
            "OWN_FLAT",
            "PARENTS_HOUSE",
            "SHARED_FLAT",
            "RENT_FREE"
          ]
        },
        "liabilityLegalProtection": {
          "type": "array",
          "items": { "type": "string", "enum": ["BUILDER", "LANDLORD"] }
        },
        "pets": {
          "type": "array",
          "items": {
            "type": "string",
            "enum": ["DOG", "CAT", "HORSE", "AQUARIUM"]
          }
        }
      },
      "title": "Answers"
    }
type HouseLiving
    = HouseLivingRENTED
    | HouseLivingOWNHOUSE
    | HouseLivingOWNFLAT
    | HouseLivingPARENTSHOUSE
    | HouseLivingSHAREDFLAT
    | HouseLivingRENTFREE


type LiabilityLegalProtection
    = LiabilityLegalProtectionLiabilityLegalProtectionLiabilityLegalProtectionLiabilityLegalProtectionBUILDER
    | LiabilityLegalProtectionLiabilityLegalProtectionLiabilityLegalProtectionLiabilityLegalProtectionLANDLORD

type Pets
    = PetsPetsPetsPetsDOG
    | PetsPetsPetsPetsCAT
    | PetsPetsPetsPetsHORSE
    | PetsPetsPetsPetsAQUARIUM

The actual output for LiabilityLegalProtection and Pets should only add the prefix a single time.

openapi-generator version

v4.0.0-beta3

Command line used for generation
    docker run --rm \
                -v "$PWD:/local" \
                openapitools/openapi-generator-cli:${OPEN_API_VERSION} generate \
                    -i /local/swagger.json \
                    -o "/local/$SDK_DIR/$generator" \
                    -g "$generator" \
                    --invoker-package "crm" \
                    --additional-properties elmEnableCustomBasePaths=true \
                    --additional-properties elmPrefixCustomTypeVariants=true
Suggest a fix

https://github.com/OpenAPITools/openapi-generator/blob/69ad9a9957fc0dca9dbd792cb9a6a3b6f5bf197c/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ElmClientCodegen.java#L696-L698

A fix would be to check if the prefix is already part of the value. This will work, but will not remove the root cause. It seems that certain cases leed to concatenating the prefix 4 times. In other cases it's working fine.

@eriktim What do you think?

Elm Bug

Most helpful comment

Thanks for reporting this @andys8 !
I something miss some FP here, so I am not particularity proud of my fix...

>All comments

Thanks for reporting this @andys8 !
I something miss some FP here, so I am not particularity proud of my fix...

Was this page helpful?
0 / 5 - 0 ratings