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

[Codegen] Spec not adhered to wrt. relative Server URLs #9215

Open
cristianpetrache opened this issue Feb 27, 2019 · 0 comments
Open

[Codegen] Spec not adhered to wrt. relative Server URLs #9215

cristianpetrache opened this issue Feb 27, 2019 · 0 comments

Comments

@cristianpetrache
Copy link

cristianpetrache commented Feb 27, 2019

Description

Using a relative server url in the swagger file produces a java.net.MalformedURLException: no protocol

Swagger-codegen version

io.swagger.codegen.v3:swagger-codegen-maven-plugin:3.0.5
io.swagger.codegen.v3:swagger-codegen:3.0.5

Swagger declaration file content or url
openapi: "3.0.0"
info:
  version: 1.0.0
  title: 'Some title'
  description: Some description
  termsOfService: 'http://www.terms.com'
  contact:
    email: contact@email.com
  license:
    name: The License
    url: 'http://www.license.com'
servers:
  - url: '/api/v1'
paths:
..........

-->

Command line used for generation

mvn clean package

Steps to reproduce
  1. add an openapi swagger file with a relative path url
  2. use the io.swagger.codegen.v3:swagger-codegen-maven-plugin:3.0.5 plugin
  3. run mvn clean package

The output is:

[WARNING] Not valid URL: /api/v1
java.net.MalformedURLException: no protocol: /api/v1
	at java.net.URL.<init>(URL.java:606)
	at java.net.URL.<init>(URL.java:498)
	at java.net.URL.<init>(URL.java:447)
	at io.swagger.codegen.v3.utils.URLPathUtil.getServerURL(URLPathUtil.java:31)
	at io.swagger.codegen.v3.utils.URLPathUtil.getScheme(URLPathUtil.java:77)
	at io.swagger.codegen.v3.DefaultGenerator.buildSupportFileBundle(DefaultGenerator.java:673)
	at io.swagger.codegen.v3.DefaultGenerator.generate(DefaultGenerator.java:725)
	at io.swagger.codegen.v3.maven.plugin.CodeGenMojo.execute(CodeGenMojo.java:545)
	at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:207)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
	at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
	at org.apache.maven.lifecycle.internal.builder.multithreaded.MultiThreadedBuilder$1.call(MultiThreadedBuilder.java:185)
	at org.apache.maven.lifecycle.internal.builder.multithreaded.MultiThreadedBuilder$1.call(MultiThreadedBuilder.java:181)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:836)
Related issues/PRs

#7960

Suggest a fix/enhancement

#7960 fixed the problem in io.swagger.codegen.v3.DefaultGenerator#configureGeneratorProperties (line 202) and in io.swagger.codegen.v3.DefaultGenerator#buildSupportFileBundle (line 664). Now the same issue appears because of the code in io.swagger.codegen.v3.DefaultGenerator#buildSupportFileBundle (line 673), as io.swagger.codegen.v3.utils.URLPathUtil#getScheme calls the io.swagger.codegen.v3.utils.URLPathUtil#getServerURL(io.swagger.v3.oas.models.OpenAPI), instead of io.swagger.codegen.v3.utils.URLPathUtil#getServerURL(io.swagger.v3.oas.models.OpenAPI, io.swagger.codegen.v3.CodegenConfig).

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

1 participant