Skip to content

[elm] Process additionalProperties in parent alias when using composition (allOf) #1465

@mxinden

Description

@mxinden
Description

This is a follow up to #1140 and #1262.

When I use the allOf keyword to compose GettableAlert based on Alert, the Annotation is not defined as a Dict String String but as a LabelSet. But as discussed in #1140 LabelSet is not properly generated.

openapi-generator version

3.3.4-SNAPSHOT

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)

paths:
  /alert:
    get:
      operationId: getAlert
      description: Get an alert
      parameters:
      responses:
        '200':
          description: Get alerts response
          schema:
              '$ref': '#/definitions/alert'
definitions:
  alert:
    type: object
    properties:
      labels:
        $ref: '#/definitions/labelSet'
    required:
      - labels
  gettableAlert:
    allOf:
      - type: object
        properties:
          annotations:
            $ref: '#/definitions/labelSet'
        required:
          - annotations
      - $ref: '#/definitions/alert'
  labelSet:
    type: object
    additionalProperties:
      type: string
Command line used for generation

docker run --user=$(id -u ${USER}):$(id -g ${USER}) --rm -v ${PWD}:/local openapitools/openapi-generator-cli:latest generate -i /local/openapi.yaml -g elm -o /local/example

Steps to reproduce

Run above docker command with the above written OpenAPI specification. This results in:

{-
   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.GettableAlert exposing (GettableAlert, decoder, encoder)

import Data.LabelSet as LabelSet exposing (LabelSet)
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 GettableAlert =
    { labels : Dict String String
    -- I would expect `Dict String Strng` here as well.
    , annotations : LabelSet
    }


decoder : Decoder GettableAlert
decoder =
    Decode.succeed GettableAlert
        |> required "labels" (Decode.dict Decode.string)
        |> required "annotations" LabelSet.decoder



encoder : GettableAlert -> Encode.Value
encoder model =
    Encode.object
        [ ( "labels", (Encode.dict identity Encode.string) model.labels )
        , ( "annotations", LabelSet.encoder model.annotations )

        ]
Related issues/PRs

#1140 and #1262

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions