- 
                Notifications
    You must be signed in to change notification settings 
- Fork 53
fix/enhance support for "additionalProperties" #86
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| getInventory(parameters: {} & CommonRequestOptions): Promise < ResponseWithBody < 200, { | ||
| [key: string]: number | ||
| } >> { | ||
| getInventory(parameters: {} & CommonRequestOptions): Promise < ResponseWithBody < 200, object >> { | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this will be fixed/enhanced in a separate PR dealing with pre-defined response definitions...
| export type test_add_props_12 = { | ||
|  | ||
| [key: string]: some_def; | ||
| }; | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the types test_add_props_* have been validated according to the description about how to handle the different cases for additionalProperties ...
| "test_add_props_11": { "type": "object", "additionalProperties": { "type": "object", "properties": { "nested_prop": { "type": "string" } } } }, | ||
| "test_add_props_12": { "type": "object", "additionalProperties": { "$ref": "#/definitions/some_def" } } | ||
| } | ||
| } | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these are the new test cases
| minItems: 0, | ||
| title: "any", | ||
| properties: {} | ||
| }); | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know about this one? is there a better way to specify the any type?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think maybe makeAnyTypeSpec(swaggerType) would work?
        
          
                templates/type.mustache
              
                Outdated
          
        
      | %><%#isObject%>{ | ||
| <%#properties%> '<%name%>'<%^isRequired%>?<%/isRequired%>: <%>type%>;<%/properties%>}<%/isObject%><%! | ||
| <%#properties%> '<%name%>'<%^isRequired%>?<%/isRequired%>: <%>type%>;<%/properties%><%#hasAdditionalProperties%> | ||
| [key: string]: <%#additionalPropertiesType%><%>type%><%/additionalPropertiesType%>;<%/hasAdditionalProperties%>}<%/isObject%><%! | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use the newly introduced hasAdditionalProperties and additionalPropertiesType fields in the template
about `additionalProperties` usage in `swagger` see for example [this post](https://support.reprezen.com/support/solutions/articles/6000162892-support-for-additionalproperties-in-swagger-2-0-schemas) * `additionalProperties` can be defined for any `object` type * they are adding unnamed and potentially typed properties to a type * the pitfall is that not defining an `additionalProperties` field on an `object` type needs to be treated as defining it as `true` (see URL given above) * this means that many object types will add a `[key: string]: any;` definition which is required according to the swagger spec * there is no dedicated `dictionary` object or class => `dictionary` has been removed Note, that this is a breaking change, since the `type` template need to adjust to the newly introduced properties `hasAdditionalProperties` and `additionalPropertiesType`!
| minItems: 0, | ||
| title: "any", | ||
| properties: {} | ||
| }); | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think maybe makeAnyTypeSpec(swaggerType) would work?
| any opinions on this PR? | 
| @Kosta-Github I didn't merge it yet since i was wondering if you would fix the following. If you don't have a lot of time to do this for now I'm ok to merge it :D | 
| 
 honestly, I will not have the time right now, I just came back from vacation and need to clean out several tasks accumulated so far... | 
| 
 Thats fine, in that case i'll merge it. Thanks a bunch for your contributions! | 
| Published as  | 
| @Kosta-Github specifically said this was a breaking change. This should have been published as  | 
| @Kosta-Github can you provide a migration guide? Or updates to the README? | 
| } | ||
| if ( | ||
| swaggerType.additionalProperties === undefined || | ||
| swaggerType.additionalProperties === true | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If additionalProperties is undefined, wouldn't it make more sense to default to false?
| 
 | 
| @andy-viv re-reading the comments in the link above, I might come to the conclusion that for the  | 
| 
 @Kosta-Github yes, that criticism was actually directed toward @Markionium. Also, I figured out why this broke for my project... We had custom templates for  | 
| @Kosta-Github  I still think we should just treat  Barring that, I would be okay with only supporting the case where  | 
| Hey @andy-viv, @Kosta-Github , I sincerely apologise. I definitely messed this one up, sorry for the inconvenience. I read it was a breaking change when merging the PR. But somehow forgot about it when releasing it a couple days later. I think it might be worth investing some time in a better process for this. Just to be clear from our side on what to do. You mitigated the problem? @mtennoe went ahead and published it as 2.0.0, so you can consume that. We considered un-publishing the version that should have been published as 2.0.0. But that would also break others that took a direct dependency on that version. Again sorry for the inconvenience, Mark | 
| Hey Mark, Sorry for the late response. No problem. For now I have had to pin to 1.10.4 because we will need to update our custom templates to match the new requirements. I plan on opening a PR to do what I said in this comment: 
 Until then, we're going to leave it pinned to 1.10.4. Thank you @mtennoe and @Markionium for the work on this project! | 
as mentioned mtennoe#86 (comment) treat additionalProperties === undefined the same way as additionalProperties === false

about
additionalPropertiesusage inswaggersee for example this postadditionalPropertiescan be defined for anyobjecttypeadditionalPropertiesfield on anobjecttype needs to be treated as defining it astrue(see URL given above)[key: string]: any;definition which is required according to the swagger specdictionaryobject or class =>dictionaryhas been removedNote, that this is a breaking change, since the
typetemplate need to adjust to the newly introduced propertieshasAdditionalPropertiesandadditionalPropertiesType!