I am trying to generate a python client library with openApI3 . For this I have created a openapi.yml file, where I defined my url and schema with request and response.
I am trying with openApI-generator that I found here https://github.com/OpenAPITools/openapi-generator command: openapitools/openapi-generator-cli
This generator, producing a set of directory and files based on schema defined in yml file.
When I test it's auto generated fils, I am getting error
I am adding here my yml file and auto-generated test_file with error below:`
This is my yml file
opanapi.yml
openapi: 3.0.1
info:
title: Config Service
version: '2.0'
description: Project and system config microservice
contact: {}
servers:
- url: ''
paths:
/config/v1/datasources:
get:
tags:
- config/v1
responses:
'200':
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/Datasource'
description: Success
'404':
description: Not Found
operationId: get_datasources
summary: GET endpoint
description: return list of sources
components:
schemas:
Datasource:
description: ''
type: object
properties:
type:
type: string
minLength: 1
properties:
type: object
properties:
_id:
type: object
properties:
type:
type: string
minLength: 1
This is the auto-generated test file for models.
test_datasource.py
# coding: utf-8
"""
Config Service
Project and system config microservice # noqa: E501
The version of the OpenAPI document: 2.0
Generated by: https://openapi-generator.tech
"""
from __future__ import absolute_import
import unittest
import datetime
import tech.client.config
from tech.client.config.models.datasource import Datasource # noqa: E501
from tech.client.config.rest import ApiException
class TestDatasource(unittest.TestCase):
"""Datasource unit test stubs"""
def setUp(self):
pass
def tearDown(self):
pass
def make_instance(self, include_optional):
"""Test Datasource
include_option is a boolean, when False only required
params are included, when True both required and
optional params are included """
# model = tech.client.config.models.datasource.Datasource() # noqa: E501
if include_optional :
return Datasource(
type = '0',
properties = tech.client.config.models.datasource_properties.Datasource_properties(
_id = tech.client.config.models.datasource_properties__id.Datasource_properties__id(
type = '0', )
else :
return Datasource(
)
def testDatasource(self):
"""Test Datasource"""
inst_req_only = self.make_instance(include_optional=False)
inst_req_and_optional = self.make_instance(include_optional=True)
if __name__ == '__main__':
unittest.main()
When I am test the above file , I am getting the below error.**
**Error:**
File "test_datasource.py", line 76, in testDatasource
inst_req_and_optional = self.make_instance(include_optional=True)
File "test/test_datasource.py", line 41, in make_instance
_id = tech.client.config.models.datasource_properties__id.Datasource_properties__id(
AttributeError: module 'tech.client.config.models' has no attribute 'datasource_properties__id'
Note: In models directory datasource_properties__id is not auto-generated.
I searched a lot regarding this, I a not sure why I am getting this issue. Does opeanAPI 3 not support nested-schema/nested objects ?
Any help/lead would be really appreciable. Thanks