Skip to content
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

Schema object allOf requires type #4074

Closed
tstibbs opened this issue Jan 29, 2024 · 2 comments · Fixed by #4381
Closed

Schema object allOf requires type #4074

tstibbs opened this issue Jan 29, 2024 · 2 comments · Fixed by #4381
Assignees
Labels
generator Issues or improvements relater to generation capabilities. help wanted Issue caused by core project dependency modules or library type:bug A broken experience
Milestone

Comments

@tstibbs
Copy link

tstibbs commented Jan 29, 2024

If a schema object uses allOf and includes an inline schema definition, but that inline definition doesn't specify type, then the inline definition is ignored (in java generation at least).

Minimal example:

openapi: 3.0.3
servers:
  - url: 'https://example.com'
info:
  title: example
  version: 0.0.1
paths:
  /path:
    post:
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/outerPayload'
      responses:
        '201':
          description: Created
          content:
            application/json:
              schema:
                type: string

components:
  schemas:
    outerPayload:
      allOf:
        - $ref: '#/components/schemas/innerPayload'
        - properties:
            someField:
              type: string
    innerPayload:
      properties:
        anotherField:
          type: string

Steps to reproduce

Run command: kiota generate --language java -n 'test'
Version: 1.10.1 (docker container mcr.microsoft.com/openapi/kiota)

Expected behaviour

A class test.OuterPayload should be generated with fields someField and anotherField and matching setter methods (note anotherField is in a superclass).

Actual behaviour

Only anotherField appears; someField is not generated.
No errors or warnings are logged - the fields/methods are simply missing in the generated java code.

Workaround

In the inline schema definition, include type: object.
Of course this is only possible if you are in control of the schema in use - so in most cases this workaround won't work.

Notes

I believe the above document is valid according to the OpenAPI spec. In all other situations, the type appears to default to object and it does not need to be specified explicitly. For example, in innerPayload in the example above, type: object is not required. It appears only to be within allOf that type: object is required.

@baywet
Copy link
Member

baywet commented Jan 29, 2024

Thanks for using kiota and for reaching out.
There are a couple of ways we could alleviate this.

We could add a validation rule that warns when a schema has properties, but its type isn't object. like this one

This would prompt people to edit their description and add the missing type object.

We could alliteratively/also change this evaluation rule to add am or condition branch which checks on the presence of properties. This might have side effects though. Additional unit tests would go here

Is this something you'd be interested in submitting a pull request for?

@baywet baywet added type:bug A broken experience help wanted Issue caused by core project dependency modules or library generator Issues or improvements relater to generation capabilities. labels Jan 29, 2024
@baywet baywet added this to the Backlog milestone Jan 29, 2024
@baywet baywet assigned baywet and unassigned tstibbs May 7, 2024
baywet added a commit that referenced this issue May 7, 2024
@baywet baywet moved this from Todo 📃 to In Progress 🚧 in Kiota May 7, 2024
@baywet baywet modified the milestones: Backlog, Kiota v1.15 May 7, 2024
@baywet
Copy link
Member

baywet commented May 7, 2024

Hi @tstibbs
Here is a short update, I was able to isolate and fix the root cause of this issue in #4381
I'm still running tests for the other issues this PR is addressing, but it's promising!
Thanks for your patience on this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
generator Issues or improvements relater to generation capabilities. help wanted Issue caused by core project dependency modules or library type:bug A broken experience
Projects
Archived in project
2 participants