Repository: netbox-community/netbox

Issue:
API Definitions for available-ips and available-prefixes are incorrect
<!--
    NOTE: IF YOUR ISSUE DOES NOT FOLLOW THIS TEMPLATE, IT WILL BE CLOSED.

    Please indicate the nature of the change by placing an X in one of the
    boxes below.
-->
### Change Type
[ ] Addition
[x] Correction
[ ] Deprecation
[ ] Cleanup (formatting, typos, etc.)

### Area
[ ] Installation instructions
[ ] Configuration parameters
[ ] Functionality/features
[x] REST API
[ ] Administration/development
[ ] Other

<!-- Describe the proposed change(s). -->
### Proposed Changes
I'm writing a ipam project with go-netbox(https://github.com/kobayashi/go-netbox for v2.8), which generate the client from swagger. And I'm using the prefix/available-ips api to create unused ip address. I notice that the api documents in http://netbox/api/docs/ has difference with actually code:
* The request model should be IPAddress rather than WritablePrefix
  _ref: https://github.com/netbox-community/netbox/blob/v2.8.3/netbox/ipam/api/views.py#L211_
* The return code should be 201 rather than 200
  _ref: https://github.com/netbox-community/netbox/blob/v2.8.3/netbox/ipam/api/views.py#L218_

These mismatches make go-netbox client unable to work correctly. I would appreciate if this can be fixed.


Discussion:
You are correct in that it should be IPAddress instead of WritablePrefix, however you are incorrect in the return code.  The return code should be 201, however the proper response should still be 201 as it is "created"
Yeah, the return code should be 201. And that is what I said above. The problem is that the api doc told me to use 200 as the success code.
I think this line may be the cause
https://github.com/netbox-community/netbox/blob/c507ab30e97bcb3e2f503a9e6d9558f6a4cb25aa/netbox/ipam/api/views.py#L164

Resolving patch:
diff --git a/netbox/ipam/api/views.py b/netbox/ipam/api/views.py
--- a/netbox/ipam/api/views.py
+++ b/netbox/ipam/api/views.py
@@ -74,12 +74,8 @@ class PrefixViewSet(CustomFieldModelViewSet):
     serializer_class = serializers.PrefixSerializer
     filterset_class = filters.PrefixFilterSet
 
-    @swagger_auto_schema(
-        methods=['get', 'post'],
-        responses={
-            200: serializers.AvailablePrefixSerializer(many=True),
-        }
-    )
+    @swagger_auto_schema(method='get', responses={200: serializers.AvailablePrefixSerializer(many=True)})
+    @swagger_auto_schema(method='post', responses={201: serializers.AvailablePrefixSerializer(many=True)})
     @action(detail=True, url_path='available-prefixes', methods=['get', 'post'])
     @advisory_lock(ADVISORY_LOCK_KEYS['available-prefixes'])
     def available_prefixes(self, request, pk=None):
@@ -158,12 +154,9 @@ def available_prefixes(self, request, pk=None):
 
             return Response(serializer.data)
 
-    @swagger_auto_schema(
-        methods=['get', 'post'],
-        responses={
-            200: serializers.AvailableIPSerializer(many=True),
-        }
-    )
+    @swagger_auto_schema(method='get', responses={200: serializers.AvailableIPSerializer(many=True)})
+    @swagger_auto_schema(method='post', responses={201: serializers.AvailableIPSerializer(many=True)},
+                         request_body=serializers.AvailableIPSerializer(many=False))
     @action(detail=True, url_path='available-ips', methods=['get', 'post'])
     @advisory_lock(ADVISORY_LOCK_KEYS['available-ips'])
     def available_ips(self, request, pk=None):


Test patch: