hashicorp / terraform-plugin-codegen-openapi

OpenAPI to Terraform Provider Code Generation Specification
Mozilla Public License 2.0
53 stars 12 forks source link

Consider mapping JSON schema `date-time` format to `timetypes.RFC3339` custom type #102

Open austinvalle opened 9 months ago

austinvalle commented 9 months ago

Use Cases or Problem Statement

JSON schema (the backbone of all the request/response body schemas in OpenAPI 3.0/3.1) supports designating a type: string as an RFC3339 string via format: date-time: https://json-schema.org/understanding-json-schema/reference/string#dates-and-times.

Recently, HashiCorp has published terraform-plugin-framework-timetypes, which contains an RFC3339 custom string type, which provides validation and semantic equality handling that is often required for RFC3339 strings. The Provider code specification already supports custom types.

Proposal

For any string types that define a format of date-time, add the timetypes.RFC3339Type type and timetypes.RFC3339 value to the custom type in the outputted provider code spec.

Schema

rfc3339_prop:
  description: RFC3339 date-time string!
  type: string
  format: date-time

IR Attribute

{
  "name": "rfc3339_prop",
  "string": {
    "computed_optional_required": "computed",
    "description": "RFC3339 date-time string!",
    "custom_type": {
      "import": {
        "path": "github.com/hashicorp/terraform-plugin-framework-timetypes/timetypes"
      },
      "type": "timetypes.RFC3339Type",
      "value_type": "timetypes.RFC3339"
    }
  }
}

Additional Information

No response

Code of Conduct