- Notifications
You must be signed in to change notification settings - Fork 2.9k
9608 drf spectacular2 #11626
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
Merged
Merged
9608 drf spectacular2 #11626
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
… unique ID of each request for change logging
* Enable HTMX rendering for embedded tables * Start converting embedded tables to use HTMX (WIP) * Additional table conversions (WIP) * Standardize HTMX usage for nested group models * Enable HTMX for additional emebedded tables * Fix HTMX table rendering for ObjectChildrenView * Standardize usage of inc/panel_table.html * Hide selection boxes in embedded tables
Closed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
Fixes: #9608
Removes drf-yasg and replaces it with drf-spectacular which allows us to go from Swagger 2 to OpenAPI 3.
The documentation will also need to be updated for this change.
There are still a few warnings around IPAddressField but it defaults to string which is correct. You can generate the file and see any warnings via:
Implemenation Notes:
had to add allow_null=True to many serializers. This should be correct as for example provider_network if you look at the class it is a nullable field.
code for NetBoxAutoSchema is to fix the bulk operations.
The 3 generated spec specify all(?) readonly fields as required. e.g. Prefix which list as required: [ "_depth", "children", "created" "display", "family", "id", "last_updated", "prefix", "url"]. This is different then the 2 spec where the readonly fields are not required. The 3 spec is more correct as the field are marked as readonly, however it is possible some client generators may have difficult with this, this can be controlled via a settings for SPECTACULAR_SETTINGS:
Had to add some get_serializer_class to some ViewSets - these views had different serializers for get/post but didn't define a base serializer which caused issues with drf-spectacular. First put a base serializer in with serializer_class =, however this caused side-issues of it being a class within NetBoxAutoSchema so used the get_serializer_class.
There is difference in the paths in the schema old (api is prefixed): "/circuits/circuit-terminations/" new: "/api/circuits/circuit-terminations/" not sure if this would have any effects on clients.
The Writable classes have "Request" post-pended to the name via spectacular, again don't think this will have any major effect on clients: "$ref: '#/definitions/WritableCircuitTermination'" -> "$ref: '#/components/schemas/WritableCircuitTerminationRequest'"
Descriptions for the classes in the schema are not good, usually defaulting to a base item, however the descriptions are not present in the 2.0 schema file, so not something broken just has never been added. Better descriptions to the serializers can be added in the future. For example the WritableCircuitRequest has the description "description: Adds support for custom fields and tags."
Merging Info
Warnings
Currently has the following warnings - these default to string, or auto resolve, can look at going through and cleaning these up so no warnings later.
Not sure why IPAddressField is causing warnings - tried to override it in several places to prevent the warning without success, again defaults to string which is correct.
/Users/ahanson/dev/work/netbox/netbox/ipam/api/nested_serializers.py: Warning [DeviceViewSet > DeviceWithConfigContextSerializer > NestedIPAddressSerializer]: model field "IPAddressField" has no mapping in ModelSerializer. It may be a deprecated field. Defaulting to "string"
/Users/ahanson/dev/work/netbox/venv/lib/python3.10/site-packages/rest_framework/serializers.py: Warning [DeviceViewSet > WritableDeviceWithConfigContextSerializer]: unable to resolve type hint for function "primary_ip". Consider using a type hint or @extend_schema_field. Defaulting to string.
/Users/ahanson/dev/work/netbox/venv/lib/python3.10/site-packages/rest_framework/serializers.py: Warning [InterfaceViewSet > WritableInterfaceSerializer]: unable to resolve type hint for function "l2vpn_termination". Consider using a type hint or @extend_schema_field. Defaulting to string.
/Users/ahanson/dev/work/netbox/venv/lib/python3.10/site-packages/rest_framework/serializers.py: Warning [VirtualDeviceContextViewSet > WritableVirtualDeviceContextSerializer]: unable to resolve type hint for function "primary_ip". Consider using a type hint or @extend_schema_field. Defaulting to string.
/Users/ahanson/dev/work/netbox/venv/lib/python3.10/site-packages/rest_framework/serializers.py: Warning [AggregateViewSet > WritableAggregateSerializer]: unable to resolve type hint for function "family". Consider using a type hint or @extend_schema_field. Defaulting to string.
/Users/ahanson/dev/work/netbox/netbox/ipam/api/serializers.py: Warning [IPAddressViewSet > IPAddressSerializer]: model field "IPAddressField" has no mapping in ModelSerializer. It may be a deprecated field. Defaulting to "string"
/Users/ahanson/dev/work/netbox/venv/lib/python3.10/site-packages/rest_framework/serializers.py: Warning [IPAddressViewSet > WritableIPAddressSerializer]: unable to resolve type hint for function "family". Consider using a type hint or @extend_schema_field. Defaulting to string.
/Users/ahanson/dev/work/netbox/venv/lib/python3.10/site-packages/rest_framework/serializers.py: Warning [IPAddressViewSet > WritableIPAddressSerializer]: model field "IPAddressField" has no mapping in ModelSerializer. It may be a deprecated field. Defaulting to "string"
/Users/ahanson/dev/work/netbox/netbox/ipam/api/serializers.py: Warning [IPRangeViewSet > IPRangeSerializer]: model field "IPAddressField" has no mapping in ModelSerializer. It may be a deprecated field. Defaulting to "string"
/Users/ahanson/dev/work/netbox/venv/lib/python3.10/site-packages/rest_framework/serializers.py: Warning [IPRangeViewSet > WritableIPRangeSerializer]: unable to resolve type hint for function "family". Consider using a type hint or @extend_schema_field. Defaulting to string.
/Users/ahanson/dev/work/netbox/venv/lib/python3.10/site-packages/rest_framework/serializers.py: Warning [IPRangeViewSet > WritableIPRangeSerializer]: model field "IPAddressField" has no mapping in ModelSerializer. It may be a deprecated field. Defaulting to "string"
/Users/ahanson/dev/work/netbox/venv/lib/python3.10/site-packages/rest_framework/serializers.py: Warning [PrefixViewSet > WritablePrefixSerializer]: unable to resolve type hint for function "family". Consider using a type hint or @extend_schema_field. Defaulting to string.
/Users/ahanson/dev/work/netbox/netbox/ipam/filtersets.py: Warning [ServiceViewSet > ServiceFilterSet]: model field "IPAddressField" has no mapping in ModelSerializer. It may be a deprecated field. Defaulting to "string"
/Users/ahanson/dev/work/netbox/venv/lib/python3.10/site-packages/rest_framework/serializers.py: Warning [AvailableVLANsView > WritableVLANSerializer]: unable to resolve type hint for function "l2vpn_termination". Consider using a type hint or @extend_schema_field. Defaulting to string.
/Users/ahanson/dev/work/netbox/venv/lib/python3.10/site-packages/rest_framework/serializers.py: Warning [VLANViewSet > WritableVLANSerializer]: unable to resolve type hint for function "l2vpn_termination". Consider using a type hint or @extend_schema_field. Defaulting to string.
/Users/ahanson/dev/work/netbox/venv/lib/python3.10/site-packages/rest_framework/serializers.py: Warning [VMInterfaceViewSet > WritableVMInterfaceSerializer]: unable to resolve type hint for function "l2vpn_termination". Consider using a type hint or @extend_schema_field. Defaulting to string.
/Users/ahanson/dev/work/netbox/venv/lib/python3.10/site-packages/rest_framework/serializers.py: Warning [VirtualMachineViewSet > WritableVirtualMachineWithConfigContextSerializer]: unable to resolve type hint for function "primary_ip". Consider using a type hint or @extend_schema_field. Defaulting to string.
Warning: enum naming encountered a non-optimally resolvable collision for fields named "type". The same name has been used for multiple choice sets in multiple components. The collision was resolved with "TypeDdfEnum". add an entry to ENUM_NAME_OVERRIDES to fix the naming.
Warning: enum naming encountered a non-optimally resolvable collision for fields named "type". The same name has been used for multiple choice sets in multiple components. The collision was resolved with "Type261Enum". add an entry to ENUM_NAME_OVERRIDES to fix the naming.
Warning: enum naming encountered a non-optimally resolvable collision for fields named "type". The same name has been used for multiple choice sets in multiple components. The collision was resolved with "Type666Enum". add an entry to ENUM_NAME_OVERRIDES to fix the naming.
Warning: enum naming encountered a non-optimally resolvable collision for fields named "type". The same name has been used for multiple choice sets in multiple components. The collision was resolved with "Type6e5Enum". add an entry to ENUM_NAME_OVERRIDES to fix the naming.
Warning: enum naming encountered a non-optimally resolvable collision for fields named "type". The same name has been used for multiple choice sets in multiple components. The collision was resolved with "Type2fcEnum". add an entry to ENUM_NAME_OVERRIDES to fix the naming.
Warning: enum naming encountered a non-optimally resolvable collision for fields named "type". The same name has been used for multiple choice sets in multiple components. The collision was resolved with "Type209Enum". add an entry to ENUM_NAME_OVERRIDES to fix the naming.
Warning: enum naming encountered a non-optimally resolvable collision for fields named "type". The same name has been used for multiple choice sets in multiple components. The collision was resolved with "Type653Enum". add an entry to ENUM_NAME_OVERRIDES to fix the naming.
Warning: enum naming encountered a non-optimally resolvable collision for fields named "protocol". The same name has been used for multiple choice sets in multiple components. The collision was resolved with "Protocol766Enum". add an entry to ENUM_NAME_OVERRIDES to fix the naming.
Warning: enum naming encountered a non-optimally resolvable collision for fields named "protocol". The same name has been used for multiple choice sets in multiple components. The collision was resolved with "ProtocolFe4Enum". add an entry to ENUM_NAME_OVERRIDES to fix the naming.
Warning: enum naming encountered a non-optimally resolvable collision for fields named "auth_type". The same name has been used for multiple choice sets in multiple components. The collision was resolved with "AuthTypeF47Enum". add an entry to ENUM_NAME_OVERRIDES to fix the naming.
Warning: enum naming encountered a non-optimally resolvable collision for fields named "status". The same name has been used for multiple choice sets in multiple components. The collision was resolved with "Status565Enum". add an entry to ENUM_NAME_OVERRIDES to fix the naming.
Warning: enum naming encountered a non-optimally resolvable collision for fields named "status". The same name has been used for multiple choice sets in multiple components. The collision was resolved with "Status6a0Enum". add an entry to ENUM_NAME_OVERRIDES to fix the naming.
Warning: enum naming encountered a non-optimally resolvable collision for fields named "status". The same name has been used for multiple choice sets in multiple components. The collision was resolved with "Status62cEnum". add an entry to ENUM_NAME_OVERRIDES to fix the naming.
Warning: enum naming encountered a non-optimally resolvable collision for fields named "status". The same name has been used for multiple choice sets in multiple components. The collision was resolved with "Status71fEnum". add an entry to ENUM_NAME_OVERRIDES to fix the naming.
Warning: enum naming encountered a non-optimally resolvable collision for fields named "status". The same name has been used for multiple choice sets in multiple components. The collision was resolved with "StatusB66Enum". add an entry to ENUM_NAME_OVERRIDES to fix the naming.