swagger-api / swagger-api/swagger-codegen
[PYTHON] variable substitution not occurring during template generation OpenAPI spec 3.0
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the issue with the provided OpenAPI YAML and the swagger-codegen-cli-3.0.21 command, then inspect the generated configuration.py where the unresolved host is assigned. Compare the requested behavior with the referenced OpenAPI generator implementation. Done means default server variables are substituted in the generated Python client so the host is usable.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- openapi, python
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100