Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 27 additions & 26 deletions DESIGN.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,41 +71,42 @@ For a given [OAS type](https://spec.openapis.org/oas/v3.1.0#data-types) and form

> **NOTE:** All `Type` and `Format` fields below are native to OpenAPI Spec 3.x, with the exception of the format `set`, which is a custom field that only this generator tool is expected to support.

| Type (OAS) | Format (OAS) | Items type (OAS `array`) | Plugin Framework Attribute Type |
|------------|---------------------|--------------------------|---------------------------------------------------------------------------------------------|
| `integer` | - | - | `Int64Attribute` |
| `number` | `double` or `float` | - | `Float64Attribute` |
| `number` | (all others) | - | `NumberAttribute` |
| `string` | - | - | `StringAttribute` |
| `boolean` | - | - | `BoolAttribute` |
| `array` | - | `object` | `ListNestedAttribute` |
| `array` | - | (all others) | `ListAttribute` (nests with [element types](#oas-to-plugin-framework-element-types)) |
| `array` | `set` | `object` | `SetNestedAttribute` |
| `array` | `set` | (all others) | `SetAttribute` (nests with [element types](#oas-to-plugin-framework-element-types)) |
| `object` | - | - | `SingleNestedAttribute` |
| Type (OAS) | Format (OAS) | Other Criteria | Plugin Framework Attribute Type |
|------------|---------------------|----------------------------------------------|---------------------------------------------------------------------------------------------|
| `integer` | - | - | `Int64Attribute` |
| `number` | `double` or `float` | - | `Float64Attribute` |
| `number` | - | - | `NumberAttribute` |
| `string` | - | - | `StringAttribute` |
| `boolean` | - | - | `BoolAttribute` |
| `array` | - | `items.type == object` | `ListNestedAttribute` |
| `array` | - | `items.type == (any)` | `ListAttribute` (nests with [element types](#oas-to-plugin-framework-element-types)) |
| `array` | `set` | `items.type == object` | `SetNestedAttribute` |
| `array` | `set` | `items.type == (any)` | `SetAttribute` (nests with [element types](#oas-to-plugin-framework-element-types)) |
| `object` | - | `additionalProperties.type == object` | `MapNestedAttribute` |
| `object` | - | `additionalProperties.type == (any)` | `MapAttribute` (nests with [element types](#oas-to-plugin-framework-element-types)) |
| `object` | - | - | `SingleNestedAttribute` |

#### Unsupported Attribute Types
- `ListNestedBlock`, `SetNestedBlock`, and `SingleNestedBlock`
- While the Plugin Framework supports blocks, the Plugin Framework team encourages provider developers to prefer `ListNestedAttribute`, `SetNestedAttribute`, and `SingleNestedAttribute` for new provider development.
- `ObjectAttribute`
- The generator will default to `SingleNestedAttribute` for object types to provide the additional schema information.
- `MapNestedAttribute`, and `MapAttribute`
- Mapping for these types is currently not supported, but will be considered in future versions.

### OAS to Plugin Framework Element Types

For attributes that don't have additional schema information (currently only `ListAttribute` and `SetAttribute`), the following rules will be applied for mapping from OAS type and format combinations, into Framework element types.

| Type (OAS) | Format (OAS) | Items type (OAS `array`) | Plugin Framework Element Type |
|------------|---------------------|--------------------------|---------------------------------|
| `integer` | - | - | `Int64Type` |
| `number` | `double` or `float` | - | `Float64Type` |
| `number` | (all others) | - | `NumberType` |
| `string` | - | - | `StringType` |
| `boolean` | - | - | `BoolType` |
| `array` | - | (all) | `ListType` |
| `array` | `set` | (all) | `SetType` |
| `object` | - | - | `ObjectType` |
For attributes that don't have additional schema information (`ListAttribute`, `SetAttribute`, and `MapAttribute`), the following rules will be applied for mapping from OAS type and format combinations, into Framework element types.

| Type (OAS) | Format (OAS) | Other Criteria | Plugin Framework Element Type |
|------------|---------------------|---------------------------------------|---------------------------------|
| `integer` | - | - | `Int64Type` |
| `number` | `double` or `float` | - | `Float64Type` |
| `number` | - | - | `NumberType` |
| `string` | - | - | `StringType` |
| `boolean` | - | - | `BoolType` |
| `array` | - | - | `ListType` |
| `array` | `set` | - | `SetType` |
| `object` | - | `additionalProperties.type == (any)` | `MapType` |
| `object` | - | - | `ObjectType` |

### Required, Computed, and Optional

Expand Down
153 changes: 148 additions & 5 deletions internal/cmd/testdata/edgecase/generated_framework_ir.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,54 @@
{
"datasources": [
{
"name": "nested_lists",
"name": "map_test",
"schema": {
"attributes": [
{
"name": "main_list",
"name": "map_prop",
"map": {
"computed_optional_required": "computed_optional",
"element_type": {
"float64": {}
},
"description": "This is a map of floats"
}
},
{
"name": "mapnested_prop",
"map_nested": {
"computed_optional_required": "computed_optional",
"nested_object": {
"attributes": [
{
"name": "bool_prop",
"bool": {
"computed_optional_required": "computed_optional",
"description": "Bool inside a map!"
}
},
{
"name": "string_prop",
"string": {
"computed_optional_required": "computed_optional",
"description": "String inside a map!",
"sensitive": false
}
}
]
},
"description": "This is a map with a nested object"
}
}
]
}
},
{
"name": "nested_collections",
"schema": {
"attributes": [
{
"name": "double_nested_list",
"list": {
"computed_optional_required": "computed_optional",
"element_type": {
Expand All @@ -15,14 +58,71 @@
}
}
},
"description": "This list has another list nested underneath!"
"description": "This list has a list nested underneath!"
}
},
{
"name": "double_nested_map",
"list": {
"computed_optional_required": "computed_optional",
"element_type": {
"map": {
"element_type": {
"string": {}
}
}
},
"description": "This list has a map nested underneath!"
}
},
{
"name": "double_nested_set",
"set": {
"computed_optional_required": "computed_optional",
"element_type": {
"set": {
"element_type": {
"string": {}
}
}
},
"description": "This set has a set nested underneath!"
}
},
{
"name": "triple_nested_map",
"list": {
"computed_optional_required": "computed_optional",
"element_type": {
"set": {
"element_type": {
"map": {
"element_type": {
"object": {
"attribute_types": [
{
"name": "bool_prop",
"bool": {}
},
{
"name": "string_prop",
"string": {}
}
]
}
}
}
}
}
},
"description": "This list has a set of maps nested underneath!"
}
}
]
}
},
{
"name": "set_collections",
"name": "set_test",
"schema": {
"attributes": [
{
Expand Down Expand Up @@ -70,7 +170,50 @@
},
"resources": [
{
"name": "set_collections",
"name": "map_test",
"schema": {
"attributes": [
{
"name": "map_prop",
"map": {
"computed_optional_required": "computed_optional",
"element_type": {
"string": {}
},
"description": "This is a map of strings"
}
},
{
"name": "mapnested_prop",
"map_nested": {
"computed_optional_required": "required",
"nested_object": {
"attributes": [
{
"name": "bool_prop",
"bool": {
"computed_optional_required": "computed_optional",
"description": "Bool inside a map!"
}
},
{
"name": "string_prop",
"string": {
"computed_optional_required": "computed_optional",
"description": "String inside a map!",
"sensitive": false
}
}
]
},
"description": "This is a map with a nested object"
}
}
]
}
},
{
"name": "set_test",
"schema": {
"attributes": [
{
Expand Down
104 changes: 97 additions & 7 deletions internal/cmd/testdata/edgecase/openapi_spec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ info:
description: This is a fake API spec that was built to test some of the less common API schema structures and their mapping in the OpenAPI to Framework code generator
version: 1.0.0
paths:
/nested_lists:
/nested_collections:
get:
summary: Test for nested lists (list within a list)
summary: Test for nested collections (list within a list, set within a list, map within a list)
responses:
"200":
description: OK
Expand All @@ -15,9 +15,52 @@ paths:
schema:
type: object
properties:
main_list:
$ref: "#/components/schemas/multidimensional_array_schema"
/set_collections:
double_nested_list:
$ref: "#/components/schemas/double_nested_list_schema"
double_nested_set:
$ref: "#/components/schemas/double_nested_set_schema"
double_nested_map:
$ref: "#/components/schemas/double_nested_map_schema"
triple_nested_map:
$ref: "#/components/schemas/triple_nested_map_schema"
/map_test:
get:
summary: Test for MapNested attributes and Map attributes in a data source
responses:
"200":
description: OK
content:
application/json:
schema:
type: object
properties:
mapnested_prop:
$ref: "#/components/schemas/mapnested_schema"
map_prop:
description: This is a map of floats
type: object
additionalProperties:
type: number
format: float
post:
summary: Test for MapNested attributes and Map attributes in a resource
requestBody:
required: true
content:
application/json:
schema:
type: object
required:
- mapnested_prop
properties:
mapnested_prop:
$ref: "#/components/schemas/mapnested_schema"
map_prop:
description: This is a map of strings
type: object
additionalProperties:
type: string
/set_test:
get:
summary: Test for SetNested attributes and Set attributes in a data source
responses:
Expand Down Expand Up @@ -57,13 +100,48 @@ paths:
type: string
components:
schemas:
multidimensional_array_schema:
description: This list has another list nested underneath!
double_nested_list_schema:
description: This list has a list nested underneath!
type: array
items:
type: array
items:
type: string
double_nested_set_schema:
description: This set has a set nested underneath!
type: array
format: set
items:
type: array
format: set
items:
type: string
double_nested_map_schema:
description: This list has a map nested underneath!
type: array
items:
type: object
description: This is a double nested map of strings
additionalProperties:
type: string
triple_nested_map_schema:
description: This list has a set of maps nested underneath!
type: array
items:
type: array
format: set
items:
type: object
description: This is a triple nested map of objects
additionalProperties:
type: object
properties:
string_prop:
description: String inside a map!
type: string
bool_prop:
description: Bool inside a map!
type: boolean
setnested_schema:
description: This is a set with a nested object
type: array
Expand All @@ -77,3 +155,15 @@ components:
bool_prop:
description: Bool inside a set!
type: boolean
mapnested_schema:
description: This is a map with a nested object
type: object
additionalProperties:
type: object
properties:
string_prop:
description: String inside a map!
type: string
bool_prop:
description: Bool inside a map!
type: boolean
Loading