Open alexz0000 opened 6 years ago
it would fail yes, but since the spec is upgraded you're effectively working with a new version of the server api, in that case the client does need to regenerate. But at least you have defined behavior instead of undefined behavior.
@casualjim But users/customers may not be want to upgrade their SDK, If we force they do this, they may not be happy. And also, since we have lots of polymorphic APIs, some of them are upgraded very frequently, If they get failed frequently, I don't think they are happy. Actually, I prefer to ignore the new added sub-models. If the users/customers want to use the new added models, they can decide if upgrade to latest version of SDK
One solution can also be to implement a default implementation of the polymorphic base type and return an instance of that. At least you'd get basic functionality.
the files to change are these: https://github.com/go-swagger/go-swagger/blob/master/generator/templates/schema.gotmpl https://github.com/go-swagger/go-swagger/blob/master/generator/templates/schemabody.gotmpl
Thanks, I will try it.
When I tried to update the schema template, I got below error message. Looks I cannot override the templates except I update the code of go-swagger. If there any ways to let it effect?
Could not complete template processing in directory "../go-swagger-local/templates": Could not add template: Cannot overwrite protected template schema
generate, modify then reuse model with x-go-type
I think the solution cannot get the purpose. And we're gonna to force our customers to upgrade their SDK version if there are new sub-models.
Problem statement
I can see the generated code for polymorphic model in client. And the unmarshal func will validate the discriminator. For example
My question is what if the server side add new sub-models? what if the user doesn't upgrade the client SDK? Looks the their old SDK will get panic.
I didn't find a solution, so create this request. Could you give me a solution? Thanks.
Swagger specification
Swagger 2.0
Steps to reproduce
Environment
swagger version: 0.15.0 go version: 1.10.3 OS: Mac OS