Skip to content

Commit

Permalink
chore: support application/vnd.api+json content type
Browse files Browse the repository at this point in the history
  • Loading branch information
mateusz-drzymala-form3 committed Jan 8, 2025
1 parent 5e36fe5 commit 71daa77
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
11 changes: 6 additions & 5 deletions internal/app/pactproxy/interaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ import (
)

const (
mediaTypeJSON = "application/json"
mediaTypeText = "text/plain"
mediaTypeXml = "application/xml"
mediaTypeCsv = "text/csv"
mediaTypeJSON = "application/json"
mediaTypeJSONAPI = "application/vnd.api+json"
mediaTypeText = "text/plain"
mediaTypeXml = "application/xml"
mediaTypeCsv = "text/csv"
)

type pathMatcher interface {
Expand Down Expand Up @@ -116,7 +117,7 @@ func LoadInteraction(data []byte, alias string) (*Interaction, error) {
}

switch mediaType {
case mediaTypeJSON:
case mediaTypeJSON, mediaTypeJSONAPI:
interaction.addJSONConstraintsFromPact("$.body", propertiesWithMatchingRule, requestBody)
return interaction, nil
case mediaTypeText, mediaTypeCsv, mediaTypeXml:
Expand Down
9 changes: 5 additions & 4 deletions internal/app/pactproxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,11 @@ type Config struct {
}

var supportedMediaTypes = map[string]func([]byte, *url.URL) (requestDocument, error){
mediaTypeJSON: ParseJSONRequest,
mediaTypeText: ParsePlainTextRequest,
mediaTypeCsv: ParsePlainTextRequest,
mediaTypeXml: ParsePlainTextRequest,
mediaTypeJSON: ParseJSONRequest,
mediaTypeJSONAPI: ParseJSONRequest,
mediaTypeText: ParsePlainTextRequest,
mediaTypeCsv: ParsePlainTextRequest,
mediaTypeXml: ParsePlainTextRequest,
}

type api struct {
Expand Down
6 changes: 6 additions & 0 deletions internal/app/proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,12 @@ func createNonJsonTestCases() map[string]nonJsonTestCase {
respContentType: "application/json",
respBody: `{"status":"ok"}`,
},
"application/vnd.api+json request and application/json response": {
reqContentType: "application/vnd.api+json",
reqBody: `{"firstname":"foo"}`,
respContentType: "application/json",
respBody: `{"status":"ok"}`,
},
}
}

Expand Down

0 comments on commit 71daa77

Please sign in to comment.