Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Java] Issue with evaluating server URL (3.0.0-rc1) #8412

Closed
douglasbgray opened this issue Jul 11, 2018 · 8 comments
Closed

[Java] Issue with evaluating server URL (3.0.0-rc1) #8412

douglasbgray opened this issue Jul 11, 2018 · 8 comments
Assignees

Comments

@douglasbgray
Copy link

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.

@haitongz
Copy link

can anyone give some suggestion for this issue

@b5l
Copy link

b5l commented Oct 16, 2020

Bump, I am experiencing exactly the same issue using version 3.0.22:

Server configuration:

{
  "url": "http://{instance}:{port}/api/ext/{version}",
  "variables": {
    "instance": {
      "default": "localhost"
    },
    "port": {
      "enum": [
        "80",
        "443",
        "1356"
      ],
      "default": "1356"
    },
    "version": {
      "default": "1.0"
    }
  }
}

Output of java -jar swagger-codegen-cli-3.0.22.jar generate -i /tmp/swagger/api.json -l html:

13:41:38.914 [Thread-0] WARN  i.s.codegen.v3.utils.URLPathUtil - Not valid URL: http://{instance}:{port}/api/ext/{version}
java.net.MalformedURLException: Error at index 0 in: "{port}"
	at java.base/java.net.URL.<init>(URL.java:679)
	at java.base/java.net.URL.<init>(URL.java:541)
	at java.base/java.net.URL.<init>(URL.java:488)
	at io.swagger.codegen.v3.utils.URLPathUtil.getServerURL(URLPathUtil.java:70)
	at io.swagger.codegen.v3.DefaultGenerator.configureGeneratorProperties(DefaultGenerator.java:228)
	at io.swagger.codegen.v3.DefaultGenerator.generate(DefaultGenerator.java:773)
	at io.swagger.codegen.v3.cli.cmd.Generate.run(Generate.java:378)
	at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: java.lang.NumberFormatException: Error at index 0 in: "{port}"
	at java.base/java.lang.NumberFormatException.forCharSequence(NumberFormatException.java:81)
	at java.base/java.lang.Integer.parseInt(Integer.java:735)
	at java.base/java.net.URLStreamHandler.parseURL(URLStreamHandler.java:223)
	at java.base/java.net.URL.<init>(URL.java:674)
	... 7 common frames omitted
13:41:39.040 [Thread-0] WARN  i.s.codegen.v3.utils.URLPathUtil - Not valid URL: http://{instance}:{port}/api/ext/{version}
java.net.MalformedURLException: Error at index 0 in: "{port}"
	at java.base/java.net.URL.<init>(URL.java:679)
	at java.base/java.net.URL.<init>(URL.java:541)
	at java.base/java.net.URL.<init>(URL.java:488)
	at io.swagger.codegen.v3.utils.URLPathUtil.getServerURL(URLPathUtil.java:70)
	at io.swagger.codegen.v3.DefaultGenerator.buildSupportFileBundle(DefaultGenerator.java:723)
	at io.swagger.codegen.v3.DefaultGenerator.generate(DefaultGenerator.java:785)
	at io.swagger.codegen.v3.cli.cmd.Generate.run(Generate.java:378)
	at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: java.lang.NumberFormatException: Error at index 0 in: "{port}"
	at java.base/java.lang.NumberFormatException.forCharSequence(NumberFormatException.java:81)
	at java.base/java.lang.Integer.parseInt(Integer.java:735)
	at java.base/java.net.URLStreamHandler.parseURL(URLStreamHandler.java:223)
	at java.base/java.net.URL.<init>(URL.java:674)
	... 7 common frames omitted
13:41:39.040 [Thread-0] WARN  i.s.codegen.v3.utils.URLPathUtil - Not valid URL: http://{instance}:{port}/api/ext/{version}
java.net.MalformedURLException: Error at index 0 in: "{port}"
	at java.base/java.net.URL.<init>(URL.java:679)
	at java.base/java.net.URL.<init>(URL.java:541)
	at java.base/java.net.URL.<init>(URL.java:488)
	at io.swagger.codegen.v3.utils.URLPathUtil.getServerURL(URLPathUtil.java:33)
	at io.swagger.codegen.v3.utils.URLPathUtil.getScheme(URLPathUtil.java:79)
	at io.swagger.codegen.v3.DefaultGenerator.buildSupportFileBundle(DefaultGenerator.java:732)
	at io.swagger.codegen.v3.DefaultGenerator.generate(DefaultGenerator.java:785)
	at io.swagger.codegen.v3.cli.cmd.Generate.run(Generate.java:378)
	at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: java.lang.NumberFormatException: Error at index 0 in: "{port}"
	at java.base/java.lang.NumberFormatException.forCharSequence(NumberFormatException.java:81)
	at java.base/java.lang.Integer.parseInt(Integer.java:735)
	at java.base/java.net.URLStreamHandler.parseURL(URLStreamHandler.java:223)
	at java.base/java.net.URL.<init>(URL.java:674)
	... 8 common frames omitted
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.github.jknack.handlebars.context.MemberValueResolver (file:/tmp/swagger/swagger-codegen-cli-3.0.22.jar) to method java.util.Collections$EmptyMap.isEmpty()
WARNING: Please consider reporting this to the maintainers of com.github.jknack.handlebars.context.MemberValueResolver
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
13:41:39.243 [Thread-0] INFO  i.s.codegen.v3.AbstractGenerator - writing file /tmp/swagger/./index.html
13:41:39.247 [Thread-0] INFO  i.s.codegen.v3.AbstractGenerator - writing file /tmp/swagger/./.swagger-codegen/VERSION

@douglasbgray
Copy link
Author

Saw that someone was looking for a fix, so I created one.

PR - #10565

@jaekim0312
Copy link

@douglasbgray thanks for the fix. This looks good to me. I was wondering you have any plan to merge your changes? Your branch was created a year ago, but not merged yet. I was wondering you have any plan for it. Thanks.

@douglasbgray
Copy link
Author

Hi @jaekim0312 I am not an administrator for this project, so I do not have merge rights. I am not part of the project team, just thought I could help with a solution, since it seemed like my Issue was not being worked on. Only the owners can merge changes and I am not sure they are actively reviewing and merging changes from outside contributors right now.

@dchiang
Copy link

dchiang commented Jan 27, 2022

I am getting the exactly same issue when generating server stubs with python-flask locally using swagger-codegen version 3.0.32

@uri200
Copy link

uri200 commented May 21, 2022

Same here when using this command

swagger-codegen generate -i https://raw.githubusercontent.com/jdegre/5GC_APIs/master/TS29591_Nnef_EventExposure.yaml -l go -o client

It looks like that PR described before fixes that issue. @HugoMario , @frantuma could you please take a look at that PR please #10565

@HugoMario
Copy link
Contributor

fixed by #10565

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants