[BUG][Elm] Root operation causes StringIndexOutOfBoundsException
Created by: Elewyth
Bug Report Checklist
-
Have you provided a full/minimal spec to reproduce the issue? -
Have you validated the input using an OpenAPI validator (example)? -
What's the version of OpenAPI Generator used? -
Have you search for related issues/PRs? -
What's the actual output vs expected output? -
[Optional] Bounty to sponsor the fix (example)
Description
Generating client code for Elm (0.19) from an openapi.yaml specification with a root operation /
causes a StringIndexOutOfBoundsException:
Exception in thread "main" java.lang.RuntimeException: Could not generate api file for 'Default'
at org.openapitools.codegen.DefaultGenerator.generateApis(DefaultGenerator.java:666)
at org.openapitools.codegen.DefaultGenerator.generate(DefaultGenerator.java:922)
at org.openapitools.codegen.cmd.Generate.run(Generate.java:396)
at org.openapitools.codegen.OpenAPIGenerator.main(OpenAPIGenerator.java:60)
Caused by: java.lang.StringIndexOutOfBoundsException: String index out of range: 0
at java.base/java.lang.StringLatin1.charAt(StringLatin1.java:47)
at java.base/java.lang.String.charAt(String.java:693)
at org.openapitools.codegen.languages.ElmClientCodegen.lambda$postProcessOperationsWithModels$3(ElmClientCodegen.java:449)
at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:195)
at java.base/java.util.Spliterators$ArraySpliterator.forEachRemaining(Spliterators.java:948)
at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484)
at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)
at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:913)
at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:578)
at org.openapitools.codegen.languages.ElmClientCodegen.postProcessOperationsWithModels(ElmClientCodegen.java:449)
at org.openapitools.codegen.DefaultGenerator.processOperations(DefaultGenerator.java:1175)
at org.openapitools.codegen.DefaultGenerator.generateApis(DefaultGenerator.java:552)
... 3 more
openapi-generator version
@openapitools/openapi-generator-cli@0.0.14-4.0.2 (installed via NPM)
OpenAPI declaration file content or url
openapi: 3.0.0
info:
title: Elm Root Bug
version: 1.0.0
paths:
/:
get:
summary: Root endpoint that causes generator bug
responses:
204:
description: No response body
Command line used for generation
npx openapi-generator generate -i bug.yaml -g elm -o output
Steps to reproduce
- Save sample spec as
bug.yaml
npm install -g openapi-generator-cli
npx openapi-generator generate -i bug.yaml -g elm -o output
Related issues/PRs
I could not find a related issue, as this seems to be a bug specific to the Elm generator implementation.
Suggest a fix
ElmClientCodegen.java:449 contains a lambda with str.charAt(0)
which fails on operations with a path of /
. This should probably have a fallback on something like "root"
or even an empty string. The Haskell generator produces an empty string and an operation named "rootGet"
.