MCPcopy Index your code
hub / github.com/oapi-codegen/oapi-codegen / buildUnmarshalCase

Function buildUnmarshalCase

pkg/codegen/template_helpers.go:270–276  ·  view source on GitHub ↗

buildUnmarshalCase builds an unmarshaling case clause for different content-types:

(typeDefinition ResponseTypeDefinition, caseAction string, contentType string)

Source from the content-addressed store, hash-verified

268
269// buildUnmarshalCase builds an unmarshaling case clause for different content-types:
270func buildUnmarshalCase(typeDefinition ResponseTypeDefinition, caseAction string, contentType string) (caseKey string, caseClause string) {
271 caseKey = fmt.Sprintf("%s.%s.%s", prefixLeastSpecific, contentType, typeDefinition.ResponseName)
272 caseClauseKey := getConditionOfResponseName("rsp.StatusCode", typeDefinition.ResponseName)
273 contentTypeLiteral := StringToGoString(contentType)
274 caseClause = fmt.Sprintf("case strings.Contains(rsp.Header.Get(\"%s\"), %s) && %s:\n%s\n", "Content-Type", contentTypeLiteral, caseClauseKey, caseAction)
275 return caseKey, caseClause
276}
277
278func buildUnmarshalCaseStrict(typeDefinition ResponseTypeDefinition, caseAction string, contentType string) (caseKey string, caseClause string) {
279 caseKey = fmt.Sprintf("%s.%s.%s", prefixLeastSpecific, contentType, typeDefinition.ResponseName)

Callers 1

genResponseUnmarshalFunction · 0.85

Calls 2

StringToGoStringFunction · 0.85

Tested by

no test coverage detected