-
Notifications
You must be signed in to change notification settings - Fork 6k
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]NullPointerException during codegen #12190
Comments
Updated with a YAML to repro. |
I think I have a solution to this problem, but the code change belongs in https://github.com/swagger-api/swagger-codegen-generators I think this yaml helps demonstrate the problem more clearly, because it does not require similarly named responses and schemas: openapi: 3.0.0
info:
title: "reproCase"
version: "0.1"
paths:
/test:
post:
description: test
responses:
'200':
$ref: '#/components/responses/StandardOK'
components:
responses:
StandardOK:
description: OK
content:
applicaton/xml:
schema:
$ref: '#/components/schemas/StandardResponse'
schemas:
StandardResponse:
oneOf:
- $ref: '#/components/schemas/schema1'
- $ref: '#/components/schemas/schemaDoesNotExist'
schema1:
type: string
schema2:
type: string Having something named Using 3.0.46 I was able to reproduce:
3.0.41 had a slightly different error:
With my changes we get a sane error message:
PR incoming |
Thanks for looking into this. "match" and "nomatch" are more common in the Voice Recognition domain I work on. One thing I want to point out: in my example YAML, all schemas exist. It is just referencing the response from "components" in the actual response definition caused the issue. Not sure if your example uncovered a new issue or if it covers the one highlighted by my example as well. |
Unfortunately, you are mixing up responses and schemas in your situation. Just because a response exists with a particular name does not mean that a schema exists with a particular name. When using my updated code, you see the actual error:
The problem is that there is no SCHEMA with the name |
Ok, good. Looks like the fix produces a better error for my case as well. Yes, as I admitted in my original description, referencing a response from "components" in the inline response was a mistake but few things led to that:
The request was to get a better error response which your fix does provide, it appears. |
Handled by swagger-api/swagger-codegen-generators#1274 |
Getting NPE while generating codegen in Java. Stack trace attached below. YAML to repro the issue below.
Swagger-codegen version 3.0.43
"/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java" -jar swagger-codegen-cli.jar generate -i ./restapi_orig.json -l java -o ./gen
Was able to generate a short YAML that repro'ed the issue:
If I change the ref, "#/components/responses/r-match" to "#/components/schemas/match", it works(no NPE). It is probably wrong to refer to a component-ized response within an inline response but I wish it would error out without an NPE. I was originally trying to component-ize the responses but later decided to do the response inline. When I still had the mistaken reference to the component-ized response it threw this exception. But it took a lot of whittling down a long YAML to discover that.
The text was updated successfully, but these errors were encountered: