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

[elm] failed to generate map from object with additionalProperties #1140

Closed
mxinden opened this issue Sep 28, 2018 · 6 comments
Closed

[elm] failed to generate map from object with additionalProperties #1140

mxinden opened this issue Sep 28, 2018 · 6 comments

Comments

@mxinden
Copy link
Contributor

mxinden commented Sep 28, 2018

Description

I am trying to generate an elm client based on an OpenAPI spec (see below). The spec contains a map (labelSet) represented as an object with the additionalProperties field and no properties field like described in the swagger docs.

Generating the client with the command mentioned below generates an invalid LabelSet.elm file.

openapi-generator version
$ docker run openapitools/openapi-generator-cli:latest version

3.3.0-SNAPSHOT

Image ID: acde33bd7281

OpenAPI declaration file content or url
---

swagger: '2.0'

info:
  version: 0.0.1
  title: Alertmanager API
  description: API of the Prometheus Alertmanager (https://github.com/prometheus/alertmanager)
  license:
    name: Apache 2.0
    url: http://www.apache.org/licenses/LICENSE-2.0.html

consumes:
  - "application/json"
produces:
  - "application/json"

paths:
  /alerts:
    get:
      operationId: xxx
      description: xxx
      parameters:
      responses:
        '200':
          description: xxx
          schema:
            type: array
            items:
              '$ref': '#/definitions/alert'
definitions:
  alert:
    type: object
    properties:
      labels:
        $ref: '#/definitions/labelSet'
  labelSet:
    type: object
    additionalProperties:
      type: string
Invalid output file

LabelSet.elm:

{-
   Alertmanager API
   API of the Prometheus Alertmanager (https://github.com/prometheus/alertmanager)

   OpenAPI spec version: 0.0.1

   NOTE: This file is auto generated by the openapi-generator.
   https://github.com/openapitools/openapi-generator.git
   Do not edit this file manually.
-}


module Data.LabelSet exposing (LabelSet, labelSetDecoder, labelSetEncoder)

import Json.Decode as Decode exposing (Decoder)
import Json.Decode.Pipeline exposing (optional, required)
import Json.Encode as Encode
import Maybe exposing (map, withDefault)


type alias LabelSet =
    {     }


labelSetDecoder : Decoder LabelSet
labelSetDecoder =
    Decode.succeed LabelSet



labelSetEncoder : LabelSet -> Encode.Value
labelSetEncoder model =
    Encode.object
        ]
Command line used for generation
docker run --user=1000:1000 --rm -v /home/mxinden/go/src/github.com/prometheus/alertmanager/ui/app/../..:/local openapitools/openapi-generator-cli:latest generate \                                                                                                             
        -i /local/api/v2/openapi.yaml\
        -g elm \
        --version \
        -o /local/ui/app/./openapi-STca4PUI5T
Steps to reproduce

Running elm format on the above LabelSet.elm file results in:

-- SYNTAX PROBLEM ---------------------------------------- src/Data/LabelSet.elm

I ran into something unexpected when parsing your code!

34elm-format: <stderr>: hPutChar: invalid argument (invalid character)
make: *** [Makefile:24: format] Error 1
@wing328
Copy link
Member

wing328 commented Sep 29, 2018

@mxinden thanks for reporting the issue.

cc @trenneman

@eriktim
Copy link
Contributor

eriktim commented Sep 29, 2018

@mxinden Thanks for reporting. additionalProperties has not been supported so far. This will hopefully be resolved in #1144.

@wing328 wing328 modified the milestones: 3.3.0, 3.3.1 Oct 1, 2018
@wing328 wing328 modified the milestones: 3.3.1, 3.3.2 Oct 15, 2018
eriktim added a commit to eriktim/openapi-generator that referenced this issue Oct 22, 2018
wing328 pushed a commit that referenced this issue Oct 23, 2018
@mxinden
Copy link
Contributor Author

mxinden commented Oct 24, 2018

Thanks for the work on this @trenneman @wing328!

I have tested out the latest docker image and current master (196f122).

The generated file now properly imports Dict, but still produces an invalid elm file:

{-
   Alertmanager API
   API of the Prometheus Alertmanager (https://github.com/prometheus/alertmanager)

   OpenAPI spec version: 0.0.1

   NOTE: This file is auto generated by the openapi-generator.
   https://github.com/openapitools/openapi-generator.git
   Do not edit this file manually.
-}


module Data.LabelSet exposing (LabelSet, decoder, encoder)

import Dict exposing (Dict)
import Json.Decode as Decode exposing (Decoder)
import Json.Decode.Pipeline exposing (optional, required)
import Json.Encode as Encode


type alias LabelSet =
    {     }


decoder : Decoder LabelSet
decoder =
    Decode.succeed LabelSet



encoder : LabelSet -> Encode.Value
encoder model =
    Encode.object

        ]

Am I running off of the wrong version?

@eriktim
Copy link
Contributor

eriktim commented Oct 24, 2018

@mxinden I should have mentioned the PR raised issue #1296. After that (non-Elm specific) PR the Data.LabelSet module won't be generated anymore. Already, if you do not use that module you should be fine.

@wing328
Copy link
Member

wing328 commented Oct 25, 2018

@mxinden you can use .openapi-generator-ignore to skip LabelSet file from being generated for the time being or you can revise the definition like the following to workaround the issue:

definitions:
  alert:
    type: object
    properties:
      labels:
        type: object
        additionalProperties:
          type: string

@mxinden
Copy link
Contributor Author

mxinden commented Oct 26, 2018

@trenneman @wing328 ah, sorry, I have overlooked the inline Dict String String definition in the parent file. Everything working fine.

I am simply deleting LabelSet.elm for now. Thanks for the pointers and the repeated help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants