hashicorp / hashicorp/terraform-plugin-codegen-openapi

datasource incorrect type when name overlaps with parameters

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

Description

### Config Files
In my OpenAPI Spec, I have the following OpenAPI spec:

```yaml
openapi: 3.0.1
info:
title: Swagger Petstore
description: ""
version: 1.0.6
servers:
- url: https://petstore.swagger.io/v2
paths:
/pet/{id}:
get:
summary: Find pet by ID
parameters:
- name: id
in: path
required: true
schema:
type: string
responses:
"200":
description: successful operation
content:
application/json:
schema:
$ref: '#/components/schemas/Pet'
application/xml:
schema:
$ref: '#/components/schemas/Pet'
post:
summary: Updates a pet in the store with form data
parameters:
- name: id
in: path
description: ID of pet that needs to be updated
required: true
schema:
type: string
requestBody:
content:
application/x-www-form-urlencoded:
schema:
type: object
properties:
name:
type: string
description: Updated name of the pet
status:
type: string
description: Updated status of the pet
responses:
"200":
description: successful operation
content:
application/json:
schema:
$ref: '#/components/schemas/Pet'
application/xml:
schema:
$ref: '#/components/schemas/Pet'
components:
schemas:
Pet:
required:
- name
type: object
properties:
id:
type: integer
format: int64
name:
type: string
example: doggie
xml:
name: Pet
```

Coupled with the generator config:
```yaml
provider:
name: pet
resources:
pet:
read:
path: /pet/{id}
method: GET
create:
path: /pet/{id}
method: POST
data_sources:
pet:
read:
path: /pet/{id}
method: GET
```

### Result Files

When the code spec is generated (`tfplugingen-openapi generate --config ./generator_config.yml --output ./provider_code_spec.json ./swagger.yaml`) we see the attribute id within the datasource defined as a string, but the resource defined as the desired int:

##### Data Source
```json
{
"name": "id",
"string": {
"computed_optional_required": "required"
}
}
```

##### Resource
```json
{
"name": "id",
"int64": {
"computed_optional_required": "computed"
}
},
```

### Expected Outcome
If I change the path in the OpenAPI spec, to `/pet/{petId}` the datasource returns the `id` as the desired int64 type. The expected outcome is with `/pet/{id}` on the data source, the code gen should return an `int64` type for data source, as it does in the resource.

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.