Description
Description
When running code gen on an openapi 3.x document with a servers
section, if you use a variable for the port, code gen throws an exception. The exception does not block the generation, but does generate a warning in the output. In addition method returns null in this circumstance. I not sure how this impacts downstream processes or the availability of servers
for use in templates.
Error looks like:
java.net.MalformedURLException: For input string: "{port}"
at java.net.URL.<init>(URL.java:627)
at java.net.URL.<init>(URL.java:490)
at java.net.URL.<init>(URL.java:439)
at io.swagger.codegen.utils.URLPathUtil.getServerURL(URLPathUtil.java:30)
at io.swagger.codegen.DefaultGenerator.configureGeneratorProperties(DefaultGenerator.java:211)
...
Swagger-codegen version
3.0.0-rc1
Swagger declaration file content or url
servers:
- url: 'http://localhost:{port}/sample'
description: 'Development server running on localhost'
variables:
port:
default: '8080'
description: port number on which the server is running
Command line used for generation
Using the code generation plugin, so just a simple mvn clean compile
Steps to reproduce
I have created a sample project that shows the error and has steps to reproduce here: https://github.com/douglasbgray/code-gen-server-issue
Related issues/PRs
Did not find any open issues related to this
Suggest a fix/enhancement
Error is coming from URLPathUtil.java
. Before checking if the url can be converted into a java.net.URL
, it needs to perform the variable substitution, which would resolve the {port} and generate a URL that would be valid.