Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ScheduleTypeLimit: Default None is not carried out to openapi Json #29

Closed
MingboPeng opened this issue Jan 30, 2020 · 6 comments
Closed

Comments

@MingboPeng
Copy link
Member

@chriswmackey @mostaphaRoudsari
This Default = None has been left out when translating to Json file, which causes .Net side a problem when loading the sample ScheduleTypeLimit json file from this repo. Its upperlimit has been set to null, but its value type is float in python (double in C#).

This is an issue that double cannot be null in C#. However, I could make this a Nullable double for upper and lower limit, only if it defaults to null in Json .

I do find the float type parameter with default value can be translated to Json, see radiant_fraction in people load as an example. I am not sure what causes this Default = None not been translated.

Do you have any clue how to fix this?

lower_limit: float = Field(
default=None,
description='Lower limit for the schedule type is entered.'
)
upper_limit: float = Field(
default=None,
description='Upper limit for the schedule type is entered.'
)

image

radiant_fraction: float = Field(
0.3,
ge=0,
le=1,
description='The radiant fraction of sensible heat released by people. The default'
'value is 0.30.'

@mostaphaRoudsari
Copy link
Member

default=None is how Pydantic defines an optional input. It is regardless of the real type of the object. See here: https://pydantic-docs.helpmanual.io/usage/schema/#field-customisation

I'm not sure what is the best approach for this. Does it mean that we should always have a default value for numeric fields?

@chriswmackey
Copy link
Member

Having a value of None is needed for certain uses of ScheduleTypeLimit that don't actually have an upper or lower limit. For example, temperature has a lower limit of -273 K but there's no upper limit. So I guess this is a case where a Nullable double is actually the right data type.

@MingboPeng
Copy link
Member Author

Can we make it +infinity for this case? so that pydantic can export this value to json.

@mostaphaRoudsari
Copy link
Member

@MingboPeng, do I understand correctly that your issue is that when the value is set to None the 'default' key is not exported to the schema JSON file? In that case we have to see how to get that exported from Pydantic instead of changing the default values from None.

@chriswmackey
Copy link
Member

@MingboPeng and @mostaphaRoudsari ,

I just explained here how you can tell from the OpenAPI specification if a property has a default of None:
#30 (comment)
Let us know if this logic is good enough for you to use, @MingboPeng .

@chriswmackey
Copy link
Member

I am going to close out this issue given that the discussion about this mostly happened over here and we now have a solution to this issue over there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants