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

Open
Xtansia opened this issue Feb 16, 2024 · 0 comments
Open

Allow opting out of mixin flattening in OpenAPI conversion #2145

Xtansia opened this issue Feb 16, 2024 · 0 comments
Labels
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"
                    }
                }
            }
        }
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request A feature should be added or improved.
Projects
None yet
Development

No branches or pull requests

2 participants