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

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

Open
3 of 6 tasks
1337joe opened this issue Feb 7, 2025 · 3 comments
Open
3 of 6 tasks

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

1337joe opened this issue Feb 7, 2025 · 3 comments
Labels
bug Identifies a bug which needs to be addressed question This is a question

Comments

@1337joe
Copy link
Contributor

1337joe commented Feb 7, 2025

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

@1337joe 1337joe added bug Identifies a bug which needs to be addressed question This is a question triage:not-checked Item was not checked by the core team labels Feb 7, 2025
@1337joe
Copy link
Contributor Author

1337joe commented Feb 7, 2025

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.

@matmair
Copy link
Member

matmair commented Feb 7, 2025

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

@matmair matmair removed the triage:not-checked Item was not checked by the core team label Feb 7, 2025
@matmair
Copy link
Member

matmair commented Feb 7, 2025

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Identifies a bug which needs to be addressed question This is a question
Projects
None yet
Development

No branches or pull requests

2 participants