Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Merge requests
  • !14497

[elixir] Properly map AnyType

  • Review changes

  • Download
  • Email patches
  • Plain diff
Merged Administrator requested to merge github/fork/mrmstn/elixir/anytype into master Jan 21, 2023
  • Overview 3
  • Commits 4
  • Pipelines 0
  • Changes 3

Created by: mrmstn

Fixes #14070 (closed)

This PR will handle AnyType as primitives to prevent the generator from generating specific classes, since in elixir structs cannot have any extra undefined files. This will also result in AnyType parameters not be serialized in any other way than Poison interprets it.

Since the Pet Store doesn't have some good examples to see the results of this change, here's a Dummy Spec:

openapi: 3.0.3
info:
  title: Dummy Spec
  version: 1.0.11
servers:
  - url: https://dummy.example.com/api
paths:
  /quotas:
    get:
      operationId: GetQuotas
      responses:
        "200":
          $ref: '#/components/responses/GetQuotasResponse'
      tags:
      - Enterprise
  /dummy:
    get:
      operationId: GetQuotas
      responses:
        "200":
          $ref: '#/components/responses/GetJobScaleStatusResponse'
      tags:
      - Enterprise
components:
  schemas:
    ConsulGateway:
      properties:
        Mesh: {}
      type: object
  responses:
    GetJobScaleStatusResponse:
      description: ""
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ConsulGateway'
    GetQuotasResponse:
      content:
        application/json:
          schema:
            items: {}
            type: array
      description: ""

The Spec contains two interesting parts. First, there is the ConsulGateway with the Mesh properties, with no further definition. Secondly, there is the GetQuotasResponse with an array of AnyType objects.

--- a/lib/nomad_client/api/enterprise.ex
+++ b/lib/nomad_client/api/enterprise.ex
@@ -21,7 +21,7 @@ defmodule NomadClient.Api.Enterprise do
   - `{:ok, [%AnyType{}, ...]}` on success
   - `{:error, Tesla.Env.t}` on failure
   """
-  @spec get_quotas(Tesla.Env.client, keyword()) :: {:ok, list(NomadClient.Model.AnyType.t)} | {:error, Tesla.Env.t}
+  @spec get_quotas(Tesla.Env.client, keyword()) :: {:ok, list(any())} | {:error, Tesla.Env.t}
   def get_quotas(connection, _opts \\ []) do
     request =
       %{}
@@ -32,7 +32,7 @@ defmodule NomadClient.Api.Enterprise do
     connection
     |> Connection.request(request)
     |> evaluate_response([
-      {200, [%NomadClient.Model.AnyType{}]}
+      {200, []}
     ])
   end

As you can see in the upper diff. The generator won't interpret the undefined list as %NomadClient.Model.AnyType{} anymore, but uses [] instead.

--- a/lib/nomad_client/model/consul_gateway.ex
+++ b/lib/nomad_client/model/consul_gateway.ex
@@ -12,15 +12,13 @@ defmodule NomadClient.Model.ConsulGateway do
   ]
 
   @type t :: %__MODULE__{
-    :Mesh => AnyType | nil
+    :Mesh => any() | nil
   }
 end
 
 defimpl Poison.Decoder, for: NomadClient.Model.ConsulGateway do
-  import NomadClient.Deserializer
-  def decode(value, options) do
+  def decode(value, _options) do
     value
-    |> deserialize(:Mesh, :struct, NomadClient.Model.AnyType, options)
   end
 end

In the upper diff, you can see that Mesh will not be decoded to the not existing NomadClient.Model.AnyType anymore. Mesh will not be serialized to a struct and will be left as is from Poison

@halostatue or @wing328 I would be honored if you could review my changes.

PR checklist

  • Read the contribution guidelines.
  • Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
  • Run the following to build the project and update samples:
    ./mvnw clean package 
    ./bin/generate-samples.sh
    ./bin/utils/export_docs_generators.sh
    Commit all changed files. This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master. These must match the expectations made by your contribution. You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example ./bin/generate-samples.sh bin/configs/java*. For Windows users, please run the script in Git BASH.
  • File the PR against the correct branch: master (6.3.0) (minor release - breaking changes with fallbacks), 7.0.x (breaking changes without fallbacks)
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.
Assignee
Assign to
Reviewers
Request review from
Time tracking
Source branch: github/fork/mrmstn/elixir/anytype