-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
OpenAPI decorator does not properly generate schemas of type Partial
#1179
Comments
I don't think it's a good idea to interpret I think we need a way how to tweak the auto-magic algorithm that's currently in use to build JSON Schema/OpenAPI Schema description of A possible API: @post('/')
makeStuff(@requestBody(Note, {propertyBlacklist: ['id']}) note: Partial<Note>) {} ( |
+1 to having a way to tweak the auto-magic algorithm but I also think we should have a default "magic" fallback that we default to and then a way to tweak it if needed. I have another alternative name for |
+1 for the discussion above. We can also implement some schema combination methods in package |
BTW, this is a problem we faced in LoopBack 3.x too, see strongloop/loopback#2924 Another example of a property that must be omitted when creating a new model is The solution in LB 3.x touched several layers:
Maybe we can get some inspiration from this existing solution and perhaps leverage certain parts? |
The overlapping between parameter value and model instance validation is interesting: For example,
I start to lean toward that a parameter can impose additional constraints beyond the model type checking as such validations only make sense in the method invocation context. For the model itself, it's hard to describe when |
This makes a lot of sense to me too. I think it's also in line with |
|
(cross-posted @raymondfeng's #1722 (comment)) I'm proposing to introduce an {
schema: {
'x-ts-type': Order,
'x-ts-type-options': {
partial: true,
includes: ['p1', 'p2'],
excludes: []
}
} |
Description / Steps to reproduce / Feature proposal
From
todo.controllers.ts
inexample-getting-started
:It should be noted that the spec generated by
@requestBody
is not correct since the argumnet that the operation takes in does not need anid
property. One may think thatPartial<Todo>
may be the next best thing, but it's not possible at the moment to specify which properties are optional and which aren't.We should find a way to generate the schema for a model when used as a parameter so that id property is not included in the generated schema
Proposed behavior:
requestBody
is used on a model that extendsEntity
, always generate (or modify) its spec without the property that's been assigned asid
.requestBody
becomes very overloadedAcceptance Criteria:
explore more options from TypeScript (like Partial) to see if they can infer or provide us with additional data/metadata
allow
requestBody
(or other new decorator to create the appropriate metadata) to take in the model type and schema generation options to produce a custom schemaexcludeProperties
should generate an OpenAPI Schema that lacks the given keys and their values when converting from the JSON Schema generated inrest
includeProperties
should generate an OpenAPI Schema that contains only the given keys and their values when converted from the JSON Schema generated inrest
Backwards compatibility must be preserved (
@requestBody(spec)
)related to fix(repository): fix broken code in readme #1121
See Reporting Issues for more tips on writing good issues
The text was updated successfully, but these errors were encountered: