hashicorp / terraform-plugin-codegen-openapi

OpenAPI to Terraform Provider Code Generation Specification
Mozilla Public License 2.0
49 stars 6 forks source link

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

Closed pauly4it closed 8 months ago

pauly4it commented 9 months ago

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

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 commented 8 months ago

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 commented 8 months ago

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

github-actions[bot] commented 1 month ago

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.