orval icon indicating copy to clipboard operation
orval copied to clipboard

Angular schema nullability definitions incorrectly done

Open jonimake opened this issue 6 months ago • 4 comments

I'm using orval 7.9.0 and I have the following component schema:

"components": {
	"schemas": {
	   "TestDto":{
		  "type":"object",
		  "required":[
			 "Foo",
			 "Bar"
		  ],
		  "properties":{
			 "Foo":{
				"type":"string"
			 },
			 "Bar":{
				"nullable":true,
				"type":"string"
			 },
			 "Foobar":{
				"nullable":true,
				"type":"string"
			 }
		  }
	   }
	}
}

and the generated model with angular client output is as such:

export interface TestDto {
  Foo: string;
  /** @nullable */
  Bar: string;
  /** @nullable */
  Foobar?: string;
}

As you can see the Bar and Foobar properties both have the "nullable" comment (but Bar surprisingly isn't nullable nor optional at all) and Foobar is just an optional property.

If I generate with zod client output I get what I expected:

export interface TestDto {
  Foo: string;
  /** @nullable */
  Bar: string | null;
  /** @nullable */
  Foobar?: string | null;
}

Is there any specific reason for why angular generation works this way or is it just a bug?

jonimake avatar May 15 '25 08:05 jonimake

Probably just a bug in the angular client if you want to debug and submit a PR

melloware avatar May 17 '25 01:05 melloware

Looks like the change in https://github.com/orval-labs/orval/pull/1200 is the root cause here. Removed the angular client check and now the models are correctly generated. I suspect a proper fix for this would be to generate non-nullable scalar values only for url params when generating angular code.

jonimake avatar May 17 '25 08:05 jonimake

PR would be great!

melloware avatar May 17 '25 13:05 melloware

PR is over here: https://github.com/orval-labs/orval/pull/2103

Let me know if anything else needs to be done, wasn't sure about the changelog part in the checklist.

jonimake avatar May 20 '25 19:05 jonimake

@snebjorn here is another Angular one that got started with a PR but never finished if you want to look!

melloware avatar Jul 27 '25 11:07 melloware