Skip to content

Commit

Permalink
Merge pull request #1 from jacmarjorie/raw-message
Browse files Browse the repository at this point in the history
Resolve RawMessage as byte slice with optional reference
  • Loading branch information
gmlewis authored Nov 29, 2023
2 parents 6a4e3be + bed9bae commit 2190a11
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 14 deletions.
8 changes: 7 additions & 1 deletion fixtures/allow_additional_props.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
"type": "string",
"contentEncoding": "base64"
},
"RawMessage": {
"type": "string",
"contentEncoding": "base64"
},
"GrandfatherType": {
"properties": {
"family_name": {
Expand Down Expand Up @@ -203,7 +207,9 @@
"type": "array"
},
"anything": true,
"raw": true
"raw": {
"$ref": "#/$defs/RawMessage"
}
},
"type": "object",
"required": [
Expand Down
8 changes: 7 additions & 1 deletion fixtures/defaults_expanded_toplevel.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
"type": "string",
"contentEncoding": "base64"
},
"RawMessage": {
"type": "string",
"contentEncoding": "base64"
},
"GrandfatherType": {
"properties": {
"family_name": {
Expand Down Expand Up @@ -203,7 +207,9 @@
"type": "array"
},
"anything": true,
"raw": true
"raw": {
"$ref": "#/$defs/RawMessage"
}
},
"additionalProperties": false,
"type": "object",
Expand Down
8 changes: 7 additions & 1 deletion fixtures/ignore_type.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
"type": "string",
"contentEncoding": "base64"
},
"RawMessage": {
"type": "string",
"contentEncoding": "base64"
},
"GrandfatherType": {
"properties": {},
"additionalProperties": false,
Expand Down Expand Up @@ -197,7 +201,9 @@
"type": "array"
},
"anything": true,
"raw": true
"raw": {
"$ref": "#/$defs/RawMessage"
}
},
"additionalProperties": false,
"type": "object",
Expand Down
5 changes: 4 additions & 1 deletion fixtures/no_reference.json
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,10 @@
"type": "array"
},
"anything": true,
"raw": true
"raw": {
"type": "string",
"contentEncoding": "base64"
}
},
"additionalProperties": false,
"type": "object",
Expand Down
5 changes: 4 additions & 1 deletion fixtures/no_reference_anchor.json
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,10 @@
"type": "array"
},
"anything": true,
"raw": true
"raw": {
"type": "string",
"contentEncoding": "base64"
}
},
"additionalProperties": false,
"type": "object",
Expand Down
8 changes: 7 additions & 1 deletion fixtures/required_from_jsontags.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
"type": "string",
"contentEncoding": "base64"
},
"RawMessage": {
"type": "string",
"contentEncoding": "base64"
},
"GrandfatherType": {
"properties": {
"family_name": {
Expand Down Expand Up @@ -204,7 +208,9 @@
"type": "array"
},
"anything": true,
"raw": true
"raw": {
"$ref": "#/$defs/RawMessage"
}
},
"additionalProperties": false,
"type": "object",
Expand Down
8 changes: 7 additions & 1 deletion fixtures/test_user.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
"type": "string",
"contentEncoding": "base64"
},
"RawMessage": {
"type": "string",
"contentEncoding": "base64"
},
"GrandfatherType": {
"properties": {
"family_name": {
Expand Down Expand Up @@ -204,7 +208,9 @@
"type": "array"
},
"anything": true,
"raw": true
"raw": {
"$ref": "#/$defs/RawMessage"
}
},
"additionalProperties": false,
"type": "object",
Expand Down
8 changes: 7 additions & 1 deletion fixtures/test_user_assign_anchor.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
"type": "string",
"contentEncoding": "base64"
},
"RawMessage": {
"type": "string",
"contentEncoding": "base64"
},
"GrandfatherType": {
"$anchor": "GrandfatherType",
"properties": {
Expand Down Expand Up @@ -206,7 +210,9 @@
"type": "array"
},
"anything": true,
"raw": true
"raw": {
"$ref": "#/$defs/RawMessage"
}
},
"additionalProperties": false,
"type": "object",
Expand Down
6 changes: 0 additions & 6 deletions reflect.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,9 +288,6 @@ var (
// Byte slices will be encoded as base64
var byteSliceType = reflect.TypeOf([]byte(nil))

// Except for json.RawMessage
var rawMessageType = reflect.TypeOf(json.RawMessage{})

// Go code generated from protobuf enum types should fulfil this interface.
type protoEnum interface {
EnumDescriptor() ([]byte, []int)
Expand Down Expand Up @@ -445,9 +442,6 @@ func (r *Reflector) reflectSchemaExtend(definitions Definitions, t reflect.Type,
}

func (r *Reflector) reflectSliceOrArray(definitions Definitions, t reflect.Type, st *Schema) {
if t == rawMessageType {
return
}

r.addDefinition(definitions, t, st)

Expand Down

0 comments on commit 2190a11

Please sign in to comment.