Skip to content

[OAS 3.0.0] Variables in "servers" object  #793

@TiFu

Description

@TiFu
Description

The generator currently produces the following output for -DdebugSupportingFiles:

"servers" : [ {
      "url" : "http://petstore.swagger.io:{port}/{basePath}",
      "description" : "The production API server",
      "variables" : {
        "port" : {
          "default" : "8443",
          "enum" : [ "8443", "443" ]
        },
        "basePath" : {
          "default" : "v2"
        }
      }
    } ],

for the following input:

openapi: 3.0.0
servers:
  - url: 'http://petstore.swagger.io:{port}/{basePath}'
    description: The production API server
    variables:
      port:
        enum:
          - '8443'
          - '443'
        default: '8443'
      basePath:
        default: v2

(full spec

AFAIK mustache does not allow iterating objects (Correct me if I'm wrong - I tried a lot of different combinations and couldn't get it to work).
This is problematic because the entries of variables are user defined, so they can't be referenced in the template by hardcoding variable names.

Problem Example:
I wanted to write a template which generates a class for each server with one setter per variable e.g. setBasePath(path: string) and setPort(port: 8443 | 443)

openapi-generator version: 3.0.0
Command line used for generation

-DdebugSupportingFiles with any language.

Suggest a fix/enhancement

Change the variables object to an array of objects, each containing a name property.

"servers" : [ {
      "url" : "http://petstore.swagger.io:{port}/{basePath}",
      "description" : "The production API server",
      "variables" : [
              {
               "name": "port",
               "default" : "8443",
               "enum" : [ "8443", "443" ]
        },
        {    
             "name": "basePath",
             "default" : "v2"
        }
      ]
    } ],

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions