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

additionalProperties schema is not parsed correctly #1427

Closed
fpoppinga opened this issue Oct 11, 2023 · 4 comments
Closed

additionalProperties schema is not parsed correctly #1427

fpoppinga opened this issue Oct 11, 2023 · 4 comments
Assignees
Labels
invalid-input status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close
Milestone

Comments

@fpoppinga
Copy link

Describe the bug
When parsing an OpenAPI spec which contains a schema for the additionalProperties field, the schema does not end up in the parsed OpenApiDocument.

To Reproduce
Steps to reproduce the current behavior:

consider the following minimal spec (example.yml):

openapi: 3.0.0
info:
  title: Sample API
  version: 0.1.9
paths:
  /users:
    get:
      responses:
        "200":
          content:
            application/json:
              schema:
                type: object
                additionalProperties:
                  schema:
                    type: object
                    properties:
                      data:
                        type: string

And the code:

using Microsoft.OpenApi.Models;
using Microsoft.OpenApi.Readers;

var document = new OpenApiStreamReader().Read(File.OpenRead("example.yml"), out var diagnostics);

var additionalProperties = document.Paths["/users"].Operations[OperationType.Get].Responses[
    "200"
].Content["application/json"]
    .Schema
    .AdditionalProperties;

Console.WriteLine(value: additionalProperties.Properties.Count); // prints "0"

This makes it impossible, to generate code based on the type of the additional properties (cf. #microsoft/kiota/62 )

Expected behavior

I would expect the additionalProperties schema to be parsed and contain the schema of type "object" with the properties dictionary containing a field data of type string.

Additional context

I think the parsing is in principle implemented in OpenApiSchemaDeserializer.cs#L161. However, somewhere there must be a bug.

@baywet
Copy link
Member

baywet commented Oct 11, 2023

Thanks for reporting this!
Is this something you'd be willing to look into further and submit a pull request for?

@baywet baywet added type:bug A broken experience help wanted priority:p2 Medium. Generally has a work-around and a smaller sub-set of customers is affected. SLA <=30 days labels Oct 11, 2023
@baywet baywet added this to the Backlog milestone Oct 11, 2023
@fpoppinga
Copy link
Author

I will see if I can have a look this weekend ;-)

@MaggieKimani1
Copy link
Contributor

MaggieKimani1 commented Oct 25, 2023

@fpoppinga the yaml file provided seems incorrect. The additionalProperties field is already defined as an OpenApiSchema object so it shouldn't have a schema field nested within it. Instead the schema should be defined directly within the additionalProperties field. Try using this instead and you'll see the object being populated:

openapi: 3.0.0
info:
  title: Sample API
  version: 0.1.9
paths:
  /users:
    get:
      responses:
        "200":
          content:
            application/json:
              schema:
                type: object
                additionalProperties:
                    type: object
                    properties:
                      data:
                        type: string

@MaggieKimani1 MaggieKimani1 added status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close invalid-input and removed type:bug A broken experience help wanted priority:p2 Medium. Generally has a work-around and a smaller sub-set of customers is affected. SLA <=30 days labels Oct 25, 2023
@MaggieKimani1
Copy link
Contributor

Closing this issue as its been addressed. Feel free to reopen if the response isn't satisfactory.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid-input status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close
Projects
None yet
Development

No branches or pull requests

3 participants