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

Support for Any Type schema #82

Open
pauly4it opened this issue Oct 21, 2023 · 5 comments
Open

Support for Any Type schema #82

pauly4it opened this issue Oct 21, 2023 · 5 comments
Labels
enhancement New feature or request

Comments

@pauly4it
Copy link

Our OpenAPI spec contains quite a few Any Type/arbitrary-type schemas.

Currently, the codegen tool skips a resource in the generator config because one of the child schemas is an Any Type, returning the following message:
time=2023-10-20T16:27:09.841-06:00 level=WARN msg="skipping resource schema mapping" resource=system oas_path=decision_mappings.allowed.expected oas_line_number=5019 err="no 'type' array or supported allOf, oneOf, anyOf constraint - attribute cannot be created"

Example:

systems.v1.AllowedMapping:
  properties:
    expected:
      $ref: '#/components/schemas/systems.v1.AllowedMapping.expected'
    negated:
      default: false
      description: when set to true, decision is Allowed when the mapped property IS NOT equal to the expected value
      type: boolean
    path:
      description: dot-separated decision property path
      type: string
  required:
    - path
systems.v1.AllowedMapping.expected: {}

In the above example from our spec, expected can by any type of value based on the user's custom configuration (e.g, true, 200, "allowed", {"allowed": true, "errors": null}, etc.).

@austinvalle
Copy link
Member

Hey there @pauly4it 👋🏻 ,

To provide some initial expectations, there are a couple dependencies that we need to resolve before this functionality can be added to codegen-openapi:

Once those are in-place, adding this functionality to codegen-openapi will be possible and we can consider this enhancement. I'll add this issue to our backlog to track 👍🏻

@austinvalle austinvalle added the enhancement New feature or request label Oct 23, 2023
@pauly4it
Copy link
Author

@austinvalle could we potentially treat an Any Type as a string?

I was thinking more about how a user may configure that expected attribute from my example in a TF HCL file, and it could be something like:

resource "system" "example" {
  # ... other system resource config params
  
          expected = <<EOF
{"allowed": true, "errors": null}
EOF
  
  # ... rest of system resource config
}

@austinvalle
Copy link
Member

Hmmm 🤔,

While it may be possible to represent this use-case of Any as a string, I'm not sure that'd be expected for all cases. I'm wondering if maybe in the future we could extend the overrides config block to allow explicitly setting the type.

data_sources:
  system:
    read:
      path: /system
      method: GET
    schema:
      attributes:
        overrides:
          expected:
            type: string

For what you described above, a string type would work, but you might even want to use the jsontypes.Normalized type, which is built on top of the string type: https://github.com/hashicorp/terraform-plugin-framework-jsontypes.

@pauly4it
Copy link
Author

Overrides of attribute type would definitely help solve the problem in these types of cases. Combined with #81, it could add more flexibility into the configuration.

@bflad
Copy link
Contributor

bflad commented Apr 25, 2024

Good news here is that the first part of this, terraform-plugin-framework support for dynamic types and attributes is available. The other code generation projects will need to be updated with that support then hopefully this can be supported.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants