Skip to content

openapi2conv: invalid transformation for type: file #979

@reversearrow

Description

@reversearrow

OpenAPI Version 2 (Swagger) supports a primitive type type: file to denote the response as being a file. Data Types documentation.

However, OpenAPI 3.0 does not have a "file" type; instead, file is defined as type: strings with the format: binary (reference).

When using openapi2conv to convert from OAS v2 to v3, the converter does not correctly convert type: "file" to type: "string" with format: "binary". This results in a OpenAPI V3 validation error.

For example, a v2 path with a GET operation:

 "/foo": {
    "get": {
        "description": "foo",
        "operationId": "foo",
        "produces": [
            "application/pdf",
            "application/json"
        ],
        "responses": {
            "200": {
                "description": "returns all information about foo",
                "schema": {
                    "type": "file"
                }
            },
            "400": {
                "description": "bad request"
            },
            "500": {
                "description": "internal server error"
            }
        },
        "summary": "get foo document"
    }
}

Gets converted to V3 document with type: file as type: file instead of the type: "string" with format: "binary"

 "/foo": {
    "get": {
        "description": "foo",
        "operationId": "foo",
        "responses": {
            "200": {
                "content": {
                    "application/json": {
                        "schema": {
                            "type": "file"
                        }
                    },
                    "application/pdf": {
                        "schema": {
                            "type": "file"
                        }
                    }
                },
                "description": "returns all information about foo"
            },
            "400": {
                "description": "bad request"
            },
            "500": {
                "description": "internal server error"
            }
        },
        "summary": "get foo document"
    }
}

The type: "file" should be converted to type: "string" and format: "binary".

 "/foo": {
    "get": {
        "description": "foo",
        "operationId": "foo",
        "responses": {
            "200": {
                "content": {
                    "application/json": {
                        "schema": {
                            "format": "binary",
                            "type": "string"
                        }
                    },
                    "application/pdf": {
                        "schema": {
                            "format": "binary",
                            "type": "string"
                        }
                    }
                },
                "description": "returns all information about foo"
            },
            "400": {
                "description": "bad request"
            },
            "500": {
                "description": "internal server error"
            }
        },
        "summary": "get foo document"
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions