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 properties with no type as an object #79

Closed
pauly4it opened this issue Oct 20, 2023 · 5 comments · Fixed by #80
Closed

Support properties with no type as an object #79

pauly4it opened this issue Oct 20, 2023 · 5 comments · Fixed by #80
Labels
enhancement New feature or request

Comments

@pauly4it
Copy link

I tried using the codegen tool on our OpenAPI v3 spec with just one resource to test it out, and I got the following error:

time=2023-10-19T17:00:55.405-06:00 level=WARN msg="skipping resource schema mapping" resource=user oas_line_number=8174 err="no 'type' array or supported allOf, oneOf, anyOf constraint - attribute cannot be created"

When I dug into our schema, it looks like our spec doesn't include the type field for most schema objects, though they are specified in the various properties values. For example:

"users.v1.UsersPutRequest": {
    "properties": {
        "enabled": {
            "type": "boolean"
        },
        "roles": {
            "items": {
                "type": "string"
            },
            "type": "array"
        }
    },
    "required": [
        "enabled"
    ]
},

I spoke with our engineering team, and they said that in JSON Schema the type defaults to “object” and OpenAPI inherits that. For context, we're using getkin/kin-openapi to create the OpenAPI v3 spec.

Just to checkt, I added type manually to the schema objects needed for the user resource, and then the tool worked without errors.

Is this a requirement of the codegen tool? Or can the behavior be adjusted to assume an object type if type is not explicitly defined?

Really appreciate the work put into this tool!

@austinvalle
Copy link
Member

Hey there @pauly4it 👋🏻 , thanks for opening the issue. Very interesting! We hadn't really considered the use-case of an empty type being considered an object 🤔.

... can the behavior be adjusted to assume an object type if type is not explicitly defined?

At first glance this sounds reasonable to me: if type is undefined, and properties exist, default to object. Our goal with this tool is to not stray far from the OpenAPI 3.0, 3.1, and JSON schema specifications, but there are going to be cases where that either doesn't make sense, or causes conflicts with existing tooling like getkin/kin-openapi.

I spoke with our engineering team, and they said that in JSON Schema the type defaults to “object” and OpenAPI inherits that.

I looked into the JSON schema spec, and while I can't find an explicit statement of type: object being the default... It seems to imply that properties will only be used to describe objects, which is good enough for me 👍🏻

@austinvalle austinvalle added the enhancement New feature or request label Oct 20, 2023
@austinvalle austinvalle changed the title Error "no 'type' array or supported allOf, oneOf, anyOf constraint - attribute cannot be created" Support properties with no type as an object Oct 20, 2023
@austinvalle
Copy link
Member

@pauly4it
If you'd like to test out a fix for this issue from the linked PR and you're using the Go toolchain for installing:

go install github.com/hashicorp/terraform-plugin-codegen-openapi/cmd/tfplugingen-openapi@8002d1668f3d0a95679f2bdb0089348a85d3120d

@pauly4it
Copy link
Author

That solved the issue. Thanks for the quick response!

@austinvalle
Copy link
Member

austinvalle commented Oct 23, 2023

This has been merged into main and can be installed via the Go toolchain for now. This will eventually be released with v0.2.0 (we're trying to batch the fixes and enhancements together 🙂)

go install github.com/hashicorp/terraform-plugin-codegen-openapi/cmd/tfplugingen-openapi@28389a734a7050940e5541d95baca3c5ba833a4d

Copy link

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 22, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
2 participants