DoclerLabs / api-client-generator

API client generator is a console application capable of generating an API client based on OpenAPI(Swagger) specification.
MIT License
31 stars 19 forks source link

Free-form response object support #51

Closed Yarre closed 3 years ago

Yarre commented 3 years ago

Hi, I added support for free-form objects in response as allowed in OpenApi specification.

vsouz4 commented 3 years ago

"If the dictionary values can be of any type (aka free-form object), use additionalProperties: true:"

I'm wondering whether we need to worry with https://swagger.io/docs/specification/data-models/dictionaries/ "additionalProperties" or not... 🤔

I mean, apparently a free form object is only when additionalProperties is true or {} (which is the default), so perhaps we need to check and fail when additionalProperties is set saying we don't support it yet? Maybe we shouldn't try to generate a free form object when it's not a free form object per say...

Yarre commented 3 years ago

@vsouz4 it is an interesting question regarding additionalProperties. It is true that you wrote and additionally openapi specification says that:

additionalProperties - Value can be boolean or object. Inline or referenced schema MUST be of a Schema Object and not a standard JSON Schema. Consistent with JSON Schema, additionalProperties defaults to true.

So basically we should check if additionalProperties is not set to false. Or maybe if it contains any constraint that it also should not be a free-form object. Or output a warning that generator doesn't support constraints from the additionalProperties section.

vsouz4 commented 3 years ago

@vsouz4 it is an interesting question regarding additionalProperties. It is true that you wrote and additionally openapi specification says that:

additionalProperties - Value can be boolean or object. Inline or referenced schema MUST be of a Schema Object and not a standard JSON Schema. Consistent with JSON Schema, additionalProperties defaults to true.

So basically we should check if additionalProperties is not set to false. Or maybe if it contains any constraint that it also should not be a free-form object. Or output a warning that generator doesn't support constraints from the additionalProperties section.

hmm, if you extend the Field::isFreeFormObject() checking not only empty properties but also additionalProperties, it could work indeed... and we won't introduce any non backwards compatible change, otherwise somebody might be using already additionalProperties in their specs and we'd start failing the client generation 😄

wdyt @JasonBenett, @pelyib ?

Yarre commented 3 years ago

@vsouz4 I added check for additionalProperties=false