openapi-generator icon indicating copy to clipboard operation
openapi-generator copied to clipboard

[BUG][Codegen] 'Required property not in properties' error when the second referenced model is a combined model

Open dorothea-kalliora opened this issue 2 years ago • 2 comments

Bug Report Checklist

  • [x] Have you provided a full/minimal spec to reproduce the issue?
  • [x] Have you validated the input using an OpenAPI validator (example)?
  • [x] Have you tested with the latest master to confirm the issue still exists?
  • [x] Have you searched for related issues/PRs?
  • [x] 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:

  1. the first model has a required and defined property named property1 and
  2. 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 https://github.com/OpenAPITools/openapi-generator/commit/64f2cad9e8995db1d92c718576be3f5ca49da02e.

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 the User model directly on the UserInfoEmail model)
  • we use the --openapi-normalizer REF_AS_PARENT_IN_ALLOF=true argument when generating the code.

dorothea-kalliora avatar Feb 14 '24 16:02 dorothea-kalliora

Wondering if there has been any progress on this or if there is a recommended workaround

MattTheRed avatar May 29 '24 14:05 MattTheRed

same with this issue.

fcarrero avatar Jun 26 '24 16:06 fcarrero

bump

wfajkowski avatar Jul 10 '24 14:07 wfajkowski