Skip to content

OpenAPI schema doesn't match data returned from the server #9045

Closed

Description

@1337joe

Please verify that this bug has NOT been raised before.

  • I checked and didn't find a similar issue

Describe the bug*

I can work with pretty much any language I can set up an IDE for, but my language of choice for anything complex is likely to be Java. I've been running SQL queries to pull data directly from my InvenTree database, but that's obviously not ideal.

Given that there's an OpenAPI schema published for InvenTree, I figured it would be straightforward to generate a Java library so I could pull data from my InvenTree instance (particularly SalesOrder data). Unfortunately, the schema-generated code doesn't support the response I get back from the server.

Running a query for order 1 against the order_so_retrieve operation on my dev server with the test data loaded I get the following error (edited to add line breaks for readability):

java.lang.IllegalArgumentException:
The field `notes` in the JSON string is not defined in the `SalesOrder` properties.
JSON: {
    "pk":1,
    "created_by":{"pk":1,"username":"admin","first_name":"","last_name":"","email":""},
    "creation_date":"2021-11-17",
    "start_date":null,
    "target_date":null,
    "description":"Selling some stuff",
    "line_items":1,
    "completed_lines":1,
    "link":"",
    "project_code":null,
    "project_code_detail":null,
    "reference":"SO0001",
    "responsible":6,
    "responsible_detail":{"pk":6,"owner_id":3,"name":"engineer","label":"user"},
    "contact":null,
    "contact_detail":null,
    "address":null,
    "address_detail":null,
    "status":20,
    "status_text":"Shipped",
    "status_custom_key":20,
    "notes":"",
    "barcode_hash":"",
    "overdue":false,
    "customer":30,
    "customer_reference":"",
    "shipment_date":"2022-09-07",
    "total_price":"150.000000",
    "order_currency":null,
    "shipments_count":1,
    "completed_shipments_count":1
}

Inspecting the SalesOrder schema definition I can verify that notes is not in the schema, but I can also see that some fields are null that the schema lists as required (address_detail, contact_detail, responsible_detail).

Steps to Reproduce

  1. Generate a client from the OpenAPI schema document.
  2. Attempt to query the server on various end points, particularly order_so_retrieve (/api/order/so/{id}/)
  3. View that the returned JSON contains notes,

Expected behaviour

I expect the JSON response from the server to comply with the documented schema.

Deployment Method

  • Docker
  • Package
  • Bare metal
  • Other - added info in Steps to Reproduce

Version Information

My dev server is running master (commit 8bea3ca), client is generated from schema version 309.

Please verify if you can reproduce this bug on the demo site.

  • I can reproduce this bug on the demo site.

Relevant log output

Activity

  1. added
    bug
    question
    triage:not-checked
    on Feb 7, 2025
  2. 1337joe commented on Feb 7, 2025

    @1337joe
    ContributorAuthor

    I'm currently digging in to the schema generation, but I felt it was worth creating an issue to track against since this is likely to be a series of pull requests instead of a small fix.

  3. matmair commented on Feb 7, 2025

    @matmair
    Member

    The schema is auto generated from the models so this would need addressing in the serializer, not the schema.

  4. removed
    triage:not-checked
    on Feb 7, 2025
  5. matmair commented on Feb 7, 2025

    @matmair
    Member

    Note that the schema is generated with a setting optimizing for renderability, not code generation - see https://drf-spectacular.readthedocs.io/en/latest/client_generation.html

  6. github-actions commented on Apr 17, 2025

    @github-actions
    Contributor

    This issue seems stale. Please react to show this is still important.

  7. added
    inactive
    on Apr 17, 2025
  8. matmair commented on Apr 17, 2025

    @matmair
    Member

    @1337joe is this being addressed to our satisfaction now?

  9. 1337joe commented on Apr 17, 2025

    @1337joe
    ContributorAuthor

    Almost. I've got one last branch I need to clean up for merging that makes a bunch of currently-required fields nullable but I keep putting that off as I test more endpoints to try to get it all at once. I'll get that finished up in the next day or two and and tag that as closing this issue.

  10. removed
    inactive
    on Apr 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugquestion

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions