OpenAPI data types are all named "data" #28
Description
I'm trying to use swagger-codegen to generate a Python client from my django-rest-swagger schema (django-rest-swagger==2.0.7, djangorestframework==3.5.3).
I am getting a lot of models named Data*, and no client models related to my actual API models.
Here's an example OpenAPI path:
"paths" : {
"/accounts/{id}/" : {
"put" : {
"tags" : [ "accounts" ],
"summary" : "The accounts for all Users.",
"description" : "The accounts for all Users.",
"operationId" : "accounts_update",
"consumes" : [ "application/json" ],
"parameters" : [ {
"name" : "id",
"in" : "path",
"description" : "",
"required" : true,
"type" : "string"
}, {
"in" : "body",
"name" : "data",
"required" : false,
"schema" : {
"type" : "object",
"required" : [ "account_number"],
"properties" : {
"account_number" : {
"type" : "string",
"description" : ""
},
...
}
}
} ],
"responses" : {
"200" : {
"description" : ""
}
}
},
...
Note the "in": "body", "name": "data" in the generated swagger JSON.
The model generated by swagger-codegen has the correct fields, but incorrect name:
class Data1(object):
"""
NOTE: This class is auto generated by the swagger code generator program.
Do not edit the class manually.
"""
def __init__(self, account_number=None, ...):
"""
Data1 - a model defined in Swagger
:param dict swaggerTypes: The key is attribute name
and the value is attribute type.
:param dict attributeMap: The key is attribute name
and the value is json key in definition.
"""
self.swagger_types = {
'account_number': 'str',
...
}
...
Per the swagger-codegen client, it's expected that the "name" field here should actually describe the resource.
@marcgibbons over at django-rest-swagger pointed out in the original issue (marcgibbons/django-rest-swagger#595) that the name field is hardcoded to data
here: https://github.com/core-api/python-openapi-codec/blob/master/openapi_codec/encode.py#L167. Seems like it should either be the Serializer name, or the Serializer.Meta.model. (Configurable would be better; should be simple to delegate to an overridable function which gets passed the Serializer and returns the resource name.).
Thoughts on whether this sounds like the right approach, and where best to put this logic if it's acceptable?