Dealing with additionalProperties #2829
Unanswered
rupinder10
asked this question in
Q&A
Replies: 2 comments 1 reply
-
I did see that additionalProperties are supported in go-swagger. And they seem to be in the generated code too. But for some reason they can't be parsed ? And there are no details in the error message |
Beta Was this translation helpful? Give feedback.
0 replies
-
You are not sending schemas. it appears to me that you are trying to have some form of inheritance going? |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have swagger file with the following definition:
"Components": { "type": "object", "properties": { "schemas": { "description": "An object to hold reusable schema objects", "type": "object", "additionalProperties": { "$ref": "#/definitions/Schema" } }
And input to unmarshal is
{ "schemas": { "OrderHeader": { "type": "GatewaySchema", "schema": "Test1" }, "OrderLine": { "type": "GatewaySchema", "schema": "Test2" }, "order_POST_bodyParameters": { "type": "GatewaySchema", "schema": "Test3" }, "order_POST_response": { "type": "GatewaySchema", "schema": "Test4" } } }
The following piece of code throws an error:
json: cannot unmarshal object into Go struct field Components.schemas of type models.Schema
buf, err := ioutil.ReadFile("order.json") reader := bytes.NewReader(buf) if err == nil { dec := json.NewDecoder(reader) dec.UseNumber() // preserve number formats obj := &models.Components{} err := dec.Decode(obj)
I have read up everything and seems like additionalProperties are supported in go-swagger code generation. Obviously, there is something I am missing regarding this.
The swagger file used to generate the code and the project with the generate code and the client code to test is attached.
ServiceManagementBody.zip
wmapis.zip
Beta Was this translation helpful? Give feedback.
All reactions