convertSwagger2markup fails with NPE with swagger files with schema json objects
convertSwagger2markup fails with NPE.
This happens because if input swagger file has json objects schema like this one
"schema" : {
"$ref" : "#/definitions/APIResult"
}
When removing all schema json nodes from input swagger file, the generation finishes without error.
pom.xml
<swagger2markup.version>1.2.0</swagger2markup.version>
Stacktrace
Failed to execute goal 'convertSwagger2markup'
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:212)
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.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:863)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:288)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:199)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: org.apache.maven.plugin.MojoFailureException: Failed to execute goal 'convertSwagger2markup'
at io.github.swagger2markup.Swagger2MarkupMojo.execute(Swagger2MarkupMojo.java:74)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:207)
... 20 more
Caused by: java.lang.NullPointerException
at io.github.swagger2markup.internal.adapter.PropertyAdapter.getType(PropertyAdapter.java:116)
at io.github.swagger2markup.internal.adapter.PropertyAdapter.getType(PropertyAdapter.java:123)
at io.github.swagger2markup.internal.component.ResponseComponent.lambda$apply$1(ResponseComponent.java:106)
at java.util.TreeMap.forEach(TreeMap.java:1001)
at io.github.swagger2markup.internal.component.ResponseComponent.apply(ResponseComponent.java:82)
at io.github.swagger2markup.internal.component.PathOperationComponent.buildResponsesSection(PathOperationComponent.java:227)
at io.github.swagger2markup.internal.component.PathOperationComponent.apply(PathOperationComponent.java:106)
at io.github.swagger2markup.internal.document.PathsDocument.applyPathOperationComponent(PathsDocument.java:223)
at io.github.swagger2markup.internal.document.PathsDocument.buildOperation(PathsDocument.java:207)
at io.github.swagger2markup.internal.document.PathsDocument.lambda$null$1(PathsDocument.java:133)
at java.lang.Iterable.forEach(Iterable.java:75)
at io.github.swagger2markup.internal.document.PathsDocument.lambda$buildsPathsSection$2(PathsDocument.java:133)
at java.util.TreeMap.forEach(TreeMap.java:1001)
at io.github.swagger2markup.internal.document.PathsDocument.buildsPathsSection(PathsDocument.java:127)
at io.github.swagger2markup.internal.document.PathsDocument.apply(PathsDocument.java:103)
at io.github.swagger2markup.Swagger2MarkupConverter.applyPathsDocument(Swagger2MarkupConverter.java:197)
at io.github.swagger2markup.Swagger2MarkupConverter.toFolder(Swagger2MarkupConverter.java:182)
at io.github.swagger2markup.Swagger2MarkupMojo.execute(Swagger2MarkupMojo.java:69)
... 22 more
Maybe a duplicate of https://github.com/Swagger2Markup/swagger2markup/issues/213
Hi, could you please provide a minimal Swagger Spec to reproduce this issue? Btw if you use and like Swagger2markup, we would love to get your GitHub Star.
Hi, here you go. Thanx.
{
"swagger" : "2.0",
"info" : {
"description" : "description",
"version" : "v1",
"title" : "title",
"contact" : {
"name" : "contact",
"url" : "foo.tld",
"email" : "[email protected]"
}
},
"host" : "localhost:8000",
"basePath" : "/",
"tags" : [ {
"name" : "stuff",
"description" : "workers Operations"
}, {
"name" : "things",
"description" : "things Operations"
}, {
"name" : "choices",
"description" : "choices Operations"
} ],
"schemes" : [ "http", "https" ],
"paths" : {
"/stuff" : {
"get" : {
"tags" : [ "stuff" ],
"summary" : "Lists a page for Stuff stored in the Database",
"description" : "",
"operationId" : "listBotnets",
"consumes" : [ "application/json" ],
"produces" : [ "application/json" ],
"parameters" : [ {
"name" : "page",
"in" : "query",
"description" : "page",
"required" : false,
"type" : "integer",
"default" : 1,
"format" : "int32"
} ],
"responses" : {
"200" : {
"description" : "Lists a page for Stuff stored in the Database",
"schema" : {
"type" : "array",
"items" : {
"$ref" : "#/definitions/workersData"
}
},
"headers" : {
"Link" : {
"type" : "array",
"description" : "Links for pagination (RFC5899)",
"items" : {
"$ref" : "#/definitions/Link"
}
}
}
}
}
},
"post" : {
"tags" : [ "stuff" ],
"summary" : "Creates a new workers entry and returning it's ID",
"description" : "",
"operationId" : "createworkers",
"consumes" : [ "application/json" ],
"produces" : [ "application/json" ],
"parameters" : [ {
"in" : "body",
"name" : "workers",
"description" : "workers Data for creation",
"required" : true,
"schema" : {
"$ref" : "#/definitions/workersData"
}
} ],
"responses" : {
"303" : {
"description" : "Redirects to created workers URL"
},
"400" : {
"description" : "Invalid data"
},
"500" : {
"description" : "If an internal error happens"
}
}
}
}
},
"definitions" : {
"workersData" : {
"type" : "object",
"properties" : {
"links" : {
"type" : "array",
"xml" : {
"name" : "_links"
},
"items" : {
"$ref" : "#/definitions/Link"
}
},
"id" : {
"type" : "string",
"format" : "uuid"
},
"name" : {
"type" : "string"
},
"variantId" : {
"type" : "string",
"format" : "uuid"
},
"active" : {
"type" : "boolean",
"default" : false
},
"description" : {
"type" : "string"
}
}
},
"UriBuilder" : {
"type" : "object"
},
"Link" : {
"type" : "object",
"properties" : {
"params" : {
"type" : "object",
"additionalProperties" : {
"type" : "string"
}
},
"title" : {
"type" : "string"
},
"uriBuilder" : {
"$ref" : "#/definitions/UriBuilder"
},
"uri" : {
"type" : "string",
"format" : "uri"
},
"rel" : {
"type" : "string"
},
"rels" : {
"type" : "array",
"items" : {
"type" : "string"
}
},
"type" : {
"type" : "string"
}
}
}
}
}
The definitions section is missing. Is this by mistake?
Yes. sorry. I made that mistake by creating the minimal version. I'll try to do it again. Thanx.
You can edit the existing comment.
Debugging it further, i see that this happens while processing response headers
https://github.com/Swagger2Markup/swagger2markup/blob/v1.2.0/src/main/java/io/github/swagger2markup/internal/component/ResponseComponent.java#L106
-->
https://github.com/Swagger2Markup/swagger2markup/blob/v1.2.0/src/main/java/io/github/swagger2markup/internal/adapter/PropertyAdapter.java#L123
definitionDocumentResolver == null ?
It works if we remove the $ from ref
"$ref" : "#/definitions/Link"
Thanx