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
  • Issues
  • #793
Closed
Open
Issue created Aug 12, 2018 by Administrator@rootContributor

[OAS 3.0.0] Variables in "servers" object

Created by: 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"
        }
      ]
    } ],
Assignee
Assign to
Time tracking