Skip to content

[PYTHON] variable substitution not occurring during template generation OpenAPI spec 3.0 #10480

@jazzapple

Description

@jazzapple
Description

I'm using server templating in my swagger.yaml and swagger-codegen-cli-3.0.21 JAR file to generate a Python SDK. In the generated configuration.py file, the host is populated as a string with the placeholders rather than being substituted. This consequently returns "name or service unknown" error when the client tries to connect to the host

Swagger-codegen version

swagger-codegen-cli-3.0.21

Swagger declaration file content or url
openapi: 3.0.0
info:
  title: my model
  version: '1.0'
servers:
- url: '{protocol}://{server}/{basePath}'
  variables:
    protocol:
      enum:
      - http
      - https
      default: http
    server:
      enum:
      - localhost:1234
      - prod_server
      default: localhost:1234
    basePath:
      default: v1/mymodel
Command line used for generation

java -jar swagger-codegen-cli-3.0.21 generate -i myclient/swagger.yaml -o myclient/ -l python

Steps to reproduce

run command line above, returns configuration.py with:

self.host = "{protocol}://{server}/{basePath}"
Related issues/PRs
Suggest a fix/enhancement

have codegen perform variable substitution on the default values and populate host accordingly in configuration.py. Similar functionality has been implemented in OpenAPI generator which handles both multiple servers and variable substitution

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions