-
-
Notifications
You must be signed in to change notification settings - Fork 7.4k
[python-client] Add model default values #1776
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
Merged
wing328
merged 11 commits into
OpenAPITools:master
from
spacether:issue_1748_add_model_default_values
Jan 9, 2019
Merged
Changes from 7 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
6b515d9
Adds two models to the v2.0 spec, uses examples as defaults in python…
spacether 49d8a9b
Adds array default and type_holder_default and type_holder_example tests
spacether 30ee536
Re-generated python security client with ./bin/security/python-petsto…
spacether 5b663a1
Changes comment text, rebased master
spacether dff27c9
Updates client + server samples
spacether 67d74e0
Adds missing samples updates
spacether b77e186
Changes python client to look for true or false with booleans in toDe…
spacether c05dc6b
Changes boolean casting to use Boolean.valueOf
spacether fa024b4
Adds deserialization fix for python tests
spacether 45fa46d
Changes Mock to namedtuple in python deserialization tests
spacether 4261d64
Actually remove unittest.mock
spacether File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
samples/client/petstore-security-test/python/.openapi-generator/VERSION
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| 3.3.4-SNAPSHOT | ||
| 4.0.0-SNAPSHOT |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
samples/client/petstore/csharp/OpenAPIClient/docs/TypeHolderDefault.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| # Org.OpenAPITools.Model.TypeHolderDefault | ||
| ## Properties | ||
|
|
||
| Name | Type | Description | Notes | ||
| ------------ | ------------- | ------------- | ------------- | ||
| **StringItem** | **string** | | [default to "what"] | ||
| **NumberItem** | **decimal?** | | | ||
| **IntegerItem** | **int?** | | | ||
| **BoolItem** | **bool?** | | [default to true] | ||
| **ArrayItem** | **List<int?>** | | | ||
|
|
||
| [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) | ||
|
|
13 changes: 13 additions & 0 deletions
13
samples/client/petstore/csharp/OpenAPIClient/docs/TypeHolderExample.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| # Org.OpenAPITools.Model.TypeHolderExample | ||
| ## Properties | ||
|
|
||
| Name | Type | Description | Notes | ||
| ------------ | ------------- | ------------- | ------------- | ||
| **StringItem** | **string** | | | ||
| **NumberItem** | **decimal?** | | | ||
| **IntegerItem** | **int?** | | | ||
| **BoolItem** | **bool?** | | | ||
| **ArrayItem** | **List<int?>** | | | ||
|
|
||
| [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) | ||
|
|
112 changes: 112 additions & 0 deletions
112
...t/petstore/csharp/OpenAPIClient/src/Org.OpenAPITools.Test/Model/TypeHolderDefaultTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,112 @@ | ||
| /* | ||
| * 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: \" \\ | ||
| * | ||
| * OpenAPI spec version: 1.0.0 | ||
| * | ||
| * Generated by: https://github.com/openapitools/openapi-generator.git | ||
| */ | ||
|
|
||
|
|
||
| using NUnit.Framework; | ||
|
|
||
| using System; | ||
| using System.Linq; | ||
| using System.IO; | ||
| using System.Collections.Generic; | ||
| using Org.OpenAPITools.Api; | ||
| using Org.OpenAPITools.Model; | ||
| using Org.OpenAPITools.Client; | ||
| using System.Reflection; | ||
| using Newtonsoft.Json; | ||
|
|
||
| namespace Org.OpenAPITools.Test | ||
| { | ||
| /// <summary> | ||
| /// Class for testing TypeHolderDefault | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// This file is automatically generated by OpenAPI Generator (https://openapi-generator.tech). | ||
| /// Please update the test case below to test the model. | ||
| /// </remarks> | ||
| [TestFixture] | ||
| public class TypeHolderDefaultTests | ||
| { | ||
| // TODO uncomment below to declare an instance variable for TypeHolderDefault | ||
| //private TypeHolderDefault instance; | ||
|
|
||
| /// <summary> | ||
| /// Setup before each test | ||
| /// </summary> | ||
| [SetUp] | ||
| public void Init() | ||
| { | ||
| // TODO uncomment below to create an instance of TypeHolderDefault | ||
| //instance = new TypeHolderDefault(); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Clean up after each test | ||
| /// </summary> | ||
| [TearDown] | ||
| public void Cleanup() | ||
| { | ||
|
|
||
| } | ||
|
|
||
| /// <summary> | ||
| /// Test an instance of TypeHolderDefault | ||
| /// </summary> | ||
| [Test] | ||
| public void TypeHolderDefaultInstanceTest() | ||
| { | ||
| // TODO uncomment below to test "IsInstanceOfType" TypeHolderDefault | ||
| //Assert.IsInstanceOfType<TypeHolderDefault> (instance, "variable 'instance' is a TypeHolderDefault"); | ||
| } | ||
|
|
||
|
|
||
| /// <summary> | ||
| /// Test the property 'StringItem' | ||
| /// </summary> | ||
| [Test] | ||
| public void StringItemTest() | ||
| { | ||
| // TODO unit test for the property 'StringItem' | ||
| } | ||
| /// <summary> | ||
| /// Test the property 'NumberItem' | ||
| /// </summary> | ||
| [Test] | ||
| public void NumberItemTest() | ||
| { | ||
| // TODO unit test for the property 'NumberItem' | ||
| } | ||
| /// <summary> | ||
| /// Test the property 'IntegerItem' | ||
| /// </summary> | ||
| [Test] | ||
| public void IntegerItemTest() | ||
| { | ||
| // TODO unit test for the property 'IntegerItem' | ||
| } | ||
| /// <summary> | ||
| /// Test the property 'BoolItem' | ||
| /// </summary> | ||
| [Test] | ||
| public void BoolItemTest() | ||
| { | ||
| // TODO unit test for the property 'BoolItem' | ||
| } | ||
| /// <summary> | ||
| /// Test the property 'ArrayItem' | ||
| /// </summary> | ||
| [Test] | ||
| public void ArrayItemTest() | ||
| { | ||
| // TODO unit test for the property 'ArrayItem' | ||
| } | ||
|
|
||
| } | ||
|
|
||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about using
Boolean.valueOfinstead of usingequalsIgnoreCase?Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Boolean.valueOf(string) will always return True or False,
so Boolean.valueOf("5") would return False.
When I pass in "5" as a boolean the code should return null. Code updated use equalsIgnoreCase to check for "true" and "false" otherwise return null.
I'd prefer matching on true false strings rather than truthy "0" "5" "1.234" "[1,2,3]" because truthiness differs from language.
equalsIgnoreCase lets us only look for a string match to true or false ignoring case.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If someone puts down 5 as the example value and assume it will be treated false in boolean, it's the user's issue (not something we need to handle) and I don't think it should return null (clearly there's a value defined)
We've seen spec using 1 or 0 to as example value for boolean type (not entirely correct as they should be using "true" or "false" instead) but still we want to able to handle these cases correctly as some languages (e.g. Perl) treat 1 as true.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Coercing it to a boolean gives the user back some boolean which is usefull. I will change it to Boolean.valueOf. This behavior may surprise python users though because they will be using a python client with java casting of string truthiness.
"1" -> True in Python, false in Java
"0" -> True in Python, false in Java