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
In my OpenAPI Spec, I have the following OpenAPI spec:
openapi: 3.0.1info:
title: Swagger Petstoredescription: ""version: 1.0.6servers:
- url: https://petstore.swagger.io/v2paths:
/pet/{id}:
get:
summary: Find pet by IDparameters:
- name: idin: pathrequired: trueschema:
type: stringresponses:
"200":
description: successful operationcontent:
application/json:
schema:
$ref: '#/components/schemas/Pet'application/xml:
schema:
$ref: '#/components/schemas/Pet'post:
summary: Updates a pet in the store with form dataparameters:
- name: idin: pathdescription: ID of pet that needs to be updatedrequired: trueschema:
type: stringrequestBody:
content:
application/x-www-form-urlencoded:
schema:
type: objectproperties:
name:
type: stringdescription: Updated name of the petstatus:
type: stringdescription: Updated status of the petresponses:
"200":
description: successful operationcontent:
application/json:
schema:
$ref: '#/components/schemas/Pet'application/xml:
schema:
$ref: '#/components/schemas/Pet'components:
schemas:
Pet:
required:
- nametype: objectproperties:
id:
type: integerformat: int64name:
type: stringexample: doggiexml:
name: Pet
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:
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.
The text was updated successfully, but these errors were encountered:
danquack
changed the title
datasource - Incorrect type when name overlap with parameters
datasource Incorrect type when name overlap with parameters
Nov 17, 2023
danquack
changed the title
datasource Incorrect type when name overlap with parameters
datasource incorrect type when name overlap with parameters
Nov 17, 2023
danquack
changed the title
datasource incorrect type when name overlap with parameters
datasource incorrect type when name overlaps with parameters
Nov 17, 2023
Hey there @danquack, thanks for filing an issue and sorry you're running into trouble here.
I think the problem described here is coming from the design decisions we made around priority of conflicting attributes.
In resources, the POST request body takes priority over query/path parameters
In data sources, the query/path parameters take priority over the GET response body
One of the reasons we made that decision is to determine computability (required, optional, computed), but in the case of conflicting types (string vs int64), rather than throwing an error, we just take the higher priority attribute.
Maybe a potential improvement we can make here is allowing the ability to configure this priority somehow.
An ugly workaround that could be used in the immediate is to rename/ignore the path parameter in your example, however you will lose the computability determination that comes from the parameter:
Config Files
In my OpenAPI Spec, I have the following OpenAPI spec:
Coupled with the generator config:
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
Resource
Expected Outcome
If I change the path in the OpenAPI spec, to
/pet/{petId}
the datasource returns theid
as the desired int64 type. The expected outcome is with/pet/{id}
on the data source, the code gen should return anint64
type for data source, as it does in the resource.The text was updated successfully, but these errors were encountered: