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

support object without properties #292

Open
2 tasks
FalcoSuessgott opened this issue Apr 22, 2021 · 2 comments
Open
2 tasks

support object without properties #292

FalcoSuessgott opened this issue Apr 22, 2021 · 2 comments

Comments

@FalcoSuessgott
Copy link

Is your feature request related to a problem?

We want to use that provider as a netbox terraform provider, which supports OpenAPIv2.

Currently defintions of type objects without any properties are not supported.
Netbox offers the possibility to add custom fields to objects. Those custom fields can have various data types (bool, string, date, ...).

Since in the OpenAPI spec those custom_fields are represented as objects without any properties:

    "Secret": {
      "required": [
        "assigned_object_type",
        "assigned_object_id",
        "role",
        "plaintext"
      ],
      "type": "object",
      "properties": {
        "id": {
          "title": "ID",
          "type": "integer",
          "readOnly": true
        },
        [....]
        "custom_fields": {
          "title": "Custom fields",
          "type": "object",
          "default": {}
        },

Currently the provider responds the following:

│ 23 errors occurred:
   ....
│ 	* resource netbox_secrets: custom_fields: Default is not valid for lists or sets

As a terraform schema, custom_fields are represented as the following

"custom_fields": {
  Type:     schema.TypeMap,
  Optional: true,
},

Describe the solution you'd like

It would be nice to have maps supported or to find a workaround to get that provider working with empty objects.

Describe alternatives you've considered

Maybe you can give us some hints where to start implementing this feature on our own.

Checklist (for admin only)

Don't forget to go through the checklist to make sure the issue is created properly:

  • I have added a corresponding label (feature request) to the issue (right side menu)
  • I have added this issue to the 'API Terraform Provider' GitHub project (right side menu)
@dikhan
Copy link
Owner

dikhan commented Apr 26, 2021

Hi @FalcoSuessgott ,

Thanks for opening the issue, I was just reading the custom field docs to try and get a bit more context and was wondering about the following:

  • If you have control over the API code, have you considered defining the model for the custom fields as follows? This would provide the flexibility to users to provide custom fields knowing the expected types supported and the backend could perform the corresponding validation upon receipt (eg: ensuring a integer type custom field value is actually an integer, etc). This is already supported by the OpenAPI Terraform provider, so if you have any control over the API that could be something to try out.
definitions:
  Secret:
    type: "object"
    required:
      ...
    properties:
...
      custom_fields:
        title: "Custom fields"
        type: "array"
        items:
          type: "object"
          properties:
            type:
              description: "custom property type, must be one of the supported types as specified in the regex"
              regex: "string|integer|boolean|date|url|selection|multiple_selection"
              type: string
            value:
              type: string
{
    "id": 123,
    "url": "http://localhost:8000/api/dcim/sites/123/",
    "name": "Raleigh 42",
    ...
    "custom_fields": {
        "deployed": "2018-06-19",
        "site_code": "US-NC-RAL42"
    },
    ...

Hope that helps!

Thanks
Dani

@dikhan
Copy link
Owner

dikhan commented Feb 1, 2022

Hi @FalcoSuessgott ,

Just wanted to follow up on this and see whether the previous response help at all. Reading again the error you got from the terraform provider I wonder if removing the Default from the OpenApi spec for the object property might also unblock you:

  "Secret": {
      "required": [
        "assigned_object_type",
        "assigned_object_id",
        "role",
        "plaintext"
      ],
      "type": "object",
      "properties": {
        "id": {
          "title": "ID",
          "type": "integer",
          "readOnly": true
        },
        [....]
        "custom_fields": {
          "title": "Custom fields",
          "type": "object",
        },

Currently, Terraform does not support setting defaults for fields other than primitives.

Thanks,
Dani

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants