You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: DESIGN.md
+73Lines changed: 73 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -83,6 +83,79 @@ The response body schema found will be deep merged with the query/path `paramete
83
83
- Names are strictly compared, so `id` and `user_id` would be two separate attributes in a schema.
84
84
- Arrays and Objects will have their child attributes merged, so `example_object.string_field` and `example_object.bool_field` will be merged into the same `SingleNestedAttribute` schema.
85
85
86
+
#### Collection Data Sources
87
+
88
+
If the response body schema for a data source is of type `array`, the schema in `items` will be mapped to a set collection attribute (`SetNested` or `Set`) at the root of the mapped data source. The name of the attribute will be the same as the data source name from the generator config. All [mapping rules](#oas-types-to-provider-attributes) will be followed for nested attributes.
89
+
90
+
##### Generator Config
91
+
```yaml
92
+
provider:
93
+
name: petstore
94
+
95
+
data_sources:
96
+
pets:
97
+
read:
98
+
path: /pet/findByStatus
99
+
method: GET
100
+
```
101
+
102
+
##### OpenAPI Spec
103
+
```jsonc
104
+
{
105
+
// ... Rest of OAS
106
+
"/pet/findByStatus": {
107
+
"get": {
108
+
"responses": {
109
+
"200": {
110
+
"description": "successful operation",
111
+
"content": {
112
+
"application/json": {
113
+
"schema": {
114
+
"type": "array",
115
+
"items": {
116
+
"$ref": "#/components/schemas/Pet"
117
+
}
118
+
}
119
+
}
120
+
}
121
+
}
122
+
}
123
+
}
124
+
}
125
+
}
126
+
```
127
+
128
+
##### Provider Code Spec output
129
+
```jsonc
130
+
{
131
+
"datasources": [
132
+
{
133
+
"name": "pets",
134
+
"schema": {
135
+
"attributes": [
136
+
{
137
+
"name": "pets",
138
+
"set_nested": {
139
+
"computed_optional_required": "computed",
140
+
"nested_object": {
141
+
"attributes": [
142
+
// ... mapping of #/components/schemas/Pet
143
+
]
144
+
}
145
+
}
146
+
}
147
+
]
148
+
}
149
+
}
150
+
],
151
+
"provider": {
152
+
"name": "petstore"
153
+
}
154
+
}
155
+
```
156
+
157
+
158
+
86
159
### OAS Types to Provider Attributes
87
160
88
161
For a given OAS [`type`](https://spec.openapis.org/oas/v3.1.0#data-types) and `format` combination, the following rules will be applied for mapping to the provider code specification. Not all Provider attributes are represented natively with OAS, those types are noted below in [Unsupported Attributes](#unsupported-attributes).
0 commit comments