Skip to content

Bug: Headers that use refs aren't included in output #624

Closed
@rustyconover

Description

@rustyconover

Hi there,

If a header is specified as a reference (i.e. as part of a response) the header isn't included in the produced objects.

An example response schema is:

"responses": {
    "200": {
    "content": {
        "application/json": {
        "schema": {
            "$ref": "#/components/schemas/Result_Ok_GetGroups"
        }
        }
    },
    "description": "OK",
    "headers": {
        "ETag": {
        "$ref": "#/components/headers/ETag"
        }
    }
}

That would produce a type with:

200: {
    headers: {};
    content: {
        "application/json": components["schemas"]["Result_Ok_GetGroups"];
    };
}

The reason is because of the check:

https://github.com/drwpow/openapi-typescript/blob/e2fb371f053c90af4d958c48b7b6b04271b257ca/src/transform/headers.ts#L17

v.schema won't be defined because the header is included by reference.

Properly handling the headers relies on resolving the reference (even if it is external).

Since the majority of my PR has not been merged that deals with resolving references, I'm going to just link to the commit that fixes this problem:

rustyconover@9c21864

Please feel free to cherry pick.

Rusty

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