Skip to content

feat: Generate a parameter for the Accept header when a response code has multiple content types#1464

Open
oliverkahrmann-basf wants to merge 2 commits intoogen-go:mainfrom
oliverkahrmann-basf:feature/parameters_for_accept_header
Open

feat: Generate a parameter for the Accept header when a response code has multiple content types#1464
oliverkahrmann-basf wants to merge 2 commits intoogen-go:mainfrom
oliverkahrmann-basf:feature/parameters_for_accept_header

Conversation

@oliverkahrmann-basf
Copy link
Copy Markdown

@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
Copy Markdown
Author

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

@ernado
Copy link
Copy Markdown
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.

Oliver Kahrmann added 2 commits April 7, 2026 11:01
Generate a parameter for the Accept header when a response code has multiple content types.
@oliverkahrmann-basf oliverkahrmann-basf force-pushed the feature/parameters_for_accept_header branch from f68d6a8 to 53c74f6 Compare April 7, 2026 09:02
@oliverkahrmann-basf
Copy link
Copy Markdown
Author

@ernado I've gone ahead and squashed+split the changes into the two commits discussed above, and rebased the changes to latest master.
I had to adjust the code slightly to account for the new raw message option, and changed a few imports and comments to make the linter happy. Otherwise, no logic changes since the first iteration.

Ready for review

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