[BUG][Python-Flask] Primitive type bytearray deserialization missing in util.py.
Created by: dannmartens
Bug Report Checklist
-
Have you provided a full/minimal spec to reproduce the issue? Yes. -
Have you validated the input using an OpenAPI validator ([example] (https://apidevtools.org/swagger-parser/online/))? -
What's the version of OpenAPI Generator used? HEAD of current master branch. -
Have you search for related issues/PRs? Yes. -
What's the actual output vs expected output?
File "/home/ubuntu/dvm-rest-api/dvmapi/util.py", line 111, in deserialize_model
setattr(instance, attr, _deserialize(value, attr_type))
File "/home/ubuntu/dvm-rest-api/dvmapi/util.py", line 32, in _deserialize
return deserialize_model(data, klass)
File "/home/ubuntu/dvm-rest-api/dvmapi/util.py", line 103, in deserialize_model
if not instance.openapi_types:
AttributeError: 'bytearray' object has no attribute 'openapi_types'
Description
When an object property is specified as type:string, format:byte, no code is generated to support deserialization.
openapi-generator version
HEAD of current master branch -> 4.0.0 - no regression.
OpenAPI declaration file content or url
openapi: 3.0.1
info:
title: Flask Generator Issue
description: This API provides an example of the problem with util.py generated but the Flask generator, for deserializing supported primitive types.
version: 0.1.0
servers:
- url: http://localhost:8080
paths:
/examples:
get:
summary: Example GET.
responses:
200:
description: OK
content:
application/json:
schema:
$ref: '#/components/schemas/Example'
components:
schemas:
Example:
required:
- data
properties:
data:
type: string
description: Base64 representation of data.
format: byte
Steps to reproduce
Inspect util.py, there is no mention of the primitive type 'bytearray'. Inspect models/example.py, the data property is typed 'bytearray'.
self.openapi_types = {
'data': bytearray
}
Suggest a fix
Update template to generate util.py to include 'bytearray' at
if klass in six.integer_types or klass in (float, str, bool):
return _deserialize_primitive(data, klass)