-
-
Notifications
You must be signed in to change notification settings - Fork 7.4k
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator (example)?
- Have you tested with the latest master to confirm the issue still exists?
- Have you searched for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
Using oneOf will generate a model with incorrect wrong types.
Actual output:
I have three files of models: ClientIp.java, Request,java, Response.java. Request.java has field private ClientIp clientIp = null; with type ClientIp
Expected output:
I have only two files of models: Request,java, Response.java. Request.java has field private String clientIp; with string type
openapi-generator version
openapi-generator-cli 5.2.1
commit : 8403e59
built : 2021-08-16T12:52:51Z
source : https://github.com/openapitools/openapi-generator
docs : https://openapi-generator.tech/
openapi-generator-cli 5.3.0-SNAPSHOT
commit : de95e2a
built : 2021-09-22T15:38:29+04:00
source : https://github.com/openapitools/openapi-generator
docs : https://openapi-generator.tech/
OpenAPI declaration file content or url
openapi: 3.0.3
info:
title: java codegen BUG
description: oneOf generates incorrect model for primitive types
version: 1.0.0
paths:
/openapi/example/path:
post:
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/Request'
responses:
200:
description: OK
content:
application/json:
schema:
$ref: '#/components/schemas/Response'
components:
schemas:
ClientIp:
oneOf:
- type: string
format: ipv4
- type: string
format: ipv6
nullable: false
example: '127.0.0.1' # or '2001:0db8:85a3:0000:0000:8a2e:0370:7334' for IPv6
Response:
properties:
result:
type: string
Request:
properties:
result:
type: string
client_ip:
$ref: "#/components/schemas/ClientIp"Generation Details
java -jar openapi-generator-cli.jar generate -g java -i oneOfbug.yaml -o .\gen\
Steps to reproduce
Generate a java client using the above yaml.
Related issues/PRs
it little bit similar to #4130