Skip to content

Commit

Permalink
fix: repeated treat as optional
Browse files Browse the repository at this point in the history
  • Loading branch information
uanid committed Sep 18, 2023
1 parent c096734 commit 1695fd3
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 36 deletions.
2 changes: 1 addition & 1 deletion pkg/modules/1_middleend_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func buildFromMessage(pluginOptions *proto.PluginOptions, message pgs.Message, m
}}
}

if !field.InRealOneOf() && !field.HasOptionalKeyword() {
if !field.InRealOneOf() && !field.HasOptionalKeyword() && !field.Type().IsRepeated() {
// If field is not a member of oneOf
schema.Required = append(schema.Required, propName)
}
Expand Down
17 changes: 2 additions & 15 deletions testdata/cases/jsonschema-array/test.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,7 @@
"$ref": "#/$defs/.tests.Values.enum"
}
},
"type": "object",
"required": [
"val1",
"val2",
"optioned1",
"optioned2",
"optioned3",
"message",
"enum"
]
"type": "object"
},
".tests.Values.val1": {
"items": {
Expand Down Expand Up @@ -115,11 +106,7 @@
"$ref": "#/$defs/.tests.MyMessage.val2"
}
},
"type": "object",
"required": [
"val1",
"val2"
]
"type": "object"
},
".tests.MyMessage.val1": {
"items": {
Expand Down
6 changes: 1 addition & 5 deletions testdata/cases/jsonschema-nullable/test.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,7 @@
"$ref": "#/$defs/.tests.MyMessage.val2"
}
},
"type": "object",
"required": [
"val1",
"val2"
]
"type": "object"
},
".tests.MyMessage.val1": {
"items": {
Expand Down
6 changes: 2 additions & 4 deletions testdata/cases/jsonschema-object/test.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@
"additionalProperties": {},
"type": "object",
"required": [
"val1",
"val2"
"val1"
],
"title": "MyMessage"
},
Expand All @@ -63,8 +62,7 @@
"maxProperties": 10,
"minProperties": 0,
"required": [
"val1",
"val2"
"val1"
],
"title": "MyMessage"
},
Expand Down
11 changes: 0 additions & 11 deletions testdata/cases/plugin-output-yaml/test.schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ $defs:
$ref: '#/$defs/.tests.MyMessage.val1'
val2:
$ref: '#/$defs/.tests.MyMessage.val2'
required:
- val1
- val2
type: object
.tests.MyMessage.val1:
items:
Expand Down Expand Up @@ -41,14 +38,6 @@ $defs:
oneOf:
- type: "null"
- $ref: '#/$defs/.tests.Values.val2'
required:
- val1
- val2
- optioned1
- optioned2
- optioned3
- message
- enum
type: object
.tests.Values.enum:
items:
Expand Down

0 comments on commit 1695fd3

Please sign in to comment.