@workos/oagen-emitters 0.6.4 → 0.6.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/plugin.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import { t as workosEmittersPlugin } from "./plugin-CZoeqixh.mjs";
1
+ import { t as workosEmittersPlugin } from "./plugin-BV_wDWDO.mjs";
2
2
  export { workosEmittersPlugin };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@workos/oagen-emitters",
3
- "version": "0.6.4",
3
+ "version": "0.6.5",
4
4
  "description": "WorkOS' oagen emitters",
5
5
  "license": "MIT",
6
6
  "author": "WorkOS",
@@ -127,7 +127,7 @@ export const dotnetEmitter: Emitter = {
127
127
  lines.push(' public override bool CanConvert(Type objectType) => objectType == typeof(object);');
128
128
  lines.push('');
129
129
  lines.push(
130
- ' public override object ReadJson(Newtonsoft.Json.JsonReader reader, Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer)',
130
+ ' public override object ReadJson(Newtonsoft.Json.JsonReader reader, Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer)',
131
131
  );
132
132
  lines.push(' {');
133
133
  lines.push(' var jObject = JObject.Load(reader);');
@@ -143,7 +143,7 @@ export const dotnetEmitter: Emitter = {
143
143
  lines.push(' }');
144
144
  lines.push('');
145
145
  lines.push(
146
- ' public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer)',
146
+ ' public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer)',
147
147
  );
148
148
  lines.push(' {');
149
149
  lines.push(' serializer.Serialize(writer, value);');
@@ -184,7 +184,7 @@ export const dotnetEmitter: Emitter = {
184
184
  );
185
185
  lines.push('');
186
186
  lines.push(
187
- ' public override object ReadJson(Newtonsoft.Json.JsonReader reader, Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer)',
187
+ ' public override object ReadJson(Newtonsoft.Json.JsonReader reader, Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer)',
188
188
  );
189
189
  lines.push(' {');
190
190
  lines.push(' var jObject = JObject.Load(reader);');
@@ -205,7 +205,7 @@ export const dotnetEmitter: Emitter = {
205
205
  lines.push(' }');
206
206
  lines.push('');
207
207
  lines.push(
208
- ' public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer)',
208
+ ' public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer)',
209
209
  );
210
210
  lines.push(' {');
211
211
  lines.push(' serializer.Serialize(writer, value);');
@@ -161,10 +161,12 @@ export function generateModels(models: Model[], ctx: EmitterContext, discCtx?: D
161
161
  let initializer = '';
162
162
  let setterModifier = '';
163
163
 
164
- if (constInit !== null) {
164
+ if (constInit !== null && !isOptional) {
165
165
  // Discriminator-style single-value enum/literal: emit with a const
166
166
  // initializer and a non-public setter so callers can't drift the
167
167
  // wire value. The converter still reads whatever the server sends.
168
+ // Only for required fields — optional literal fields must be nullable
169
+ // so absent keys round-trip correctly.
168
170
  csType = baseType;
169
171
  initializer = ` = ${constInit};`;
170
172
  setterModifier = 'internal ';
@@ -304,11 +304,13 @@ function renderFields(fields: Field[], overrideFields: Set<string> = new Set()):
304
304
  let kotlinType: string;
305
305
  let defaultExpr: string | null = null;
306
306
 
307
- // Const literal fields: always emit a hardcoded default matching the
308
- // literal value so callers don't have to pass it.
307
+ // Const literal fields: emit a hardcoded default matching the literal
308
+ // value so callers don't have to pass it — but only when the field is
309
+ // required. Optional literal fields must default to null so that absent
310
+ // keys round-trip correctly.
309
311
  const literalDefault = literalDefaultExpr(field.type);
310
312
 
311
- if (literalDefault !== null) {
313
+ if (literalDefault !== null && field.required) {
312
314
  kotlinType = baseType;
313
315
  defaultExpr = literalDefault;
314
316
  } else if (!field.required) {
@@ -357,8 +357,8 @@ export function generateModels(models: Model[], ctx: EmitterContext): GeneratedF
357
357
  const wireKey = field.name; // Wire keys are snake_case from the spec
358
358
  const isRequired = !isOptionalField(model.name, field, ctx);
359
359
  let accessor: string;
360
- if (field.type.kind === 'literal') {
361
- // Literal fields have a statically known value; use .get() with a default
360
+ if (field.type.kind === 'literal' && isRequired) {
361
+ // Required literal fields have a statically known value; use .get() with a default
362
362
  // so deserialization is resilient when the API omits the key.
363
363
  accessor = `data.get("${wireKey}", ${pythonLiteralDefault(field.type.value)})`;
364
364
  } else {