Skip to content

Conversation

@oliverkahrmann-basf
Copy link

@oliverkahrmann-basf oliverkahrmann-basf commented May 23, 2025

This should fix #938

Adds an automatic parameter for the HTTP Accept header, if at least one of the response codes for an operation defines more than one content type.
This can then be used to decide the actual response:

func (h *ApiHandler) GetFileContent(ctx context.Context, params api.GetFileContentParams) (api.GetFileRes, error) {
	if params.Accept.MatchesContentType(api.MediaTypeApplicationVndOpenxmlformatsOfficedocumentSpreadsheetmlSheet) {
		// XLSX download
		// […] read/generate file
		buf *bytes.Buffer

		return &api.GetFileContentOKApplicationVndOpenxmlformatsOfficedocumentSpreadsheetmlSheet{
			Data: buf,
		}, nil

	} else {
		// JSON download
		// […] read/generate data

		res := &api.FileContent{
			// […] content
		}

		return res, nil

	}
}

@oliverkahrmann-basf oliverkahrmann-basf force-pushed the feature/parameters_for_accept_header branch from d4da482 to b466a2f Compare May 26, 2025 15:39
@oliverkahrmann-basf oliverkahrmann-basf marked this pull request as ready for review May 27, 2025 14:06
@oliverkahrmann-basf oliverkahrmann-basf force-pushed the feature/parameters_for_accept_header branch from 8f39c09 to 8450a86 Compare May 27, 2025 14:08
@oliverkahrmann-basf oliverkahrmann-basf changed the title Generate a parameter for the Accept header when a response code has multiple content types feat: Generate a parameter for the Accept header when a response code has multiple content types May 27, 2025
@oliverkahrmann-basf
Copy link
Author

This PR is ready for review.
Shall I squash the commits into one feat: … commit?

@ernado
Copy link
Member

ernado commented Sep 18, 2025

Shall I squash the commits into one feat: … commit?

One for code (feat: implement ...), one for generated files chore(gen): update.

Very sorry for late responce. Now iterations will be much quicker.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature Request: Automatically Generate Accept Headers

2 participants