Improve the openapi definition of custom_fields #3031

Closed
opened 2025-12-29 18:24:56 +01:00 by adam · 10 comments
Owner

Originally created by @smutel on GitHub (Nov 25, 2019).

Environment

  • Python version: 3.5.2
  • NetBox version: 2.6.7

Proposed Functionality

Currently custom_fields are described as below in the swagger.json:

"custom_fields": {                                                      
  "title": "Custom fields",
  "type": "object"
},  

We this kind of definition, it's not easy to parse code retrieved from the api. In particular to develop a terraform provider or to use this plugin for openapi: https://github.com/dikhan/terraform-provider-openapi.

The author of this plugin suggest to define custom_fields as below:

"custom_fields":
  "title": "Custom fields",  
  "type": "array"
    "items":
      $ref: '#/definitions/custom_fields'

  "custom_field":
    "type": "object"
    "properties":
      "property_name":
        "type": "string"
      "property_type":
        "type": "string"
      "property_value":
        "type": "string"

Use Case

  • Make easy the code to use this part of this API
  • Automation

Database Changes

I don't think so that a dabase change is needed.

External Dependencies

Don't know.

Originally created by @smutel on GitHub (Nov 25, 2019). ### Environment * Python version: 3.5.2 * NetBox version: 2.6.7 ### Proposed Functionality Currently custom_fields are described as below in the swagger.json: ```json "custom_fields": { "title": "Custom fields", "type": "object" }, ``` We this kind of definition, it's not easy to parse code retrieved from the api. In particular to develop a terraform provider or to use this plugin for openapi: https://github.com/dikhan/terraform-provider-openapi. The author of this plugin suggest to define custom_fields as below: ```json "custom_fields": "title": "Custom fields", "type": "array" "items": $ref: '#/definitions/custom_fields' "custom_field": "type": "object" "properties": "property_name": "type": "string" "property_type": "type": "string" "property_value": "type": "string" ``` <!-- Convey an example use case for your proposed feature. Write from the perspective of a NetBox user who would benefit from the proposed functionality and describe how. ---> ### Use Case * Make easy the code to use this part of this API * Automation <!-- Note any changes to the database schema necessary to support the new feature. For example, does the proposal require adding a new model or field? (Not all new features require database changes.) ---> ### Database Changes I don't think so that a dabase change is needed. <!-- List any new dependencies on external libraries or services that this new feature would introduce. For example, does the proposal require the installation of a new Python package? (Not all new features introduce new dependencies.) --> ### External Dependencies Don't know.
adam added the type: featurepending closure labels 2025-12-29 18:24:56 +01:00
adam closed this issue 2025-12-29 18:24:56 +01:00
Author
Owner

@kobayashi commented on GitHub (Dec 5, 2019):

Do want to add custom fields through api? or let me know more specific use case for this?

@kobayashi commented on GitHub (Dec 5, 2019): Do want to add custom fields through api? or let me know more specific use case for this?
Author
Owner

@smutel commented on GitHub (Dec 5, 2019):

Creating a terraform provider for netbox.

@smutel commented on GitHub (Dec 5, 2019): Creating a terraform provider for netbox.
Author
Owner

@kobayashi commented on GitHub (Dec 6, 2019):

Nice! Is it related to change the scheme though? If that would be recommendation from your reference, please let me clear reason why that is recommended. Sorry but I am not familiar much with how to create a terraform provider.

@kobayashi commented on GitHub (Dec 6, 2019): Nice! Is it related to change the scheme though? If that would be recommendation from your reference, please let me clear reason why that is recommended. Sorry but I am not familiar much with how to create a terraform provider.
Author
Owner

@saper commented on GitHub (Dec 14, 2019):

It looks more complex like this - custom fields can have 6 types. For example, a boolean field will be returned by API like this:

    "custom_fields": {
        "test_field": null
      },

This will not work with something like name/value

@saper commented on GitHub (Dec 14, 2019): It looks more complex like this - custom fields can have 6 types. For example, a boolean field will be returned by API like this: ``` "custom_fields": { "test_field": null }, ``` This will not work with something like `name`/`value`
Author
Owner

@saper commented on GitHub (Dec 14, 2019):

The question is - should swagger API definition change every time we add/delete a custom field?

@saper commented on GitHub (Dec 14, 2019): The question is - should swagger API definition change every time we add/delete a custom field?
Author
Owner

@stale[bot] commented on GitHub (Dec 28, 2019):

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. NetBox is governed by a small group of core maintainers which means not all opened issues may receive direct feedback. Please see our contributing guide.

@stale[bot] commented on GitHub (Dec 28, 2019): This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. NetBox is governed by a small group of core maintainers which means not all opened issues may receive direct feedback. Please see our [contributing guide](https://github.com/netbox-community/netbox/blob/develop/CONTRIBUTING.md).
Author
Owner

@lampwins commented on GitHub (Dec 30, 2019):

The question is - should swagger API definition change every time we add/delete a custom field?

My take on this is yes. In NetBox methodology, custom fields are a part of the model schema and realistically change infrequently.

We could do this with a custom field inspector but the problem is it would require a DB query to get the field definitions. It has been proposed in the past that we switch the schema to be served as static content instead of being rendered on the fly, which would probably make this more feasible.

@lampwins commented on GitHub (Dec 30, 2019): > The question is - should swagger API definition change every time we add/delete a custom field? My take on this is yes. In NetBox methodology, custom fields are a part of the model schema and realistically change infrequently. We could do this with a custom field inspector but the problem is it would require a DB query to get the field definitions. It has been proposed in the past that we switch the schema to be served as static content instead of being rendered on the fly, which would probably make this more feasible.
Author
Owner

@saper commented on GitHub (Dec 30, 2019):

It has been proposed in the past that we switch the schema to be served as static content instead of being rendered on the fly, which would probably make this more feasible.

Thank you. This makes perfect sense. An additional advantage of static API definitions is that it might be easier to version them - it should be possible to understand when and why the API has changed.

This opens up a (remote) possibility to support multiple versions of API in the future at the same time.

(We are considering opening up netbox API to a wide range of internal consumers and it would be great to have ability to control the stability of the interface definitions somehow).

@saper commented on GitHub (Dec 30, 2019): > It has been proposed in the past that we switch the schema to be served as static content instead of being rendered on the fly, which would probably make this more feasible. Thank you. This makes perfect sense. An additional advantage of static API definitions is that it might be easier to version them - it should be possible to understand when and why the API has changed. This opens up a (remote) possibility to support multiple versions of API in the future at the same time. (We are considering opening up netbox API to a wide range of internal consumers and it would be great to have ability to control the stability of the interface definitions somehow).
Author
Owner

@stale[bot] commented on GitHub (Jan 13, 2020):

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. NetBox is governed by a small group of core maintainers which means not all opened issues may receive direct feedback. Please see our contributing guide.

@stale[bot] commented on GitHub (Jan 13, 2020): This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. NetBox is governed by a small group of core maintainers which means not all opened issues may receive direct feedback. Please see our [contributing guide](https://github.com/netbox-community/netbox/blob/develop/CONTRIBUTING.md).
Author
Owner

@stale[bot] commented on GitHub (Jan 20, 2020):

This issue has been automatically closed due to lack of activity. In an effort to reduce noise, please do not comment any further. Note that the core maintainers may elect to reopen this issue at a later date if deemed necessary.

@stale[bot] commented on GitHub (Jan 20, 2020): This issue has been automatically closed due to lack of activity. In an effort to reduce noise, please do not comment any further. Note that the core maintainers may elect to reopen this issue at a later date if deemed necessary.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#3031