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

Allow opting out of mixin flattening in OpenAPI conversion #2145

Closed
Xtansia opened this issue Feb 16, 2024 · 1 comment
Closed

Allow opting out of mixin flattening in OpenAPI conversion #2145

Xtansia opened this issue Feb 16, 2024 · 1 comment
Labels
archived This issue is archived, meaning it may be re-opened in the future given new information or action. feature-request A feature should be added or improved.

Comments

@Xtansia
Copy link
Contributor

Xtansia commented Feb 16, 2024

Currently a Smithy spec always has its mixins flattened and erased when being converted to OpenAPI/JsonSchema. This makes it difficult to represent for example fields that are global to all or a subset of operations and should be generated as a ResponseBase class etc. As such I propose to allow opting out of mixin flattening and have them instead generated as an allOf schema in OpenAPI.

Example Smithy:

$version: "2"
namespace repro

@aws.protocols#restJson1
service MyService {
    version: "2021-11-23",
    operations: [
        Get,
    ]
}

@readonly
@http(method: "GET", uri: "/")
operation Get {
    output: Output
}

structure Output with [OutputBase] {
    message: String
}

@mixin
structure OutputBase {
    success: Boolean
}

Currently generates OpenAPI:

{
    "openapi": "3.0.2",
    "info": {
        "title": "MyService",
        "version": "2021-11-23"
    },
    "paths": {
        "/": {
            "get": {
                "operationId": "Get",
                "responses": {
                    "200": {
                        "description": "Get 200 response",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/GetResponseContent"
                                }
                            }
                        }
                    }
                }
            }
        }
    },
    "components": {
        "schemas": {
            "GetResponseContent": {
                "type": "object",
                "properties": {
                    "success": {
                        "type": "boolean"
                    },
                    "message": {
                        "type": "string"
                    }
                }
            }
        }
    }
}

What I'd like the output to be:

{
    "openapi": "3.0.2",
    "info": {
        "title": "MyService",
        "version": "2021-11-23"
    },
    "paths": {
        "/": {
            "get": {
                "operationId": "Get",
                "responses": {
                    "200": {
                        "description": "Get 200 response",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/GetResponseContent"
                                }
                            }
                        }
                    }
                }
            }
        }
    },
    "components": {
        "schemas": {
            "GetResponseContent": {
                "allOf": [
                    {
                        "$ref": "#/components/schemas/OutputBase"
                    },
                    {
                        "type": "object",
                        "properties": {
                            "message": {
                                "type": "string"
                            }
                        }
                    }
                ]
            },
            "OutputBase": {
                "type": "object",
                "properties": {
                    "success": {
                        "type": "boolean"
                    }
                }
            }
        }
    }
}
@haydenbaker
Copy link
Contributor

Archiving request as not planned. We will re-open this ticket if we find additional users who need this custom behavior.

@haydenbaker haydenbaker closed this as not planned Won't fix, can't repro, duplicate, stale Jul 16, 2024
@haydenbaker haydenbaker added the archived This issue is archived, meaning it may be re-opened in the future given new information or action. label Jul 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
archived This issue is archived, meaning it may be re-opened in the future given new information or action. feature-request A feature should be added or improved.
Projects
None yet
Development

No branches or pull requests

3 participants