Skip to content

Map support in generators#11

Closed
clementdenis wants to merge 9 commits intomasterfrom
map_support_in_generators
Closed

Map support in generators#11
clementdenis wants to merge 9 commits intomasterfrom
map_support_in_generators

Conversation

@clementdenis
Copy link

No description provided.

@codecov-io
Copy link

codecov-io commented Jul 31, 2018

Codecov Report

Merging #11 into master will increase coverage by 0.23%.
The diff coverage is 93.04%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master      #11      +/-   ##
============================================
+ Coverage     80.02%   80.26%   +0.23%     
- Complexity     1681     1711      +30     
============================================
  Files           156      158       +2     
  Lines          5597     5684      +87     
  Branches        731      748      +17     
============================================
+ Hits           4479     4562      +83     
- Misses          839      840       +1     
- Partials        279      282       +3
Impacted Files Coverage Δ Complexity Δ
...pi/server/spi/handlers/EndpointsMethodHandler.java 100% <ø> (ø) 10 <0> (ø) ⬇️
...com/google/api/server/spi/config/model/Schema.java 100% <ø> (ø) 2 <0> (ø) ⬇️
...e/api/server/spi/discovery/DiscoveryGenerator.java 88.93% <100%> (+0.54%) 64 <0> (+2) ⬆️
...pi/server/spi/ServletInitializationParameters.java 96% <100%> (+0.25%) 18 <0> (+1) ⬆️
...va/com/google/api/server/spi/EndpointsServlet.java 89.83% <100%> (+0.17%) 18 <1> (+1) ⬆️
...rver/spi/response/ServletResponseResultWriter.java 94.73% <100%> (+2.73%) 17 <3> (ø) ⬇️
.../server/spi/response/RestResponseResultWriter.java 100% <100%> (ø) 5 <1> (ø) ⬇️
.../com/google/api/server/spi/config/model/Types.java 90% <77.77%> (-2.69%) 32 <3> (+3)
...i/server/spi/config/model/AuthScopeRepository.java 88.88% <88.88%> (ø) 6 <6> (?)
...oogle/api/server/spi/swagger/SwaggerGenerator.java 77.91% <90%> (+0.26%) 59 <4> (+2) ⬆️
... and 5 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c2a26bd...7cb5035. Read the comment docs.

Copy link

@alarribeau alarribeau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's neat :)
I have just made an optional comment.

FieldType.BOOLEAN,
FieldType.INT8, FieldType.INT16, FieldType.INT32, FieldType.INT64,
FieldType.FLOAT, FieldType.DOUBLE,
FieldType.DATE, FieldType.DATE_TIME

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it could be cleaner to move this logic into the FieldType enum by adding a new field :

private final boolean serializeableIntoString; // or scalarValue?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually prefer the current solution: the list of types usable as Map keys is somehow arbitrary, and might evolve over time. It is not intrinsic to the FieldTypes, on the contrary of the other existing fields.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

* object (see {@link com.google.api.server.spi.config.model.SchemaRepository#MAP_SCHEMA}).
*
* To enable one of these enum flags, you can either:
* - Set system property "endpoints.mapSchema." + systemPropertyName to any value except a falsy one

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

systemPropertyName() ?
MapSchemaFlag.systemPropertyName() ?
(It wasn't clear for me at first read what was this systemPropertyName since I read the description before the code)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The is indeed a confusion here, as we have constructor param and field with same name but different values. Renamed constructor param to systemPropertySuffix, and improved documentation.

FieldType keyFieldType = FieldType.fromType(Types.getTypeParameter(type, 0));
boolean supportedKeyType = SUPPORTED_MAP_KEY_TYPES.contains(keyFieldType);
if (!supportedKeyType) {
String message = "Map field type '" + type + "' has a key type not serializable to String";

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would make this slightly more compact too :

boolean supportedKeyType = SUPPORTED_MAP_KEY_TYPES.contains(keyFieldType);
if (!supportedKeyType) {

=>

if (!keyFieldType.isSerializableToString()) {

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See previous comment

@clementdenis clementdenis force-pushed the map_support_in_generators branch from 14c1d58 to ee0b460 Compare August 10, 2018 14:09
@clementdenis clementdenis changed the base branch from master to scopes_in_discovery August 10, 2018 14:11
@clementdenis clementdenis changed the base branch from scopes_in_discovery to master August 10, 2018 14:11
Clément Denis added 6 commits August 27, 2018 20:13
- Two unit tests disabled (to reenable)
- Missing flag to enable new map handling
- Changed description handling in SwaggerGenerator to follow spec
- Enable new behaviour with a property / env flag
- Still use JsonMap for unsupported keys (not String) or value types (arrays)
- Add a flag to warn about unsupported Map type parameters
- Reenable disabled tests (now passing)
- Test old and new behaviour in unit tests
- Support additional map key types (confirmed to work at runtime)
- Add new flag to enable support for array-like value types
- ALlow to use warn flag without actually generating new schema for Maps
- Add Javadoc on flags for maps
- Additional test cases for Map types
- Improve Map schema-related flags with dedicated MapSchemaFlag class
- Default to Map schema using "additionalProperties", with flag for legacy mode
- Fail by default when encountering non-String Map keys, with flag to ignore
- Improve unit tests
- Handle subclasses of Map with concrete key and value (exclude others)
- Exclude raw Map type
- Better support nested Maps
@clementdenis clementdenis force-pushed the map_support_in_generators branch from ee0b460 to 1e573c8 Compare August 27, 2018 18:15
@clementdenis
Copy link
Author

Fixed Swagger tests after merging cloudendpoints#155.

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

Successfully merging this pull request may close these issues.

4 participants