forked from loafle/openapi-generator-original
python-experimental adds DecimalSchema (#11282)
* Fixes test * Adds decimal examples to the pythonExp generator * Adds isDecimal to CodegenModel, updates python-exp samples * Fixes decimal types in ObjectModelWIthDecimalProperties and DecimalPayload * Updates tests * Decimal feature added to python-exp docs * Samples and docs regenerated
This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
|
||||
|
||||
import unittest
|
||||
from decimal import Decimal
|
||||
|
||||
import petstore_api
|
||||
from petstore_api.schemas import (
|
||||
@@ -24,9 +25,9 @@ from petstore_api.schemas import (
|
||||
NoneSchema,
|
||||
DateSchema,
|
||||
DateTimeSchema,
|
||||
DecimalSchema,
|
||||
ComposedSchema,
|
||||
frozendict,
|
||||
Decimal,
|
||||
NoneClass,
|
||||
BoolClass
|
||||
)
|
||||
@@ -268,6 +269,31 @@ class TestAnyTypeSchema(unittest.TestCase):
|
||||
assert isinstance(m, str)
|
||||
assert m == '2020-01-01T00:00:00'
|
||||
|
||||
def testDecimalSchema(self):
|
||||
class Model(ComposedSchema):
|
||||
|
||||
@classmethod
|
||||
@property
|
||||
def _composed_schemas(cls):
|
||||
return {
|
||||
'allOf': [
|
||||
AnyTypeSchema,
|
||||
DecimalSchema,
|
||||
],
|
||||
'oneOf': [
|
||||
],
|
||||
'anyOf': [
|
||||
],
|
||||
}
|
||||
|
||||
m = Model('12.34')
|
||||
assert isinstance(m, Model)
|
||||
assert isinstance(m, AnyTypeSchema)
|
||||
assert isinstance(m, DecimalSchema)
|
||||
assert isinstance(m, str)
|
||||
assert m == '12.34'
|
||||
assert m.as_decimal == Decimal('12.34')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
# coding: utf-8
|
||||
|
||||
"""
|
||||
OpenAPI Petstore
|
||||
|
||||
This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ # noqa: E501
|
||||
|
||||
The version of the OpenAPI document: 1.0.0
|
||||
Generated by: https://openapi-generator.tech
|
||||
"""
|
||||
|
||||
import decimal
|
||||
import unittest
|
||||
|
||||
import petstore_api
|
||||
from petstore_api.schemas import DecimalSchema
|
||||
from petstore_api.model.decimal_payload import DecimalPayload
|
||||
|
||||
|
||||
class TestDecimalPayload(unittest.TestCase):
|
||||
"""DecimalPayload unit test stubs"""
|
||||
|
||||
def test_DecimalPayload(self):
|
||||
"""Test DecimalPayload"""
|
||||
|
||||
m = DecimalPayload('12')
|
||||
assert isinstance(m, DecimalPayload)
|
||||
assert isinstance(m, DecimalSchema)
|
||||
assert isinstance(m, str)
|
||||
assert m == '12'
|
||||
assert m.as_decimal == decimal.Decimal('12')
|
||||
|
||||
m = DecimalPayload('12.34')
|
||||
assert isinstance(m, DecimalPayload)
|
||||
assert isinstance(m, DecimalSchema)
|
||||
assert isinstance(m, str)
|
||||
assert m == '12.34'
|
||||
assert m.as_decimal == decimal.Decimal('12.34')
|
||||
|
||||
# passing in a Decimal does not work
|
||||
with self.assertRaises(petstore_api.ApiTypeError):
|
||||
DecimalPayload(decimal.Decimal('12.34'))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
@@ -0,0 +1,34 @@
|
||||
# coding: utf-8
|
||||
|
||||
"""
|
||||
OpenAPI Petstore
|
||||
|
||||
This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ # noqa: E501
|
||||
|
||||
The version of the OpenAPI document: 1.0.0
|
||||
Generated by: https://openapi-generator.tech
|
||||
"""
|
||||
import decimal
|
||||
import unittest
|
||||
|
||||
from petstore_api.model.money import Money
|
||||
|
||||
|
||||
class TestMoney(unittest.TestCase):
|
||||
"""Money unit test stubs"""
|
||||
|
||||
def test_Money(self):
|
||||
"""Test Money"""
|
||||
price = Money(
|
||||
currency='usd',
|
||||
amount='10.99'
|
||||
)
|
||||
self.assertEqual(price.amount.as_decimal, decimal.Decimal('10.99'))
|
||||
self.assertEqual(
|
||||
price,
|
||||
dict(currency='usd', amount='10.99')
|
||||
)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user