question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support for additional properties

See original GitHub issue

It is sometimes the case that I want to parse an object with a few concrete properties and a bunch of additional properties.

OpenAPI 3’s Responses Object is an example for this. It has the fixed default default plus additional fields for various http statuses.

so this could look like:

{
  "default": {...},
  "200": {...},
  "400": {...},
  "404": {...}
}

And it would be great to be able to parse this into something like:

@Serializable
data class Responses(val default: Response, statuses: Map<String, Response>)

Jackson has the @JsonAnySetter annotation which can be used to implement this.

OpenAPI/JSON Schema support specifying object schemas that have both properties and additionalProperties.

Currently I think the only solution would be a hand-written KSerializer for Responses.

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:4
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
pschichtelcommented, Jul 4, 2022

I guess “require” is a strong word here. Technically it is obviously not required since there is at least two alternative approaches.

However it would be great to have a dedicated feature for that, especially since this requires duplicating field names into the transformation which can easily go out of sync with the model.

An annotation @AdditionalFields or @UnknownFields on a Map<*, *> field that then automatically collects all fields that are not consumed by other fields would be what comes to my mind.

0reactions
sandwwraithcommented, Jul 4, 2022

Yes, it still requires one, but given that JsonTransformingSerializer is much easier to implement, I’m not sure that this feature needs special support

Read more comments on GitHub >

github_iconTop Results From Across the Web

Schema in a response allows additional properties
The schema you have defined allows additional properties, either intentionally or unintentionally. In JSON, by default, any object can also accept additional ...
Read more >
Additional Properties - JSON Schema Editor
The value of "patternProperties" MUST be an object. Each property name of this object SHOULD be a valid regular expression, according to the...
Read more >
[BUG] Version 4 no longer supports additionalProperties ...
additionalProperties - Value can be boolean or object. Inline or referenced schema MUST be of a Schema Object and not a standard JSON...
Read more >
AdditionalProperties
The AdditionalProperties element identifies additional properties for use in GetItem, UpdateItem, CreateItem, FindItem, or FindFolder ...
Read more >
Usage
See 'openapi-generator-cli help <command>' for more information on a ... command for a go client, use the --additional-properties option.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found