Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: Make kind allowed values explicit on Swagger documentation for Attribute and Relationship kinds #5536

Open
bilalabbad opened this issue Jan 21, 2025 · 4 comments
Labels
group/backend Issue related to the backend (API Server, Git Agent) type/bug Something isn't working as expected type/newcomers Good for newcomers

Comments

@bilalabbad
Copy link
Contributor

Component

API Server / GraphQL

Infrahub version

1.1.4

Current Behavior

In the Swagger documentation, we see that kind is a string, but in reality, only certain values are allowed.
Image

Expected Behavior

Make kind type more narrow, for example:

kind*: Text | Number | TextArea etc...

Steps to Reproduce

  1. go to http://localhost:8000/api/docs
  2. see typing for Attribute and relationship schema

Additional Information

No response

@bilalabbad bilalabbad added type/bug Something isn't working as expected group/backend Issue related to the backend (API Server, Git Agent) type/newcomers Good for newcomers labels Jan 21, 2025
@ogenstad
Copy link
Contributor

In order to fix this we'd need to update attribute.kind here:
https://github.com/opsmill/infrahub/blob/infrahub-v1.1.4/backend/infrahub/core/schema/definitions/internal.py#L467-L473

So that it looks more like attribute.branch here:
https://github.com/opsmill/infrahub/blob/infrahub-v1.1.4/backend/infrahub/core/schema/definitions/internal.py#L560-L568

@bilalabbad, aside from the correctness of this could you please briefly explain in what way this would help you?

@bilalabbad
Copy link
Contributor Author

In the UI, types are generated based on OpenAPI definitions. Since the string type is too broad, we created a constant variable to specify all allowed values. Ideally this list should be defined and enforced by the backend to ensure consistency.

More broadly, types generated from swagger/openapi or graphql schemas act as a compatibility layer between the frontend and backend, to reduce type mismatches and chances of incompatibilities between the two.

@ogenstad
Copy link
Contributor

In the UI, types are generated based on OpenAPI definitions. Since the string type is too broad, we created a constant variable to specify all allowed values. Ideally this list should be defined and enforced by the backend to ensure consistency.

More broadly, types generated from swagger/openapi or graphql schemas act as a compatibility layer between the frontend and backend, to reduce type mismatches and chances of incompatibilities between the two.

Ok, didn't know that you'd started to do that. Is this based on a manual export, something that you generate every so often?

@bilalabbad
Copy link
Contributor Author

Ok, didn't know that you'd started to do that. Is this based on a manual export, something that you generate every so often?

For now yes, we are manually using a codegen tool for it.
In the future, we'll probably add a CI check for it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
group/backend Issue related to the backend (API Server, Git Agent) type/bug Something isn't working as expected type/newcomers Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants