Open
Description
Bug Report Checklist
There is missing import declaration in Javascript client when I got model called File
.
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator (example)?
- Have you tested with the latest master to confirm the issue still exists?
- Have you searched for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
modelNamePrefix
option solves this issue but I still consider it as bug. I guess generator thinks that File is reserved Javascript word and doesn't add it to import list.
Generated model(file is pretty big, so I've left only important parts) looks like:
import ApiClient from '../ApiClient';
import CallRecording from './CallRecording';
/**
* The Greeting model module.
* @module model/Greeting
* @version 1.0
*/
class Greeting {
/**
* Constructs a <code>Greeting</code> from a plain JavaScript object, optionally creating a new instance.
* Copies all relevant properties from <code>data</code> to <code>obj</code> if supplied or a new instance if not.
* @param {Object} data The plain JavaScript object bearing properties of interest.
* @param {module:model/Greeting} obj Optional instance to populate.
* @return {module:model/Greeting} The populated <code>Greeting</code> instance.
*/
static constructFromObject(data, obj) {
if (data) {
obj = obj || new Greeting();
if (data.hasOwnProperty('id')) {
obj['id'] = ApiClient.convertToType(data['id'], 'Number');
}
if (data.hasOwnProperty('type')) {
obj['type'] = ApiClient.convertToType(data['type'], 'String');
}
if (data.hasOwnProperty('text')) {
obj['text'] = ApiClient.convertToType(data['text'], 'String');
}
if (data.hasOwnProperty('call_recording')) {
obj['call_recording'] = CallRecording.constructFromObject(data['call_recording']);
}
if (data.hasOwnProperty('file')) {
obj['file'] = File.constructFromObject(data['file']);
}
if (data.hasOwnProperty('locale')) {
obj['locale'] = ApiClient.convertToType(data['locale'], 'String');
}
if (data.hasOwnProperty('created_at')) {
obj['created_at'] = ApiClient.convertToType(data['created_at'], 'Date');
}
if (data.hasOwnProperty('modified_at')) {
obj['modified_at'] = ApiClient.convertToType(data['modified_at'], 'Date');
}
}
return obj;
}
}
And the error is:
[Log] TypeError: File.constructFromObject is not a function. (In 'File.constructFromObject(data['file'])', 'File.constructFromObject' is undefined) — Greeting.js:81 (main.js, line 13027)
openapi-generator version
node_modules/.bin/openapi-generator-cli version
5.1.1
OpenAPI declaration file content or url
components:
schemas:
CallRecording:
type: object
required:
- id
- from_number
- to_number
- stage
- status
- duration
- direction
- recording_url
- created_at
properties:
id:
type: integer
format: int32
minimum: 1
readOnly: true
from_number:
type: string
maxLength: 20
readOnly: true
example: '+15552223214'
to_number:
type: string
maxLength: 20
readOnly: true
example: '+15558675310'
stage:
type: string
maxLength: 100
nullable: true
readOnly: true
example: recording
status:
type: string
maxLength: 100
nullable: true
readOnly: true
example: completed
duration:
type: integer
format: int32
minimum: 1
nullable: true
readOnly: true
example: 125
direction:
type: string
maxLength: 100
nullable: true
readOnly: true
example: inbound
recording_url:
description: Link for html src property.
type: string
format: url
readOnly: true
nullable: true
example: 'https://api.saas.example/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Recordings/REXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
created_at:
description: Created date in ISO format
type: string
format: date-time
readOnly: true
File:
type: object
required:
- id
- url
- checksum
- size
- extension
- client_filename
- client_media_type
- is_system
- created_at
properties:
id:
description: File public ID
type: string
maxLength: 250
readOnly: true
example: '570edfb8-00df-4e96-a675-37cbd4215f61'
url:
description: Link for html src property.
type: string
format: url
readOnly: true
nullable: true
example: 'https://api.example.com/uploads/570edfb8-00df-4e96-a675-37cbd4215f61.mp3'
checksum:
description: Hash of the file content
type: string
maxLength: 250
readOnly: true
example: 'ef74f6673903fac54244160da3a7dc8607c1f4f2'
size:
description: The file size in bytes.
type: integer
format: int64
minimum: 1
readOnly: true
example: 233013
extension:
description: File extension
type: string
maxLength: 10
readOnly: true
example: mp3
client_filename:
description: The filename sent by the client or null if none was provided.
type: string
maxLength: 250
readOnly: true
nullable: true
example: 'greeting.mp3'
client_media_type:
description: The media type sent by the client or null if none was provided.
type: string
maxLength: 100
readOnly: true
nullable: true
example: 'audio/mpeg'
is_system:
description: Whether it's system file
type: boolean
readOnly: true
nullable: true
created_at:
description: Created date in ISO format
type: string
format: date-time
readOnly: true
Greeting:
type: object
required:
- id
- type
- text
- call_recording
- file
- locale
- created_at
- modified_at
properties:
id:
type: integer
format: int32
minimum: 1
readOnly: true
type:
description: Greeting type.
type: string
enum:
- text_to_speech
- call_recording
- file_upload
readOnly: true
default: text_to_speech
text:
description: Text-To-Speech text.
type: string
maxLength: 160
nullable: true
example: Please leave us a message detailing your past experience and suitability for the position
call_recording:
$ref: '#/components/schemas/CallRecording'
nullable: true
file:
$ref: '#/components/schemas/File'
nullable: true
locale:
description: ISO locale
type: string
maxLength: 5
nullable: true
example: en-AU
created_at:
description: Created date in ISO format
type: string
format: date-time
readOnly: true
modified_at:
description: Last modified date in ISO format
type: string
format: date-time
readOnly: true
nullable: true
Generation Details
{
"$schema": "node_modules/@openapitools/openapi-generator-cli/config.schema.json",
"spaces": 2,
"generator-cli": {
"version": "5.1.1",
"generators": {
"v3.0": {
"generatorName": "javascript",
"input-spec": "#{cwd}/schema/spec_definition.yml",
"output": "#{cwd}/out/api-client",
"additionalProperties": {
"usePromises": true
},
"global-property": {
"apiTests": false,
"modelTests": false,
"apiDocs": false,
"modelDocs": false
}
}
}
}
}
Steps to reproduce
Related issues/PRs
#9521 seems related