-
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
Add support for anyOf
and oneOf
on the jsonToSchemaObject
utility
#3524
Comments
@freakpol Thank you for the suggestion, good point. But don't support the reverse conversion as you mentioned. Ideally, the composite types could be inferred from the metadata of parameter's type:
But the reality is the information of composite types are lost in the metadata, which means we cannot generate corresponding schemas for both primitive types and custom types(other models). Therefore it's on users to
In terms of supporting the feature |
And another important thing to consider: for the composite types, how to coerce the data from HTTP request? See the coercion file https://github.com/strongloop/loopback-next/blob/master/packages/rest/src/coercion/coerce-parameter.ts It's easy for a certain type, but for an union/intersection type, user may need to provide a custom coercion function for it. |
I'm not really sure if I exposed my point well. The sample code I've posted in the description of the issue, is actual code. I was not talking about converting openapi to typescript. |
@freakpol I think I understand your description correctly, only the first paragraph of my comment is talking about "converting openapi to typescript", the rest are all about the feature you'd like to have. |
Oh, ok, sorry, I'm not really that expert either on typescript and even less in loopback. |
@freakpol cool! Would you like to submit your improvement as a pull request? The most important part is to add automated tests to verify your implementation and prevent regressions in the future. See Submitting a pull request to LoopBack 4 to get started, then we can help you along the way. |
@freakpol can you please share your code for reference if PR is not yet submitted. Thanks in Advance. |
…hemaObject` utility fix loopbackio#3524
…chemaObject` utility fix loopbackio#3524
…chemaObject` utility fix loopbackio#3524
…chemaObject` utility fix loopbackio#3524
Suggestion
Add support for
anyOf
andoneOf
on thejsonToSchemaObject
utilityUse Cases
When defining models, sometimes we want to specify that some properties are of one of / any of some types. For this, the property
jsonSchema
of theproperty
annotation comes handy, but it lack of support for theanyOf
andoneOf
.Examples
When loopback generates the openapi specs, that
anyOf
is totally ignored.Now, as a potential fix, I've tried adding
As a new case, just below the
allOf
case (and commenting the correspondingpropsToIgnore
entry) and all seems to work fine. Validations works when using the openapi explorer and also, the schemas object is generated properly.Acceptance criteria
TBD - will be filled by the team.
The text was updated successfully, but these errors were encountered: