Repository navigation
Description
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
- Generate a client from the OpenAPI schema document.
- Attempt to query the server on various end points, particularly order_so_retrieve (
/api/order/so/{id}/) - 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.
Activity
1337joe commentedon 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 commentedon Feb 7, 2025
The schema is auto generated from the models so this would need addressing in the serializer, not the schema.
matmair commentedon 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
github-actions commentedon Apr 17, 2025
This issue seems stale. Please react to show this is still important.
matmair commentedon Apr 17, 2025
@1337joe is this being addressed to our satisfaction now?
1337joe commentedon Apr 17, 2025
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.