-
Notifications
You must be signed in to change notification settings - Fork 11
Propagate nullable
properties from OpenAPI 3 to CodeModel schemas
#298
Conversation
Forgot this needs a change to |
67bfdff
to
5b73b49
Compare
You may test this build by running add
or use the following in your autorest configuration: use-extension:
"@autorest/modelerfour": "http://tinyurl.com/ybjk7ysa" If this build is good for you, give this comment a thumbs up. (👍) And you should run |
OK, finally got this updated and added some unit tests (check out |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a bit confused. I see the code related to nullable
and nullableItems
(I'm assuming this is processing them for the code model), but shouldn't there be changes related to processing x-nullable
from the swagger? Meaning, turning x-nullable
into either nullable
or nullableItems
?
That happens in AutoRest Core via https://github.com/azure/perks/blob/master/oai2-to-oai3/main.ts#L532-L541
|
@daviwil So, looking at that, makes sense for |
There are two ways that can happen for
Maybe I should remove the former since the assumption would be that the |
@daviwil After reading this, what you said makes a lot more sense: https://help.apiary.io/api_101/swagger-extensions/#x-nullable |
|
@daviwil Ah, right. Derp. I got lost in my own thinking there. So, the question is, in |
In OpenAPI 3, I'll remove the behavior I mentioned above about setting |
@daviwil Perfect. Sounds great. Thanks for clarifying! 😊 |
5b73b49
to
d6d49e4
Compare
No problem! Fixed the unwanted |
You may test this build by running add
or use the following in your autorest configuration: use-extension:
"@autorest/modelerfour": "http://tinyurl.com/y93qvals" If this build is good for you, give this comment a thumbs up. (👍) And you should run |
@@ -561,11 +563,13 @@ export class ModelerFour { | |||
if (ei && this.interpret.isEmptyObject(ei)) { | |||
elementSchema = this.anySchema; | |||
} else { | |||
|
|||
elementNullable = (ei && ei.nullable) || false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TS has null propagation now 😄 ei?.nullable || false
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Old habits die hard :) I'll simplify this, thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahhh, I had to do this because .additionalProperties
is typed to false | Schema
, so the optional chaining operator fails the type check in this case after the schema has been resolved. It's either leave the current logic or use some type coercion to convince the compiler that it's definitely a Schema
, so I think I'll leave this logic as-is for now.
Issue #269 reports that
x-nullable
extensions in Swagger inputs don't have any effect on the outputted CodeModel. This change merely propagates the value fornullable
on OpenAPI 3 schemas to their CodeModel counterparts. Let me know if I missed any cases!