hashicorp / hashicorp/terraform-plugin-codegen-openapi

Consider mapping JSON schema `ipv4` and `ipv6` formats to `iptypes` custom types

Open
#103 0 comments 1 reaction 0 assignees View on GitHub
enhancement
Dominant language
Go
Stars
91
Forks
20
Avg merge
2d 13h
Merged PRs (30d)
1

Description

### 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 IPv4 or IPv6 address string via the `format` field: https://json-schema.org/understanding-json-schema/reference/string#ip-addresses.

Recently, HashiCorp has published [terraform-plugin-framework-nettypes](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework-nettypes@v0.1.0/iptypes), which contains an `iptypes` package with `IPv4Address` and `IPv6Address` [custom string types](https://developer.hashicorp.com/terraform/plugin/framework/handling-data/types/custom), which provide validation and semantic equality handling (for IPv6) that are often required for IP address strings. The Provider code specification already supports [custom types](https://developer.hashicorp.com/terraform/plugin/code-generation/specification#custom_type).

### Proposal

### Proposal

- For any string types that define a `format` of `ipv4`, add the `iptypes.IPv4AddressType` type and `iptypes.IPv4Address` value to the custom type in the outputted provider code spec.

#### Schema
```yaml
ipv4_prop:
description: IPv4 address string!
type: string
format: ipv4
```

#### IR Attribute
```json
{
"name": "ipv4_prop",
"string": {
"computed_optional_required": "computed",
"description": "IPv4 address string!",
"custom_type": {
"import": {
"path": "github.com/hashicorp/terraform-plugin-framework-nettypes/iptypes"
},
"type": "iptypes.IPv4AddressType",
"value_type": "iptypes.IPv4Address"
}
}
}
```

- For any string types that define a `format` of `ipv6`, add the `iptypes.IPv6AddressType` type and `iptypes.IPv6Address` value to the custom type in the outputted provider code spec.

#### Schema
```yaml
ipv6_prop:
description: IPv6 address string!
type: string
format: ipv6
```

#### IR Attribute
```json
{
"name": "ipv6_prop",
"string": {
"computed_optional_required": "computed",
"description": "IPv6 address string!",
"custom_type": {
"import": {
"path": "github.com/hashicorp/terraform-plugin-framework-nettypes/iptypes"
},
"type": "iptypes.IPv6AddressType",
"value_type": "iptypes.IPv6Address"
}
}
}
```

### Additional Information

_No response_

### Code of Conduct

- [X] I agree to follow this project's Code of Conduct

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.