-
-
Notifications
You must be signed in to change notification settings - Fork 7.1k
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
From version 7.3.0
when referencing two models using the oneOf
keyword and:
- the first model has a required and defined property named
property1
and - the second model is a combined model using the
allOf
keyword
we get this unexpected error in the logs:
[main] ERROR o.o.codegen.DefaultCodegen - Required var property1 not in properties
[main] ERROR o.o.codegen.DefaultCodegen - Required var property1 not in properties
Although we get this error, the generator doesn't exit and generates the api code.
We also see this error in the logs, when building the project from master following these https://github.com/OpenAPITools/openapi-generator/wiki/FAQ#how-to-test-with-the-latest-master-of-openapi-generator instructions. Here is one of the logs:
...
[TestNG-test=Surefire test-3] ERROR org.openapitools.codegen.DefaultCodegen - Required var seeds not in properties
...
openapi-generator version
version 7.3.0
OpenAPI declaration file content or url
Here is the minimal yaml
file that produces the above errors:
openapi: 3.0.3
info:
title: Test
version: 1.0.0
paths:
/api/v1/user:
get:
operationId: getUser
responses:
'200':
description: Successfully fetched information for the user
content:
application/json:
schema:
oneOf:
- $ref: '#/components/schemas/UserInfoPhone'
- $ref: '#/components/schemas/UserInfoEmail'
'401':
description: Failed to authenticate request
components:
schemas:
User:
type: object
properties:
name:
type: string
surname:
type: string
UserInfoEmail:
allOf:
- $ref: '#/components/schemas/User'
- type: object
properties:
email:
type: string
UserInfoPhone:
type: object
required:
- phone
properties:
phone:
type: string
Generation Details
Steps to reproduce
To reproduce the errors, you can run:
openapi-generator-cli generate -i test.yaml -g typescript-axios
where test.yaml
contains the above script.
The errors we get when generating the code are:
[main] ERROR o.o.codegen.DefaultCodegen - Required var phone not in properties
[main] ERROR o.o.codegen.DefaultCodegen - Required var phone not in properties
Related issues/PRs
No related PRs/issues found.
Suggest a fix
The above error log is introduced by this commit 64f2cad.
We noticed that we don't get the error if we use one of the following options:
- we reverse the order we reference the components in the
oneOf
keyword - we don't use the
allOf
keyword to extend a model (e.g. in the above example define the properties of theUser
model directly on theUserInfoEmail
model) - we use the
--openapi-normalizer REF_AS_PARENT_IN_ALLOF=true
argument when generating the code.