Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
5 of 6 tasks
dorothea-kalliora opened this issue Feb 14, 2024 · 7 comments · Fixed by #20623

Comments

@dorothea-kalliora
Copy link

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:

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

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

@fcarrero
Copy link

same with this issue.

@wfajkowski
Copy link

bump

@mdeheus
Copy link

mdeheus commented Sep 4, 2024

We have the same issue. We consider rolling back to openapi generator version 7.2.0 to avoid the 20+ errors in the log during compilation.

@blouflashdb
Copy link

Same Problem here with Version 7.11

@wing328
Copy link
Member

wing328 commented Feb 5, 2025

thanks for reporting the issue.

One way to use debug instead of error assuming there's actually no change in the output. In other words, the error message is false alarm.

Can you please confirm there's no change in the output when upgrading from v7.2.0 to newer versions?

cc @martin-mfg (author of 64f2cad)

@martin-mfg
Copy link
Contributor

TL;DR: It's more or less a false alarm and I will remove it.

As pointed out in this thread, the error message was introduced in 64f2cad, via a PR opened by me. This change only added the printed message, the reported "problem" itself existed already before. And the reported "problem" is in fact not (always) a problem. At the specific point in the code, it can be totally fine that a property is not part of the properties collection.

On the other hand, in certain situations it might in fact be a problem. OpenAPI Generator for sure has shortcomings when processing allOf/anyOf/oneOf specs. E.g. generating Java code from modules/openapi-generator/src/test/resources/3_0/anyOfDiscriminator.yaml triggers the discussed error message - and also it results in code which doesn't compile and which misses some of the specified properties. But this can be addressed in separate PRs by other contributors.

Lastly, the discussed error message was part of my PR only because I accidentally included changes by @dabdirb from his PR in my PR. So maybe @dabdirb has further insights about this error message?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants