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

Ability to exclude schema attribute from resource or data source in generator config #81

Closed
pauly4it opened this issue Oct 21, 2023 · 3 comments · Fixed by #87
Closed
Assignees
Labels
enhancement New feature or request

Comments

@pauly4it
Copy link

Similar to how you can override an attribute description in the generator config, it would be useful to be able to exclude an attribute or sub-attribute from a resource or data source.

Use cases

  • Exclude an attribute related to functionality we do not want to expose via the Terraform provider
  • Exclude an attribute that uses a schema type not yet supported by the codegen tool or which is causing generation errors

Example
A System resource post request has the following:

SystemPostRequest:
  properties:
    feature_a:
      $ref: '#/components/schemas/SystemFeatureAConfig'
    feature_b:
      description: Feature B is enabled
      type: boolean
    feature_c:
      $ref: '#/components/schemas/SystemFeatureCConfig'    
    name:
      description: system name
      type: string
  required:
    - name
SystemFeatureAConfig:
  properties:
    customization:
      $ref: '#/components/schemas/SystemFeatureACustomization'
    enforced:
      description: true if the feature is enforced
      type: boolean
    type:
      description: enforcement type
      type: string
  required:
    - enforced
    - type
SystemFeatureACustomization: {}
SystemFeatureBConfig:
  properties:
    enforced:
      description: true if the feature is enforced
      type: boolean
    type:
      description: enforcement type
      type: string
  required:
    - enforced
    - type
SystemFeatureCConfig:
  # .. schema

For this resource, let's say we don't want to expose the configuration of Feature C via the Terraform provider, and we want to disable Feature A's customization because it's an Any Type schema not currently supported by the codegen tool.

@austinvalle austinvalle added the enhancement New feature or request label Oct 23, 2023
@austinvalle
Copy link
Member

austinvalle commented Oct 23, 2023

This request seems like a good idea! There are definitely limitations to what can be generated (especially early on in the tech preview), so providing this escape hatch can remove a lot of headache 👍🏻

I'm thinking maybe a similar "flattened" style to the overrides, like:

data_sources:
  gists:
    read:
      path: /gists/{gist_id}
      method: GET
    schema:
      ignores:
        # Ignore a specific property in an object
        - fork_of.forks
        # Ignore an entire object and all child properties
        - fork_of
        # Ignore a specific property at the root
        - comments_url

Or in your example:

data_sources:
  system:
    read:
      path: /system
      method: GET
    schema:
      ignores:
        - feature_a.customization
        - feature_c

I think it's possible that in the future, it might be desired to ignore specific properties just on the request/response body for create/read/update/delete, so maybe will need to consider how best to introduce this configuration 🤔

@austinvalle
Copy link
Member

This has been released with v0.2.0

 $ go install github.com/hashicorp/terraform-plugin-codegen-openapi/cmd/tfplugingen-openapi@latest                                  
go: downloading github.com/hashicorp/terraform-plugin-codegen-openapi v0.2.0

Documentation for this functionality can be found on the HashiCorp developer site here: https://developer.hashicorp.com/terraform/plugin/code-generation/openapi-generator#ignoring-oas-properties

Copy link

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 22, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
2 participants