swagger-api / swagger-api/swagger-codegen
NullPointerException Thrown when Both `properties` and `allOf` are Defined in a `schema` Object
Open
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
Not sure if it's my spec's issue but a null pointer exception was thrown.
Swagger-codegen version
Latest code in 3.0.0 branch
Swagger declaration file content or url
openapi: 3.0.1
info:
version: 4.176.0
title: Linode API
servers:
- url: https://api.linode.com/v4
paths:
/networking/firewalls/{firewallId}/rules:
parameters:
- name: firewallId
in: path
required: true
schema:
type: integer
put:
tags:
- Networking
summary: Firewall Rules Update
operationId: updateFirewallRules
requestBody:
content:
application/json:
schema:
allOf:
- $ref: '#/components/schemas/Firewall/properties/rules'
type: object
properties:
inbound:
type: array
items:
$ref: '#/components/schemas/FirewallRuleConfig'
outbound:
type: array
items:
$ref: '#/components/schemas/FirewallRuleConfig'
responses:
'200':
description: Firewall Rules updated successfully.
content:
application/json:
schema:
$ref: '#/components/schemas/Firewall/properties/rules'
components:
schemas:
Firewall:
type: object
properties:
id:
type: integer
readOnly: true
rules:
type: object
properties:
inbound:
type: array
items:
$ref: '#/components/schemas/FirewallRuleConfig'
outbound:
type: array
items:
$ref: '#/components/schemas/FirewallRuleConfig'
FirewallRuleConfig:
type: object
properties:
protocol:
type: string
Command line used for generation
java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate -i ./openapi.yaml -l go -o ./swagger-client-go
Exception in thread "Thread-0" java.lang.RuntimeException: Could not process operation:
Tag: class Tag {
name: Networking
description: null
externalDocs: null
}
Operation: updateFirewallRules
Resource: put /networking/firewalls/{firewallId}/rules
Exception: Cannot invoke "io.swagger.v3.oas.models.media.Schema.getProperties()" because "fileTypeSchema" is null
at io.swagger.codegen.v3.DefaultGenerator.processOperation(DefaultGenerator.java:989)
at io.swagger.codegen.v3.DefaultGenerator.processPaths(DefaultGenerator.java:891)
at io.swagger.codegen.v3.DefaultGenerator.generateApis(DefaultGenerator.java:484)
at io.swagger.codegen.v3.DefaultGenerator.generate(DefaultGenerator.java:796)
at io.swagger.codegen.v3.cli.cmd.Generate.run(Generate.java:388)
at java.base/java.lang.Thread.run(Thread.java:840)
Caused by: java.lang.NullPointerException: Cannot invoke "io.swagger.v3.oas.models.media.Schema.getProperties()" because "fileTypeSchema" is null
at io.swagger.codegen.v3.generators.DefaultCodegenConfig.isFileTypeSchema(DefaultCodegenConfig.java:4443)
at io.swagger.codegen.v3.generators.DefaultCodegenConfig.fromResponse(DefaultCodegenConfig.java:2349)
at io.swagger.codegen.v3.generators.DefaultCodegenConfig.fromOperation(DefaultCodegenConfig.java:2042)
at io.swagger.codegen.v3.generators.go.GoClientCodegen.fromOperation(GoClientCodegen.java:118)
at io.swagger.codegen.v3.DefaultGenerator.processOperation(DefaultGenerator.java:965)
... 5 more
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the supplied OpenAPI declaration and generation command, then trace DefaultGenerator.processOperation through DefaultCodegenConfig.fromResponse and isFileTypeSchema, with GoClientCodegen.fromOperation as the caller shown in the stack trace. Done means the reported schema no longer produces a NullPointerException during generation; the payload does not name a test file.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go, java, openapi
- Domain
- backend-api-design, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100