Hi Ron,
The slc loopback:swagger codegen will generate base of UserCredential as
PersistedModel, but I want to inherit the properties of loopback inbuilt
User Model
Foe example
“UserCredential”: {
properties: {
“password”: { “type”: “string” }
},
allOf : [
{ “$ref”: “#/definitions/User” }
]
}
}
Here instead of “#/definitions/User” I want to use loopback inbuilt model
'User'. In this case how can we handle this scenario?
On Monday, October 27, 2014 at 5:05:37 PM UTC+5:30, Ron R wrote:
>
> Close, but not quite.
>
> Ignoring the name of the sample -
> https://github.com/swagger-api/swagger-spec/blob/master/fixtures/v2.0/json/models/modelWithComposition.json
>
> - serves as a great sample of showing inheritance.
> Composition is pretty much the same, you'd just throw out the
> "discriminator" field.
>
> Hope this helps.
>
> On 27 October 2014 13:29, mission liao <[email protected] <javascript:>
> > wrote:
>
>> Hi Ron,
>>
>> I would like to compose some example to make sure what I understood is
>> spec compliant.
>> For 'composition':
>>
>>> {
>>> “User”: {
>>> properties: {
>>> “id”: { “type”: “string” },
>>> “email”: { “type”: “string” }
>>> }
>>> },
>>> “UserCredential”: {
>>> properties: {
>>> “password”: { “type”: “string” }
>>> },
>>> allOf : [
>>> { “$ref”: “#/definitions/User” }
>>> ]
>>> }
>>> }
>>
>>
>> For inheritance:
>>
>>> {
>>> “Pet” : {
>>> properties: {
>>> “pet_type”: { “type”: “string” }
>>> },
>>> discriminator: “pet_type”,
>>> required: [“pet_type”]
>>> },
>>> “Dog”: {
>>> allOf: [
>>> { “$ref”: “#/definitions/Pet” }
>>> ]
>>> }
>>> }
>>
>> When an operation accepting *Pet* as a parameter, we can pass a Dog(with
>> *pet_type=Dog*) instead.
>> Am I on the right track? Thanks for any advice.
>>
>> On Monday, 27 October 2014 17:25:07 UTC+8, Ron R wrote:
>>>
>>> It is defined, I just need to expand on the documentation.
>>>
>>> For a quick overview - there are two.. let's say "types" of inheritance
>>> with Swagger 2.0.
>>>
>>> The first is composition using the "allOf" keyword - you can say that a
>>> model contains the properties of other models (more than one).
>>>
>>> The second is polymorphism where the "discriminator" can be used on top
>>> of the "allOf" property.
>>> Just like in 1.2, the "discriminator" must be defined at the top level
>>> model and it must be required.
>>>
>>> Unlike 1.2, there's no "subTypes". Any model that includes the super
>>> mode in the "allOf" definition will be considered a sub type of it.
>>> So the super model is unaware of its children, but now the child is
>>> aware of its parent.
>>>
>>> On 27 October 2014 10:07, mission liao <[email protected]> wrote:
>>>
>>>> Hi,
>>>>
>>>> Just want to confirm that if *model inheritance* is still undefined
>>>> in swagger 2.0.
>>>>
>>>>> TODO: Add explanation about composition and inheritance in the new
>>>>> spec.
>>>>
>>>>
>>>> We have '*discriminator*' but have nothing compared to '*subTypes*'.
>>>>
>>>> --
>>>> You received this message because you are subscribed to the Google
>>>> Groups "Swagger" group.
>>>> To unsubscribe from this group and stop receiving emails from it, send
>>>> an email to [email protected].
>>>> For more options, visit https://groups.google.com/d/optout.
>>>>
>>>
>>> --
>> You received this message because you are subscribed to the Google Groups
>> "Swagger" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected] <javascript:>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
--
You received this message because you are subscribed to the Google Groups
"Swagger" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.