Skip to content

typescript-fetch-client-generator2: Explicit header definition #64

@lee-ethan

Description

@lee-ethan
responses:
  302:
    description: Redirect Response
    headers:
      Location:
        required: true
        schema:
          type: string

generates

headers: {
	location: response.headers.get('Location') ?? undefined,
	setCookie: response.headers.get('Set-Cookie') ?? undefined,
},

Which will error as the generated response interface is:

status: 302
body?: undefined
headers: {
	'location': string
	'setCookie': string
}

Should this always be optional on the client side regardless of the required param?

status: 302
body?: undefined
headers: {
	'location'?: string
	'setCookie'?: string
}

In which case we can do

packages/typescript-fetch-client2/templates/frag/apiResponseTypes.hbs

line 61: {{{stringLiteral name}}}?: {{{nativeType}}} (optional)

That may be better than stating that the headers.get will always be defined

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions