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

JDT Serialization with Only Additional Properties fails #2171

Closed
fabianeichinger opened this issue Nov 21, 2022 · 1 comment
Closed

JDT Serialization with Only Additional Properties fails #2171

fabianeichinger opened this issue Nov 21, 2022 · 1 comment

Comments

@fabianeichinger
Copy link

My JTD schemas contain records that have either only additionalAttributes: true (i.e. no fixed internal structure) or optionalAttributes with additionalAttributes: true (where we want type safety for some attributes and pass others through). Serialization always fails in the first case and also in the second if no optionalAttributes are set in the data. This issue is very likely related to #2001 but that one only mentions optionalProperties.

What version of Ajv are you using? Does the issue happen if you use the latest version?
8.11.2

Ajv options object

not dependent on options

JSON Schema

schema1

{ 
  "properties": {},
  "additionalProperties": true
}

Same result with optionalProperties instead of properties (schema2)

schema3

{
  "optionalProperties": {
    "prop_not_in_data": { "type": "string" }
  },
  "additionalProperties": true
}

Sample data

{
  "a":1,
  "b":2
}

Your code

var serialize1 = ajv.compileSerializer(schema1)
var serialize2 = ajv.compileSerializer(schema2)
var serialize3 = ajv.compileSerializer(schema3)

console.log("serialize1", serialize1(data))
console.log("serialize2", serialize2(data))
console.log("serialize3", serialize3(data))

https://runkit.com/fabianeichinger/637bc56844c590000adfb57d

Serialization output

serialize1: {"a":1"b":2}
serialize2: {"a":1"b":2}
serialize3: {,"a":1,"b":2}

What results did you expect?
Valid JSON

Are you going to resolve the issue?
Would love to test if this is resolved by #2028. Can't get the build to work on my machine, getting some TS errors on npm install.

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

Successfully merging a pull request may close this issue.

3 participants
@epoberezkin @fabianeichinger and others