-
Notifications
You must be signed in to change notification settings - Fork 436
Closed
Description
I have some trouble with a OpenAPI spec containing a oneOf
switch. (from documentation Data Models (Schemas) > oneOf, anyOf, allOf, not)
When I try to generate the java client, I get an error caused by a null pointer Exception (version 1.0.0-SNAPSHOT
).
OpenAPI Spec:
openapi: 3.0.1
info:
title: oneOf test
version: '1.0'
servers:
- url: 'http://localhost:8000/'
paths:
/pets:
patch:
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/Pet'
responses:
'200':
description: Updated
components:
schemas:
Pet:
oneOf:
- $ref: '#/components/schemas/Cat'
- $ref: '#/components/schemas/Dog'
Dog:
type: object
properties:
bark:
type: boolean
breed:
type: string
enum: [Dingo, Husky, Retriever, Shepherd]
Cat:
type: object
properties:
hunts:
type: boolean
age:
type: integer
Stacktrace:
Exception in thread "main" java.lang.RuntimeException: Could not process model 'Pet'.Please make sure that your schema is correct!
at io.swagger.codegen.DefaultGenerator.generateModels(DefaultGenerator.java:361)
at io.swagger.codegen.DefaultGenerator.generate(DefaultGenerator.java:726)
at <my code>
Caused by: java.lang.NullPointerException
at io.swagger.codegen.languages.DefaultCodegenConfig.fromModel(DefaultCodegenConfig.java:1210)
at io.swagger.codegen.languages.java.AbstractJavaCodegen.fromModel(AbstractJavaCodegen.java:845)
at io.swagger.codegen.DefaultGenerator.processModels(DefaultGenerator.java:959)
at io.swagger.codegen.DefaultGenerator.generateModels(DefaultGenerator.java:356)
... 3 more
Note:
When instead of having a Pet
schema in the components, the composed-schema is inlined in the requestBody (as in the example from the docs), then the generator works.
openapi: 3.0.1
info:
title: oneOf test
version: '1.0'
servers:
- url: 'http://localhost:8000/'
paths:
/pets:
patch:
requestBody:
content:
application/json:
schema:
oneOf:
- $ref: '#/components/schemas/Cat'
- $ref: '#/components/schemas/Dog'
responses:
'200':
description: Updated
components:
schemas:
Dog:
type: object
properties:
bark:
type: boolean
breed:
type: string
enum: [Dingo, Husky, Retriever, Shepherd]
Cat:
type: object
properties:
hunts:
type: boolean
age:
type: integer
Metadata
Metadata
Assignees
Labels
No labels